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