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.h" 24 #include "http_client_task.h" 25 #include <curl/curl.h> 26 27 using namespace OHOS::NetStack::HttpClient; 28 29 class HttpClientTest : public testing::Test { 30 public: SetUpTestCase()31 static void SetUpTestCase() {} 32 TearDownTestCase()33 static void TearDownTestCase() {} 34 SetUp()35 virtual void SetUp() {} 36 TearDown()37 virtual void TearDown() {} 38 }; 39 40 namespace { 41 using namespace std; 42 using namespace testing::ext; 43 44 HWTEST_F(HttpClientTest, AddRequestInfoTest001, TestSize.Level1) 45 { 46 HttpClientRequest httpReq; 47 std::string url = "http://www.baidu.com"; 48 httpReq.SetURL(url); 49 50 HttpSession &session = HttpSession::GetInstance(); 51 auto task = session.CreateTask(httpReq); 52 task->Start(); 53 54 while (task->GetStatus() != TaskStatus::IDLE) { 55 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 56 } 57 EXPECT_EQ(task->GetStatus(), IDLE); 58 } 59 60 } // namespace