• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <memory>
17 #include <unistd.h>
18 
19 #include "gtest/gtest.h"
20 #include "network/softbus/softbus_session.h"
21 #include "utils_log.h"
22 
23 namespace OHOS {
24 namespace Storage {
25 namespace DistributedFile {
26 namespace Test {
27 using namespace testing::ext;
28 using namespace std;
29 
30 constexpr int TEST_SESSION_ID = 10;
31 std::shared_ptr<SoftbusSession> g_session;
32 
33 class SoftbusSessionTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
SetUp()37     void SetUp() {};
TearDown()38     void TearDown() {};
39 };
40 
SetUpTestCase(void)41 void SoftbusSessionTest::SetUpTestCase(void)
42 {
43     // input testsuit setup step,setup invoked before all testcases
44     g_session = make_shared<SoftbusSession>(TEST_SESSION_ID);
45 }
46 
TearDownTestCase(void)47 void SoftbusSessionTest::TearDownTestCase(void)
48 {
49     // input testsuit setup step,setup invoked before all testcases
50     g_session = nullptr;
51 }
52 
53 /**
54  * @tc.name: SoftbusSessionTest_IsFromServer_0100
55  * @tc.desc: Verify the IsFromServer function.
56  * @tc.type: FUNC
57  * @tc.require: SR000H0387
58  */
59 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_IsFromServer_0100, TestSize.Level1)
60 {
61     GTEST_LOG_(INFO) << "SoftbusSessionTest_IsFromServer_0100 start";
62     try {
63         bool res = g_session->IsFromServer();
64         EXPECT_TRUE(res == false);
65     } catch (const exception &e) {
66         LOGE("%{public}s", e.what());
67     }
68     GTEST_LOG_(INFO) << "SoftbusSessionTest_IsFromServer_0100 end";
69 }
70 
71 /**
72  * @tc.name: SoftbusSessionTest_GetCid_0100
73  * @tc.desc: Verify the GetCid function.
74  * @tc.type: FUNC
75  * @tc.require: SR000H0387
76  */
77 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_GetCid_0100, TestSize.Level1)
78 {
79     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetCid_0100 start";
80     try {
81         string cid = g_session->GetCid();
82         EXPECT_TRUE(cid == "");
83     } catch (const exception &e) {
84         LOGE("%{public}s", e.what());
85     }
86     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetCid_0100 end";
87 }
88 
89 /**
90  * @tc.name: SoftbusSessionTest_GetHandle_0100
91  * @tc.desc: Verify the GetHandle function.
92  * @tc.type: FUNC
93  * @tc.require: SR000H0387
94  */
95 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_GetHandle_0100, TestSize.Level1)
96 {
97     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetHandle_0100 start";
98     try {
99         int32_t socket = g_session->GetHandle();
100         EXPECT_TRUE(socket == INVALID_SOCKET_FD);
101     } catch (const exception &e) {
102         LOGE("%{public}s", e.what());
103     }
104     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetHandle_0100 end";
105 }
106 
107 /**
108  * @tc.name: SoftbusSessionTest_GetKey_0100
109  * @tc.desc: Verify the GetKey function.
110  * @tc.type: FUNC
111  * @tc.require: SR000H0387
112  */
113 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_GetKey_0100, TestSize.Level1)
114 {
115     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetKey_0100 start";
116     bool res = true;
117     try {
118         (void)g_session->GetKey();
119     } catch (const exception &e) {
120         res = false;
121         LOGE("%{public}s", e.what());
122     }
123     EXPECT_TRUE(res == true);
124     GTEST_LOG_(INFO) << "SoftbusSessionTest_GetKey_0100 end";
125 }
126 
127 /**
128  * @tc.name: SoftbusSessionTest_Release_0100
129  * @tc.desc: Verify the Release function.
130  * @tc.type: FUNC
131  * @tc.require: SR000H0387
132  */
133 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_Release_0100, TestSize.Level1)
134 {
135     GTEST_LOG_(INFO) << "SoftbusSessionTest_Release_0100 start";
136     try {
137         g_session->Release();
138         EXPECT_TRUE(true);
139     } catch (const exception &e) {
140         LOGE("%{public}s", e.what());
141     }
142     GTEST_LOG_(INFO) << "SoftbusSessionTest_Release_0100 end";
143 }
144 
145 /**
146  * @tc.name: SoftbusSessionTest_DisableSessionListener_0100
147  * @tc.desc: Verify the DisableSessionListener function.
148  * @tc.type: FUNC
149  * @tc.require: SR000H0387
150  */
151 HWTEST_F(SoftbusSessionTest, SoftbusSessionTest_DisableSessionListener_0100, TestSize.Level1)
152 {
153     GTEST_LOG_(INFO) << "SoftbusSessionTest_DisableSessionListener_0100 start";
154     try {
155         g_session->DisableSessionListener();
156         EXPECT_TRUE(true);
157     } catch (const exception &e) {
158         LOGE("%{public}s", e.what());
159     }
160     GTEST_LOG_(INFO) << "SoftbusSessionTest_DisableSessionListener_0100 end";
161 }
162 } // namespace Test
163 } // namespace DistributedFile
164 } // namespace Storage
165 } // namespace OHOS
166