aboutsummaryrefslogblamecommitdiffstats
path: root/util/system/error_ut.cpp
blob: 763b0dddb79158d80d5339667f40e83270f0fefb (plain) (tree)
1
2
3
4
5
6
7
8
9
                  
                                                  
 
                                 
 
            
                       
     
                      
      


















                                                 
            
                        
     
                                                         
      


                                            
#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);