forked from apache/brpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrno_unittest.cpp
47 lines (40 loc) · 1.23 KB
/
errno_unittest.cpp
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
42
43
44
45
46
47
// Copyright (c) 2014 Baidu, Inc.
// Author: Ge,Jun ([email protected])
// Date: Wed Jul 30 08:41:06 CST 2014
#include <gtest/gtest.h>
#include "butil/errno.h"
class ErrnoTest : public ::testing::Test{
protected:
ErrnoTest(){
};
virtual ~ErrnoTest(){};
virtual void SetUp() {
};
virtual void TearDown() {
};
};
#define ESTOP -114
#define EBREAK -115
#define ESTH -116
#define EOK -117
#define EMYERROR -30
BAIDU_REGISTER_ERRNO(ESTOP, "the thread is stopping")
BAIDU_REGISTER_ERRNO(EBREAK, "the thread is interrupted")
BAIDU_REGISTER_ERRNO(ESTH, "something happened")
BAIDU_REGISTER_ERRNO(EOK, "OK!")
BAIDU_REGISTER_ERRNO(EMYERROR, "my error");
TEST_F(ErrnoTest, system_errno) {
errno = EPIPE;
ASSERT_STREQ("Broken pipe", berror());
ASSERT_STREQ("Interrupted system call", berror(EINTR));
}
TEST_F(ErrnoTest, customized_errno) {
ASSERT_STREQ("the thread is stopping", berror(ESTOP));
ASSERT_STREQ("the thread is interrupted", berror(EBREAK));
ASSERT_STREQ("something happened", berror(ESTH));
ASSERT_STREQ("OK!", berror(EOK));
ASSERT_STREQ("Unknown error 1000", berror(1000));
errno = ESTOP;
printf("Something got wrong, %m\n");
printf("Something got wrong, %s\n", berror());
}