1 /* 2 * Copyright (c) 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 <iostream> 17 #include <cstring> 18 #include "gtest/gtest.h" 19 #include "http_client_constant.h" 20 #include "netstack_log.h" 21 22 #define private public 23 #include "http_client_error.h" 24 25 using namespace OHOS::NetStack::HttpClient; 26 27 class HttpClientErrorTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() {} 30 TearDownTestCase()31 static void TearDownTestCase() {} 32 SetUp()33 virtual void SetUp() {} 34 TearDown()35 virtual void TearDown() {} 36 }; 37 38 namespace { 39 using namespace std; 40 using namespace testing::ext; 41 42 HWTEST_F(HttpClientErrorTest, GetErrorCodeTest001, TestSize.Level1) 43 { 44 HttpClientError req; 45 46 int errorCode = req.GetErrorCode(); 47 EXPECT_EQ(errorCode, HttpErrorCode::HTTP_NONE_ERR); 48 } 49 50 HWTEST_F(HttpClientErrorTest, SetErrorCodeTest001, TestSize.Level1) 51 { 52 HttpClientError req; 53 54 req.SetErrorCode(HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 55 int errorCode = req.GetErrorCode(); 56 EXPECT_EQ(errorCode, HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 57 } 58 59 HWTEST_F(HttpClientErrorTest, GetErrorMessageTest001, TestSize.Level1) 60 { 61 HttpClientError req; 62 63 string errorMsg = req.GetErrorMessage(); 64 EXPECT_EQ(errorMsg, "No errors occurred"); 65 } 66 67 HWTEST_F(HttpClientErrorTest, GetErrorMessageTest002, TestSize.Level1) 68 { 69 HttpClientError req; 70 71 req.SetErrorCode(HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 72 string errorMsg = req.GetErrorMessage(); 73 EXPECT_EQ(errorMsg, "Permission denied"); 74 } 75 76 HWTEST_F(HttpClientErrorTest, SetCURLResultTest001, TestSize.Level1) 77 { 78 HttpClientError req; 79 80 req.SetCURLResult(CURLE_OK); 81 int errorCode = req.GetErrorCode(); 82 EXPECT_EQ(errorCode, HttpErrorCode::HTTP_NONE_ERR); 83 } 84 85 HWTEST_F(HttpClientErrorTest, SetCURLResultTest002, TestSize.Level1) 86 { 87 HttpClientError req; 88 89 req.SetCURLResult(CURLE_UNSUPPORTED_PROTOCOL); 90 int errorCode = req.GetErrorCode(); 91 EXPECT_EQ(errorCode, HttpErrorCode::HTTP_UNSUPPORTED_PROTOCOL); 92 } 93 94 } // namespace