1/* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <gtest/gtest.h> 17#include <regex> 18#include "socket_error.h" 19 20namespace OHOS { 21namespace NetStack { 22namespace TlsSocket { 23namespace { 24using namespace testing::ext; 25const int32_t ERROR_NOT_EXIT = 2303800; 26} // namespace 27 28class SocketErrorTest : public testing::Test { 29public: 30 static void SetUpTestCase() {} 31 32 static void TearDownTestCase() {} 33 34 virtual void SetUp() {} 35 36 virtual void TearDown() {} 37}; 38 39HWTEST_F(SocketErrorTest, SocketError, TestSize.Level2) 40{ 41 std::string errorMsg = MakeErrorMessage(TLS_ERR_SYS_EINTR); 42 EXPECT_STREQ(errorMsg.data(), "Interrupted system call"); 43} 44 45HWTEST_F(SocketErrorTest, SocketError2, TestSize.Level2) 46{ 47 std::string errorMsg = MakeErrorMessage(ERROR_NOT_EXIT); 48 std::regex value("^error:000002BC:lib.{5,12}reason.{5}"); 49 EXPECT_TRUE(std::regex_match(errorMsg, value) == true); 50} 51} // namespace TlsSocket 52} // namespace NetStack 53} // namespace OHOS