/*
 * Copyright 2016 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <gtest/gtest.h>
#include <folly/io/async/AsyncSocketException.h>

using namespace testing;

namespace folly {

TEST(AsyncSocketException, SimpleTest) {
  AsyncSocketException ex1(
      AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
      "test exception 1");

  EXPECT_EQ(AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
            ex1.getType());
  EXPECT_EQ(0, ex1.getErrno());
  EXPECT_EQ("AsyncSocketException: test exception 1, type = Socket not open",
            std::string(ex1.what()));

  AsyncSocketException ex2(
      AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS,
      "test exception 2",
      111 /*ECONNREFUSED*/);

  EXPECT_EQ(AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS,
            ex2.getType());
  EXPECT_EQ(111, ex2.getErrno());
  EXPECT_EQ(
      "AsyncSocketException: test exception 2, type = Invalid arguments, "
      "errno = 111 (Connection refused)",
      std::string(ex2.what()));
}

} // namespace folly
