662a3737cae10023a1cfaebcb4f7c390700b2649
[folly.git] / folly / io / async / test / AsyncSocketExceptionTest.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <gtest/gtest.h>
17 #include <folly/io/async/AsyncSocketException.h>
18
19 using namespace testing;
20
21 namespace folly {
22
23 TEST(AsyncSocketException, SimpleTest) {
24   AsyncSocketException ex1(
25       AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
26       "test exception 1");
27
28   EXPECT_EQ(AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
29             ex1.getType());
30   EXPECT_EQ(0, ex1.getErrno());
31   EXPECT_EQ("AsyncSocketException: test exception 1, type = Socket not open",
32             std::string(ex1.what()));
33
34   AsyncSocketException ex2(
35       AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS,
36       "test exception 2",
37       111 /*ECONNREFUSED*/);
38
39   EXPECT_EQ(AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS,
40             ex2.getType());
41   EXPECT_EQ(111, ex2.getErrno());
42   EXPECT_EQ(
43       "AsyncSocketException: test exception 2, type = Invalid arguments, "
44       "errno = 111 (Connection refused)",
45       std::string(ex2.what()));
46 }
47
48 } // namespace folly