• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_response.h"
24 
25 using namespace OHOS::NetStack::HttpClient;
26 
27 class HttpClientResponseTest : 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(HttpClientResponseTest, GetResponseCodeTest001, TestSize.Level1)
43 {
44     HttpClientResponse req;
45 
46     int responseTest = req.GetResponseCode();
47     EXPECT_EQ(responseTest, ResponseCode::NONE);
48 }
49 
50 HWTEST_F(HttpClientResponseTest, GetHeaderTest001, TestSize.Level1)
51 {
52     HttpClientResponse req;
53 
54     string header = req.GetHeader();
55     EXPECT_EQ(header, "");
56 }
57 
58 HWTEST_F(HttpClientResponseTest, GetRequestTimeTest001, TestSize.Level1)
59 {
60     HttpClientResponse req;
61 
62     string requestTime = req.GetRequestTime();
63     EXPECT_EQ(requestTime, "");
64 }
65 
66 HWTEST_F(HttpClientResponseTest, GetResponseTimeTest001, TestSize.Level1)
67 {
68     HttpClientResponse req;
69 
70     string responseTime = req.GetResponseTime();
71     EXPECT_EQ(responseTime, "");
72 }
73 
74 HWTEST_F(HttpClientResponseTest, SetRequestTimeTest001, TestSize.Level1)
75 {
76     HttpClientResponse req;
77 
78     req.SetRequestTime("10");
79     string requestTime = req.GetRequestTime();
80     EXPECT_EQ(requestTime, "10");
81 }
82 
83 HWTEST_F(HttpClientResponseTest, SetResponseTimeTest001, TestSize.Level1)
84 {
85     HttpClientResponse req;
86 
87     req.SetResponseTime("10");
88     string responseTime = req.GetResponseTime();
89     EXPECT_EQ(responseTime, "10");
90 }
91 
92 HWTEST_F(HttpClientResponseTest, AppendHeaderTest001, TestSize.Level1)
93 {
94     HttpClientResponse req;
95     std::string add = "test";
96     req.AppendHeader(add.data(), add.length());
97     string header = req.GetHeader();
98     EXPECT_EQ(header, "test");
99 }
100 
101 HWTEST_F(HttpClientResponseTest, SetResponseCodeTest001, TestSize.Level1)
102 {
103     HttpClientResponse req;
104 
105     req.SetResponseCode(ResponseCode::MULT_CHOICE);
106     int responseTest = req.GetResponseCode();
107     EXPECT_EQ(responseTest, ResponseCode::MULT_CHOICE);
108 }
109 
110 } // namespace