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