• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 <cstdio>
17 #include <ctime>
18 #include <gtest/gtest.h>
19 #include <sys/time.h>
20 #include <unistd.h>
21 
22 #include "softbus_access_token_test.h"
23 #include "softbus_bus_center.h"
24 #include "discovery_service.h"
25 
26 using namespace testing::ext;
27 
28 #define TEST_ERRO_MOUDULE       ((MODULE_LNN) + 3)
29 
30 namespace OHOS {
31 static int g_subscribeId = 0;
32 static int g_publishId = 0;
33 static const char *g_pkgName = "Softbus_Kits";
34 
35 class DiscSdkOnlyL2Test : public testing::Test {
36 public:
DiscSdkOnlyL2Test()37     DiscSdkOnlyL2Test()
38     {}
~DiscSdkOnlyL2Test()39     ~DiscSdkOnlyL2Test()
40     {}
41     static void SetUpTestCase(void);
42     static void TearDownTestCase(void);
SetUp()43     void SetUp() override
44     {}
TearDown()45     void TearDown() override
46     {}
47 };
48 
SetUpTestCase(void)49 void DiscSdkOnlyL2Test::SetUpTestCase(void)
50 {
51     SetAceessTokenPermission("discSdkOnlyL2Test");
52 }
53 
TearDownTestCase(void)54 void DiscSdkOnlyL2Test::TearDownTestCase(void)
55 {}
56 
GetSubscribeId(void)57 static int GetSubscribeId(void)
58 {
59     g_subscribeId++;
60     return g_subscribeId;
61 }
62 
GetPublishId(void)63 static int GetPublishId(void)
64 {
65     g_publishId++;
66     return g_publishId;
67 }
68 
69 static SubscribeInfo g_sInfo = {
70     .subscribeId = 1,
71     .mode = DISCOVER_MODE_ACTIVE,
72     .medium = COAP,
73     .freq = MID,
74     .isSameAccount = true,
75     .isWakeRemote = false,
76     .capability = "dvKit",
77     .capabilityData = (unsigned char *)"capdata3",
78     .dataLen = strlen("capdata3")
79 };
80 
81 static PublishInfo g_pInfo = {
82     .publishId = 1,
83     .mode = DISCOVER_MODE_ACTIVE,
84     .medium = COAP,
85     .freq = MID,
86     .capability = "dvKit",
87     .capabilityData = (unsigned char *)"capdata4",
88     .dataLen = strlen("capdata4")
89 };
90 
TestDeviceFound(const DeviceInfo * device)91 static void TestDeviceFound(const DeviceInfo *device)
92 {
93     printf("[client]TestDeviceFound\n");
94 }
95 
TestOnDiscoverResult(int32_t refreshId,RefreshResult reason)96 static void TestOnDiscoverResult(int32_t refreshId, RefreshResult reason)
97 {
98     (void)refreshId;
99     (void)reason;
100     printf("[client]TestDiscoverResult\n");
101 }
102 
TestOnPublishResult(int publishId,PublishResult reason)103 static void TestOnPublishResult(int publishId, PublishResult reason)
104 {
105     (void)publishId;
106     (void)reason;
107     printf("[client]TestPublishResult\n");
108 }
109 
110 static IRefreshCallback g_refreshCb = {
111     .OnDeviceFound = TestDeviceFound,
112     .OnDiscoverResult = TestOnDiscoverResult
113 };
114 
115 static IPublishCb g_publishCb = {
116     .OnPublishResult = TestOnPublishResult,
117 };
118 
119 /**
120  * @tc.name: StopPublishLNNTest004
121  * @tc.desc: not start publish.
122  * @tc.in: Test Moudle, Test Number, Test Levels.
123  * @tc.out: NonZero
124  * @tc.type: FUNC
125  * @tc.require: The StopPublishLNN operates normally.
126  */
127 HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest001, TestSize.Level2)
128 {
129     int ret;
130     int tmpId = GetPublishId();
131 
132     ret = StopPublishLNN(g_pkgName, tmpId);
133     EXPECT_TRUE(ret != 0);
134 }
135 
136 /**
137  * @tc.name: StopPublishLNNTest005
138  * @tc.desc: Verify StopPublishLNN again.
139  * @tc.in: Test Moudle, Test Number, Test Levels.
140  * @tc.out: NonZero
141  * @tc.type: FUNC
142  * @tc.require: The StopPublishLNN operates normally.
143  */
144 HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest002, TestSize.Level2)
145 {
146     int ret;
147     int tmpId = GetPublishId();
148 
149     g_pInfo.publishId = tmpId;
150     PublishLNN(g_pkgName, &g_pInfo, &g_publishCb);
151     ret = StopPublishLNN(g_pkgName, tmpId);
152     EXPECT_TRUE(ret == 0);
153     ret = StopPublishLNN(g_pkgName, tmpId);
154     EXPECT_TRUE(ret != 0);
155 }
156 
157 /**
158  * @tc.name: StopRefreshLNNTest004
159  * @tc.desc: not start discover.
160  * @tc.in: Test Moudle, Test Number, Test Levels.
161  * @tc.out: NonZero
162  * @tc.type: FUNC
163  * @tc.require: The StopRefreshLNN operates normally.
164  */
165 HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest001, TestSize.Level2)
166 {
167     int ret;
168     int tmpId = GetSubscribeId();
169 
170     ret = StopRefreshLNN(g_pkgName, tmpId);
171     EXPECT_TRUE(ret != 0);
172 }
173 
174 /**
175  * @tc.name: StopRefreshLNNTest005
176  * @tc.desc: Verify StopRefreshLNN again.
177  * @tc.in: Test Moudle, Test Number, Test Levels.
178  * @tc.out: NonZero
179  * @tc.type: FUNC
180  * @tc.require: The StopRefreshLNN operates normally.
181  */
182 HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest002, TestSize.Level2)
183 {
184     int ret;
185     int tmpId = GetSubscribeId();
186 
187     g_sInfo.subscribeId = tmpId;
188     RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb);
189     ret = StopRefreshLNN(g_pkgName, tmpId);
190     EXPECT_TRUE(ret == 0);
191     ret = StopRefreshLNN(g_pkgName, tmpId);
192     EXPECT_TRUE(ret != 0);
193 }
194 } // namespace OHOS
195