aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/error_ut.cpp
blob: 8403dfa1802cb19ea53e06d2b33981089cf7992f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "error.h"

#include <library/cpp/testing/unittest/registar.h>

#include <util/generic/ylimits.h>

#ifdef _win_
    #include "winint.h"
#else 
    #include <fcntl.h>
#endif

class TSysErrorTest: public TTestBase {
    UNIT_TEST_SUITE(TSysErrorTest);
    UNIT_TEST(TestErrorCode)
    UNIT_TEST(TestErrorMessage)
    UNIT_TEST_SUITE_END();

private:
    inline void TestErrorCode() {
        GenFailure();

        UNIT_ASSERT(LastSystemError() != 0);
    }

    inline void TestErrorMessage() {
        GenFailure();

        UNIT_ASSERT(*LastSystemErrorText() != 0);
    }

    inline void GenFailure() {
#ifdef _win_
        SetLastError(3);
#else
        UNIT_ASSERT(open("/non-existent", O_RDONLY) < 0);
#endif
    }
};

UNIT_TEST_SUITE_REGISTRATION(TSysErrorTest);