11e934351Sopenharmony_ci/* 21e934351Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41e934351Sopenharmony_ci * you may not use this file except in compliance with the License. 51e934351Sopenharmony_ci * You may obtain a copy of the License at 61e934351Sopenharmony_ci * 71e934351Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81e934351Sopenharmony_ci * 91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121e934351Sopenharmony_ci * See the License for the specific language governing permissions and 131e934351Sopenharmony_ci * limitations under the License. 141e934351Sopenharmony_ci */ 151e934351Sopenharmony_ci 161e934351Sopenharmony_ci#include <iostream> 171e934351Sopenharmony_ci#include <cstring> 181e934351Sopenharmony_ci#include "gtest/gtest.h" 191e934351Sopenharmony_ci#include "http_client_constant.h" 201e934351Sopenharmony_ci#include "netstack_log.h" 211e934351Sopenharmony_ci 221e934351Sopenharmony_ci#define private public 231e934351Sopenharmony_ci#include "http_client_error.h" 241e934351Sopenharmony_ci 251e934351Sopenharmony_ciusing namespace OHOS::NetStack::HttpClient; 261e934351Sopenharmony_ci 271e934351Sopenharmony_ciclass HttpClientErrorTest : public testing::Test { 281e934351Sopenharmony_cipublic: 291e934351Sopenharmony_ci static void SetUpTestCase() {} 301e934351Sopenharmony_ci 311e934351Sopenharmony_ci static void TearDownTestCase() {} 321e934351Sopenharmony_ci 331e934351Sopenharmony_ci virtual void SetUp() {} 341e934351Sopenharmony_ci 351e934351Sopenharmony_ci virtual void TearDown() {} 361e934351Sopenharmony_ci}; 371e934351Sopenharmony_ci 381e934351Sopenharmony_cinamespace { 391e934351Sopenharmony_ciusing namespace std; 401e934351Sopenharmony_ciusing namespace testing::ext; 411e934351Sopenharmony_ci 421e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, GetErrorCodeTest001, TestSize.Level1) 431e934351Sopenharmony_ci{ 441e934351Sopenharmony_ci HttpClientError req; 451e934351Sopenharmony_ci 461e934351Sopenharmony_ci int errorCode = req.GetErrorCode(); 471e934351Sopenharmony_ci EXPECT_EQ(errorCode, HttpErrorCode::HTTP_NONE_ERR); 481e934351Sopenharmony_ci} 491e934351Sopenharmony_ci 501e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, SetErrorCodeTest001, TestSize.Level1) 511e934351Sopenharmony_ci{ 521e934351Sopenharmony_ci HttpClientError req; 531e934351Sopenharmony_ci 541e934351Sopenharmony_ci req.SetErrorCode(HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 551e934351Sopenharmony_ci int errorCode = req.GetErrorCode(); 561e934351Sopenharmony_ci EXPECT_EQ(errorCode, HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 571e934351Sopenharmony_ci} 581e934351Sopenharmony_ci 591e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, GetErrorMessageTest001, TestSize.Level1) 601e934351Sopenharmony_ci{ 611e934351Sopenharmony_ci HttpClientError req; 621e934351Sopenharmony_ci 631e934351Sopenharmony_ci string errorMsg = req.GetErrorMessage(); 641e934351Sopenharmony_ci EXPECT_EQ(errorMsg, "No errors occurred"); 651e934351Sopenharmony_ci} 661e934351Sopenharmony_ci 671e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, GetErrorMessageTest002, TestSize.Level1) 681e934351Sopenharmony_ci{ 691e934351Sopenharmony_ci HttpClientError req; 701e934351Sopenharmony_ci 711e934351Sopenharmony_ci req.SetErrorCode(HttpErrorCode::HTTP_PERMISSION_DENIED_CODE); 721e934351Sopenharmony_ci string errorMsg = req.GetErrorMessage(); 731e934351Sopenharmony_ci EXPECT_EQ(errorMsg, "Permission denied"); 741e934351Sopenharmony_ci} 751e934351Sopenharmony_ci 761e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, SetCURLResultTest001, TestSize.Level1) 771e934351Sopenharmony_ci{ 781e934351Sopenharmony_ci HttpClientError req; 791e934351Sopenharmony_ci 801e934351Sopenharmony_ci req.SetCURLResult(CURLE_OK); 811e934351Sopenharmony_ci int errorCode = req.GetErrorCode(); 821e934351Sopenharmony_ci EXPECT_EQ(errorCode, HttpErrorCode::HTTP_NONE_ERR); 831e934351Sopenharmony_ci} 841e934351Sopenharmony_ci 851e934351Sopenharmony_ciHWTEST_F(HttpClientErrorTest, SetCURLResultTest002, TestSize.Level1) 861e934351Sopenharmony_ci{ 871e934351Sopenharmony_ci HttpClientError req; 881e934351Sopenharmony_ci 891e934351Sopenharmony_ci req.SetCURLResult(CURLE_UNSUPPORTED_PROTOCOL); 901e934351Sopenharmony_ci int errorCode = req.GetErrorCode(); 911e934351Sopenharmony_ci EXPECT_EQ(errorCode, HttpErrorCode::HTTP_UNSUPPORTED_PROTOCOL); 921e934351Sopenharmony_ci} 931e934351Sopenharmony_ci 941e934351Sopenharmony_ci} // namespace