From e87cb5d7f13fc3f8ddb78b8e7ee2f242f5a9375c Mon Sep 17 00:00:00 2001 From: JanierVan Date: Thu, 5 Sep 2024 17:19:44 +0800 Subject: [PATCH] fix: restore discovery sdk tests Signed-off-by: JanierVan --- tests/BUILD.gn | 2 + tests/sdk/discovery/BUILD.gn | 5 + tests/sdk/discovery/unittest/BUILD.gn | 112 ++ .../unittest/disc_sdk_only_l2_test.cpp | 191 +++ .../sdk/discovery/unittest/disc_sdk_test.cpp | 1078 +++++++++++++++++ .../unittest/disc_sdk_test_bt_status.c | 23 + .../unittest/disc_sdk_test_bt_status.h | 30 + .../disc_sdk_test_bt_status_virtual.c | 21 + 8 files changed, 1462 insertions(+) create mode 100644 tests/sdk/discovery/unittest/BUILD.gn create mode 100644 tests/sdk/discovery/unittest/disc_sdk_only_l2_test.cpp create mode 100644 tests/sdk/discovery/unittest/disc_sdk_test.cpp create mode 100644 tests/sdk/discovery/unittest/disc_sdk_test_bt_status.c create mode 100644 tests/sdk/discovery/unittest/disc_sdk_test_bt_status.h create mode 100644 tests/sdk/discovery/unittest/disc_sdk_test_bt_status_virtual.c diff --git a/tests/BUILD.gn b/tests/BUILD.gn index 4688210e58..f086af4b64 100644 --- a/tests/BUILD.gn +++ b/tests/BUILD.gn @@ -23,6 +23,7 @@ if (defined(ohos_lite)) { features += [ "adapter/unittest:AdapterTest", "sdk/bus_center/unittest:BusCenterSdkRefreshSmall", + "sdk/discovery/unittest:DiscSdkTest", "sdk/transmission/trans_channel:TransSdkStreamTest", ] } @@ -48,6 +49,7 @@ if (defined(ohos_lite)) { "core/frame:unittest", "core/transmission:unittest", "sdk/bus_center:unittest", + "sdk/discovery:unittest", "sdk/frame/common:unittest", "sdk/frame/standard:unittest", "sdk/transmission:unittest", diff --git a/tests/sdk/discovery/BUILD.gn b/tests/sdk/discovery/BUILD.gn index 99d1246616..41a991cbb6 100644 --- a/tests/sdk/discovery/BUILD.gn +++ b/tests/sdk/discovery/BUILD.gn @@ -18,3 +18,8 @@ group("benchmarktest") { testonly = true deps = [ "benchmarktest:benchmarktest" ] } + +group("unittest") { + testonly = true + deps = [ "unittest:unittest" ] +} diff --git a/tests/sdk/discovery/unittest/BUILD.gn b/tests/sdk/discovery/unittest/BUILD.gn new file mode 100644 index 0000000000..65ae96dafa --- /dev/null +++ b/tests/sdk/discovery/unittest/BUILD.gn @@ -0,0 +1,112 @@ +# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("../../../../dsoftbus.gni") + +dsoftbus_root_path = "../../../.." + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + import("//build/lite/config/test.gni") + + if (ohos_build_type == "debug") { + unittest("DiscSdkTest") { + output_extension = "bin" + output_dir = "$root_out_dir/test/unittest/dsoftbus" + sources = [ + "disc_sdk_test.cpp", + "disc_sdk_test_bt_status_virtual.c", + ] + include_dirs = [ + "$dsoftbus_root_path/core/common/include", + "$dsoftbus_root_path/sdk/bus_center/manager/include", + "$dsoftbus_root_path/interfaces/kits/discovery", + "$dsoftbus_root_path/interfaces/kits/common", + "$dsoftbus_root_path/tests/sdk/common/include", + ] + deps = [ + "$dsoftbus_root_path/sdk:softbus_client", + "$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test", + ] + } + } +} else { + import("//build/test.gni") + module_output_path = "dsoftbus/discovery" + ohos_unittest("DiscSdkOnlyL2Test") { + module_out_path = module_output_path + sources = [ "disc_sdk_only_l2_test.cpp" ] + include_dirs = [ + "$dsoftbus_root_path/core/common/inner_communication", + "$dsoftbus_root_path/core/common/include", + "$dsoftbus_root_path/interfaces/kits/discovery", + "$dsoftbus_root_path/interfaces/kits/common", + "$dsoftbus_root_path/sdk/discovery/include", + "$dsoftbus_root_path/sdk/discovery/manager/include", + "$dsoftbus_root_path/tests/sdk/common/include", + "unittest/common/", + ] + deps = [ + "$dsoftbus_root_path/tests/sdk:softbus_client_static", + "$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "c_utils:utils", + "googletest:gtest_main", + "hilog:libhilog", + ] + } + + ohos_unittest("DiscSdkTest") { + module_out_path = module_output_path + sources = [ "disc_sdk_test.cpp" ] + include_dirs = [ + "$dsoftbus_root_path/sdk/bus_center/manager/include", + "$dsoftbus_root_path/core/common/inner_communication", + "$dsoftbus_root_path/core/common/include", + "$dsoftbus_root_path/interfaces/inner_kits/lnn", + "$dsoftbus_root_path/interfaces/kits/discovery", + "$dsoftbus_root_path/interfaces/kits/common", + "$dsoftbus_root_path/sdk/discovery/include", + "unittest/common/", + "$dsoftbus_root_path/sdk/discovery/manager/include", + "$dsoftbus_root_path/tests/sdk/common/include", + ] + deps = [ + "$dsoftbus_root_path/tests/sdk:softbus_client_static", + "$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "c_utils:utils", + "googletest:gtest_main", + "hilog:libhilog", + ] + if (support_bluetooth && + (dsoftbus_feature_conn_br || dsoftbus_feature_conn_ble)) { + sources += [ "disc_sdk_test_bt_status.c" ] + external_deps += [ "bluetooth:btframework" ] + } else { + sources += [ "disc_sdk_test_bt_status_virtual.c" ] + } + } + + group("unittest") { + testonly = true + deps = [ + ":DiscSdkOnlyL2Test", + ":DiscSdkTest", + ] + } +} diff --git a/tests/sdk/discovery/unittest/disc_sdk_only_l2_test.cpp b/tests/sdk/discovery/unittest/disc_sdk_only_l2_test.cpp new file mode 100644 index 0000000000..6d27d0334c --- /dev/null +++ b/tests/sdk/discovery/unittest/disc_sdk_only_l2_test.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "softbus_access_token_test.h" +#include "softbus_bus_center.h" + +using namespace testing::ext; + +namespace OHOS { +static int g_subscribeId = 0; +static int g_publishId = 0; +static const char *g_pkgName = "Softbus_Kits"; + +class DiscSdkOnlyL2Test : public testing::Test { +public: + DiscSdkOnlyL2Test() + {} + ~DiscSdkOnlyL2Test() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp() override + {} + void TearDown() override + {} +}; + +void DiscSdkOnlyL2Test::SetUpTestCase(void) +{ + SetAceessTokenPermission("discSdkOnlyL2Test"); +} + +void DiscSdkOnlyL2Test::TearDownTestCase(void) +{} + +static int GetSubscribeId(void) +{ + g_subscribeId++; + return g_subscribeId; +} + +static int GetPublishId(void) +{ + g_publishId++; + return g_publishId; +} + +static SubscribeInfo g_sInfo = { + .subscribeId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata3", + .dataLen = strlen("capdata3") +}; + +static PublishInfo g_pInfo = { + .publishId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata4", + .dataLen = strlen("capdata4") +}; + +static void TestDeviceFound(const DeviceInfo *device) +{ + printf("[client]TestDeviceFound\n"); +} + +static void TestOnDiscoverResult(int32_t refreshId, RefreshResult reason) +{ + (void)refreshId; + (void)reason; + printf("[client]TestDiscoverResult\n"); +} + +static void TestOnPublishResult(int publishId, PublishResult reason) +{ + (void)publishId; + (void)reason; + printf("[client]TestPublishResult\n"); +} + +static IRefreshCallback g_refreshCb = { + .OnDeviceFound = TestDeviceFound, + .OnDiscoverResult = TestOnDiscoverResult +}; + +static IPublishCb g_publishCb = { + .OnPublishResult = TestOnPublishResult, +}; + +/** + * @tc.name: StopPublishLNNTest004 + * @tc.desc: not start publish. + * @tc.in: Test Moudle, Test Number, Test Levels. + * @tc.out: NonZero + * @tc.type: FUNC + * @tc.require: The StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest001, TestSize.Level2) +{ + int ret; + int tmpId = GetPublishId(); + + ret = StopPublishLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret != 0); +} + +/** + * @tc.name: StopPublishLNNTest005 + * @tc.desc: Verify StopPublishLNN again. + * @tc.in: Test Moudle, Test Number, Test Levels. + * @tc.out: NonZero + * @tc.type: FUNC + * @tc.require: The StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest002, TestSize.Level2) +{ + int ret; + int tmpId = GetPublishId(); + + g_pInfo.publishId = tmpId; + PublishLNN(g_pkgName, &g_pInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret == 0); + ret = StopPublishLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret != 0); +} + +/** + * @tc.name: StopRefreshLNNTest004 + * @tc.desc: not start discover. + * @tc.in: Test Moudle, Test Number, Test Levels. + * @tc.out: NonZero + * @tc.type: FUNC + * @tc.require: The StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest001, TestSize.Level2) +{ + int ret; + int tmpId = GetSubscribeId(); + + ret = StopRefreshLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret != 0); +} + +/** + * @tc.name: StopRefreshLNNTest005 + * @tc.desc: Verify StopRefreshLNN again. + * @tc.in: Test Moudle, Test Number, Test Levels. + * @tc.out: NonZero + * @tc.type: FUNC + * @tc.require: The StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest002, TestSize.Level2) +{ + int ret; + int tmpId = GetSubscribeId(); + + g_sInfo.subscribeId = tmpId; + RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret == 0); + ret = StopRefreshLNN(g_pkgName, tmpId); + EXPECT_TRUE(ret != 0); +} +} // namespace OHOS \ No newline at end of file diff --git a/tests/sdk/discovery/unittest/disc_sdk_test.cpp b/tests/sdk/discovery/unittest/disc_sdk_test.cpp new file mode 100644 index 0000000000..ae694c7a06 --- /dev/null +++ b/tests/sdk/discovery/unittest/disc_sdk_test.cpp @@ -0,0 +1,1078 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "client_bus_center_manager.h" +#include "disc_sdk_test_bt_status.h" +#include "softbus_access_token_test.h" +#include "softbus_bus_center.h" +#include "softbus_error_code.h" + +using namespace testing::ext; + +namespace OHOS { +static int g_subscribeId = 0; +static int g_publishId = 0; +static const char *g_pkgName = "Softbus_Kits"; +static const char *g_pkgName_1 = "Softbus_Kits_1"; +static const char *g_erroPkgName = "Softbus_Erro_Kits"; +static const char *g_erroPkgName1 = "ErroErroErroErroErroErroErroErroErroErroErroErroErroErroErroErroEErroE"; + +const int32_t ERRO_CAPDATA_LEN = 514; + +class DiscSdkTest : public testing::Test { +public: + DiscSdkTest() + {} + ~DiscSdkTest() + {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp() override + {} + void TearDown() override + {} +}; + +void DiscSdkTest::SetUpTestCase(void) +{ + SetAceessTokenPermission("discTest"); +} + +void DiscSdkTest::TearDownTestCase(void) +{} + +static int GetSubscribeId(void) +{ + g_subscribeId++; + return g_subscribeId; +} + +static int GetPublishId(void) +{ + g_publishId++; + return g_publishId; +} + +static SubscribeInfo g_sInfo = { + .subscribeId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata3", + .dataLen = (unsigned int) strlen("capdata3") +}; + +static PublishInfo g_pInfo = { + .publishId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata4", + .dataLen = (unsigned int) strlen("capdata4") +}; + +static PublishInfo g_pInfo1 = { + .publishId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .capability = "dvKit", + .capabilityData = nullptr, + .dataLen = 0 +}; + +static SubscribeInfo g_sInfo1 = { + .subscribeId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "hicall", + .capabilityData = nullptr, + .dataLen = 0 +}; + +static PublishInfo g_publishInfo = { + .publishId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .capability = "dvKit", + .capabilityData = nullptr, + .dataLen = 0 +}; + +static SubscribeInfo g_subscribeInfo = { + .subscribeId = 1, + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = MID, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "dvKit", + .capabilityData = nullptr, + .dataLen = 0 +}; + +static void TestDeviceFound(const DeviceInfo *device) +{ + (void)device; + printf("[client]TestDeviceFound\n"); +} + +static void TestOnDiscoverResult(int32_t refreshId, RefreshResult reason) +{ + (void)refreshId; + (void)reason; + printf("[client]TestDiscoverResult\n"); +} + +static const IRefreshCallback g_refreshCb = { + .OnDeviceFound = TestDeviceFound, + .OnDiscoverResult = TestOnDiscoverResult +}; + +static void TestOnPublishResult(int publishId, PublishResult reason) +{ + (void)publishId; + (void)reason; + printf("[client]TestPublishResult\n"); +} + +static const IPublishCb g_publishCb = { + .OnPublishResult = TestOnPublishResult, +}; + +/** + * @tc.name: PublishLNNTest001 + * @tc.desc: Test for invalid parameters + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, PublishLNNTest001, TestSize.Level1) +{ + int32_t ret = PublishLNN(nullptr, &g_pInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + ret = PublishLNN(g_pkgName, nullptr, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + ret = PublishLNN(g_pkgName, &g_pInfo, nullptr); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); +} + +/** + * @tc.name: PublishLNNTest002 + * @tc.desc: Test for invalid packageName. + * @tc.type: FUNC + * @tc.require:The PublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, PublishLNNTest002, TestSize.Level1) +{ + g_pInfo.publishId = GetPublishId(); + int32_t ret = PublishLNN(g_erroPkgName1, &g_pInfo, &g_publishCb); + EXPECT_NE(ret, SOFTBUS_OK); +} + +/** + * @tc.name: PublishLNNTest003 + * @tc.desc: Test for invalid PublishInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, PublishLNNTest003, TestSize.Level1) +{ + PublishInfo testInfo = { + .publishId = GetPublishId(), + .mode = DISCOVER_MODE_ACTIVE, + .medium = COAP, + .freq = MID, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata2", + .dataLen = (unsigned int) strlen("capdata2"), + .ranging = false + }; + + testInfo.mode = (DiscoverMode)(DISCOVER_MODE_ACTIVE + 1); + int32_t ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.mode = (DiscoverMode)(DISCOVER_MODE_PASSIVE - 1); + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.mode = DISCOVER_MODE_PASSIVE; + + testInfo.medium = (ExchangeMedium)(COAP + 1); + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.medium = (ExchangeMedium)(AUTO - 1); + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.medium = COAP; + + testInfo.freq = (ExchangeFreq)(FREQ_BUTT); + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.freq = (ExchangeFreq)(LOW - 1); + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.freq = LOW; + + testInfo.capabilityData = nullptr; + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.capabilityData = (unsigned char *)"capdata1"; + + testInfo.dataLen = ERRO_CAPDATA_LEN; + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); +} + +/** + * @tc.name: PublishLNNTest004 + * @tc.desc: Test GetPublishId and PublishLNN to see if they are running properly. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, PublishLNNTest004, TestSize.Level1) +{ + g_pInfo.publishId = GetPublishId(); + int32_t ret = PublishLNN(g_pkgName, &g_pInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_pInfo.publishId); + + g_pInfo1.publishId = GetPublishId(); + ret = PublishLNN(g_pkgName, &g_pInfo1, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_pInfo1.publishId); + + g_pInfo1.publishId = GetPublishId(); + ret = PublishLNN(g_pkgName_1, &g_pInfo1, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName_1, g_pInfo1.publishId); +} + +/** + * @tc.name: PublishLNNTest005 + * @tc.desc: Test different freq with passive CoAP publish. + * @tc.type: FUNC + * @tc.require: The PublishLNN and StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, PublishLNNTest005, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = COAP; + + int32_t ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = MID; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = SUPER_HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = EXTREME_HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: PublishLNNTest006 + * @tc.desc: Test different freq with passive BLE publish. + * @tc.type: FUNC + * @tc.require: The PublishLNN and StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, PublishLNNTest006, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + int32_t ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = MID; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = SUPER_HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = EXTREME_HIGH; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); +} + +/** + * @tc.name: PublishLNNTest007 + * @tc.desc: Test different capability with passive CoAP publish. + * @tc.type: FUNC + * @tc.require: The PublishLNN and StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, PublishLNNTest007, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = COAP; + + int32_t ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "hicall"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "profile"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "homevisionPic"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "castPlus"; + g_publishInfo.capabilityData = (unsigned char *)"{\"castPlus\":\"capdata2\"}"; + g_publishInfo.dataLen = (unsigned int) strlen("{\"castPlus\":\"capdata2\"}"); + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + g_publishInfo.capabilityData = (unsigned char *)"capdata2"; + g_publishInfo.dataLen = (unsigned int) strlen("capdata2"); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "aaCapability"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "ddmpCapability"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "osdCapability"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); +} + +/** + * @tc.name: PublishLNNTest008 + * @tc.desc: Test different capability with passive BLE publish: dvKit, castPlus, osdCapability + * @tc.type: FUNC + * @tc.require: The PublishLNN and StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, PublishLNNTest008, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + g_publishInfo.capability = "dvKit"; + int32_t ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "castPlus"; + g_publishInfo.capabilityData = (unsigned char *)"{\"castPlus\":\"capdata2\"}"; + g_publishInfo.dataLen = (unsigned int) strlen("{\"castPlus\":\"capdata2\"}"); + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + g_publishInfo.capabilityData = (unsigned char *)"capdata2"; + g_publishInfo.dataLen = (unsigned int) strlen("capdata2"); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + + g_publishInfo.capability = "osdCapability"; + ret = PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); +} + +/** + * @tc.name: RefreshLNNTest001 + * @tc.desc: Test for invalid parameters + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest001, TestSize.Level1) +{ + int32_t ret = RefreshLNN(nullptr, &g_sInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + ret = RefreshLNN(g_pkgName, nullptr, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + ret = RefreshLNN(g_pkgName, &g_sInfo, nullptr); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); +} + +/** + * @tc.name: RefreshLNNTest002 + * @tc.desc: Test for invalid packageName. + * @tc.type: FUNC + * @tc.require:The PublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest002, TestSize.Level1) +{ + g_sInfo.subscribeId = GetSubscribeId(); + int32_t ret = RefreshLNN(g_erroPkgName1, &g_sInfo, &g_refreshCb); + EXPECT_NE(ret, SOFTBUS_OK); +} + +/** + * @tc.name: RefreshLNNTest003 + * @tc.desc: Test for invalid SubscribeInfo. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest003, TestSize.Level1) +{ + SubscribeInfo testInfo = { + .subscribeId = GetSubscribeId(), + .mode = DISCOVER_MODE_ACTIVE, + .medium = COAP, + .freq = MID, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata3", + .dataLen = (unsigned int) strlen("capdata3") + }; + + testInfo.mode = (DiscoverMode)(DISCOVER_MODE_ACTIVE + 1); + int32_t ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.mode = (DiscoverMode)(DISCOVER_MODE_PASSIVE - 1); + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.mode = DISCOVER_MODE_PASSIVE; + + testInfo.medium = (ExchangeMedium)(COAP + 1); + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.medium = (ExchangeMedium)(AUTO - 1); + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.medium = COAP; + + testInfo.freq = (ExchangeFreq)(FREQ_BUTT); + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.freq = (ExchangeFreq)(LOW - 1); + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.freq = LOW; + + testInfo.capabilityData = nullptr; + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + testInfo.capabilityData = (unsigned char *)"capdata1"; + + testInfo.dataLen = ERRO_CAPDATA_LEN; + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); +} + +/** + * @tc.name: RefreshLNNTest004 + * @tc.desc: Verify the RefreshLNN normal case. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest004, TestSize.Level1) +{ + g_sInfo.subscribeId = GetSubscribeId(); + int32_t ret = RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_sInfo.subscribeId); + + g_sInfo1.subscribeId = GetSubscribeId(); + ret = RefreshLNN(g_pkgName, &g_sInfo1, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_sInfo1.subscribeId); + + g_sInfo1.subscribeId = GetSubscribeId(); + ret = RefreshLNN(g_pkgName_1, &g_sInfo1, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_sInfo1.subscribeId); +} + +/** + * @tc.name: RefreshLNNTest005 + * @tc.desc: Test different freq with passive CoAP discovery. + * @tc.type: FUNC + * @tc.require: The RefreshLNN and StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest005, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = COAP; + + int32_t ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = MID; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = SUPER_HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = EXTREME_HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: RefreshLNNTest006 + * @tc.desc: Test different freq with passive BLE discovery. + * @tc.type: FUNC + * @tc.require: The RefreshLNN and StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest006, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + int32_t ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = MID; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = SUPER_HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = EXTREME_HIGH; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); +} + +/** + * @tc.name: RefreshLNNTest007 + * @tc.desc: Test different capability with passive CoAP discovery. + * @tc.type: FUNC + * @tc.require: The RefreshLNN and StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest007, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = COAP; + + int32_t ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "hicall"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "profile"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "homevisionPic"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "castPlus"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "aaCapability"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "ddmpCapability"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "osdCapability"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); +} + +/** + * @tc.name: RefreshLNNTest008 + * @tc.desc: Test different capability with passive BLE discovery: dvKit, castPlus, osdCapability + * @tc.type: FUNC + * @tc.require: The RefreshLNN and StopRefreshLNN operates normally. + */ +HWTEST_F(DiscSdkTest, RefreshLNNTest008, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + g_subscribeInfo.capability = "dvKit"; + int32_t ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "castPlus"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + + g_subscribeInfo.capability = "osdCapability"; + ret = RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); +} + +/** + * @tc.name: StopPublishLNNTest001 + * @tc.desc: Verify StopPublishLNN invalid parameter. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopPublishLNNTest001, TestSize.Level1) +{ + int32_t tmpId = GetPublishId(); + g_pInfo.publishId = tmpId; + PublishLNN(g_pkgName, &g_pInfo, &g_publishCb); + + int32_t ret = StopPublishLNN(nullptr, tmpId); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + ret = StopPublishLNN(g_erroPkgName, tmpId); + EXPECT_NE(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopPublishLNNTest002 + * @tc.desc: Verify PublishLNN and StopPublishLNN normal case. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopPublishLNNTest002, TestSize.Level1) +{ + int32_t tmpId1 = GetPublishId(); + int32_t tmpId2 = GetPublishId(); + + g_pInfo.publishId = tmpId1; + PublishLNN(g_pkgName, &g_pInfo, &g_publishCb); + g_pInfo1.publishId = tmpId2; + PublishLNN(g_pkgName, &g_pInfo1, &g_publishCb); + + int32_t ret = StopPublishLNN(g_pkgName, tmpId1); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, tmpId2); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopPublishLNNTest003 + * @tc.desc: Verify PublishLNN and StopPublishLNN same parameter again. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopPublishLNNTest003, TestSize.Level1) +{ + int32_t tmpId = GetPublishId(); + g_pInfo.publishId = tmpId; + PublishLNN(g_pkgName, &g_pInfo, &g_publishCb); + + int32_t ret = StopPublishLNN(g_pkgName, tmpId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopPublishLNNTest004 + * @tc.desc: Test different freq with stop passive CoAP publish. + * @tc.type: FUNC + * @tc.require: The StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, StopPublishLNNTest004, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = COAP; + + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + int32_t ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = MID; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = SUPER_HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_publishInfo.freq = EXTREME_HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopPublishLNNTest005 + * @tc.desc: Test different freq with stop passive BLE publish. + * @tc.type: FUNC + * @tc.require: The StopPublishLNN operates normally. + */ +HWTEST_F(DiscSdkTest, StopPublishLNNTest005, TestSize.Level1) +{ + g_publishInfo.publishId = GetPublishId(); + g_publishInfo.mode = DISCOVER_MODE_PASSIVE; + g_publishInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + int32_t ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = MID; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = SUPER_HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_publishInfo.freq = EXTREME_HIGH; + PublishLNN(g_pkgName, &g_publishInfo, &g_publishCb); + ret = StopPublishLNN(g_pkgName, g_publishInfo.publishId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); +} + +/** + * @tc.name: StopRefreshLNNTest001 + * @tc.desc: Verify StopRefreshLNN invalid parameter. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopRefreshLNNTest001, TestSize.Level1) +{ + int32_t tmpId = GetSubscribeId(); + g_sInfo.subscribeId = tmpId; + RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb); + + int32_t ret = StopRefreshLNN(nullptr, tmpId); + EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + ret = StopRefreshLNN(g_erroPkgName, tmpId); + EXPECT_NE(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopRefreshLNNTest002 + * @tc.desc: test under normal conditions. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopRefreshLNNTest002, TestSize.Level1) +{ + int32_t tmpId1 = GetSubscribeId(); + int32_t tmpId2 = GetSubscribeId(); + + g_sInfo.subscribeId = tmpId1; + RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb); + g_sInfo1.subscribeId = tmpId2; + RefreshLNN(g_pkgName, &g_sInfo1, &g_refreshCb); + + int32_t ret = StopRefreshLNN(g_pkgName, tmpId1); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, tmpId2); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopRefreshLNNTest003 + * @tc.desc: Verify RefreshLNN and StopRefreshLNN same parameter again. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DiscSdkTest, StopRefreshLNNTest003, TestSize.Level1) +{ + int32_t tmpId = GetSubscribeId(); + g_sInfo.subscribeId = tmpId; + RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb); + + int32_t ret = StopRefreshLNN(g_pkgName, tmpId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopRefreshLNNTest004 + * @tc.desc:Test different freq with stop passive CoAP discovery. + * @tc.type: FUNC + * @tc.require: The StopRefreshLNN operates normally + */ +HWTEST_F(DiscSdkTest, StopRefreshLNNTest004, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = COAP; + + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + int32_t ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = MID; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = SUPER_HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); + + g_subscribeInfo.freq = EXTREME_HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name: StopRefreshLNNTest005 + * @tc.desc:Test different freq with stop passive BLE discovery. + * @tc.type: FUNC + * @tc.require: The StopRefreshLNN operates normally + */ +HWTEST_F(DiscSdkTest, StopRefreshLNNTest005, TestSize.Level1) +{ + g_subscribeInfo.subscribeId = GetSubscribeId(); + g_subscribeInfo.mode = DISCOVER_MODE_PASSIVE; + g_subscribeInfo.medium = BLE; + + bool isBtOn = SoftbusTestGetBtStatus(); + printf("bt status %s\n", isBtOn ? "on" : "off"); + + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + int32_t ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = MID; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = SUPER_HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); + + g_subscribeInfo.freq = EXTREME_HIGH; + RefreshLNN(g_pkgName, &g_subscribeInfo, &g_refreshCb); + ret = StopRefreshLNN(g_pkgName, g_subscribeInfo.subscribeId); + EXPECT_EQ(isBtOn, (ret == SOFTBUS_OK)); +} + +/** + * @tc.name:DiscRecoveryPublishTest01 + * @tc.desc: Test recovery publish. + * @tc.in: Test module, Test number, Test levels. + * @tc.out: Zero + * @tc.type: FUNC + * @tc.require:The DiscRecoveryPublish operates normally + */ +HWTEST_F(DiscSdkTest, DiscRecoveryPublishTest01, TestSize.Level1) +{ + int ret; + PublishInfo testInfo = { + .publishId = GetPublishId(), + .mode = DISCOVER_MODE_PASSIVE, + .medium = COAP, + .freq = LOW, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata2", + .dataLen = (unsigned int) strlen("capdata2") + }; + BusCenterClientDeinit(); + BusCenterClientInit(); + ret = DiscRecoveryPublish(); + EXPECT_EQ(ret, SOFTBUS_OK); + + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = DiscRecoveryPublish(); + EXPECT_TRUE(ret != 0); + ret = StopPublishLNN(g_pkgName, testInfo.publishId); + + ret = PublishLNN(g_pkgName, &testInfo, &g_publishCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopPublishLNN(g_pkgName, testInfo.publishId); + ret = DiscRecoveryPublish(); + EXPECT_EQ(ret, SOFTBUS_OK); +} + +/** + * @tc.name:DiscRecoverySubscribeTest01 + * @tc.desc: Test recovery subscribe. + * @tc.in: Test module, Test number, Test levels. + * @tc.out: Zero + * @tc.type: FUNC + * @tc.require:The DiscRecoverySubscribe operates normally + */ +HWTEST_F(DiscSdkTest, DiscRecoverySubscribeTest01, TestSize.Level1) +{ + int ret; + SubscribeInfo testInfo = { + .subscribeId = GetSubscribeId(), + .mode = DISCOVER_MODE_PASSIVE, + .medium = AUTO, + .freq = LOW, + .isSameAccount = true, + .isWakeRemote = false, + .capability = "dvKit", + .capabilityData = (unsigned char *)"capdata3", + .dataLen = (unsigned int) strlen("capdata3") + }; + BusCenterClientDeinit(); + BusCenterClientInit(); + ret = DiscRecoverySubscribe(); + EXPECT_EQ(ret, SOFTBUS_OK); + + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = DiscRecoverySubscribe(); + EXPECT_TRUE(ret != 0); + ret = StopRefreshLNN(g_pkgName, testInfo.subscribeId); + + ret = RefreshLNN(g_pkgName, &testInfo, &g_refreshCb); + EXPECT_EQ(ret, SOFTBUS_OK); + ret = StopRefreshLNN(g_pkgName, testInfo.subscribeId); + ret = DiscRecoverySubscribe(); + EXPECT_EQ(ret, SOFTBUS_OK); +} +} // namespace OHOS \ No newline at end of file diff --git a/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.c b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.c new file mode 100644 index 0000000000..9b07e04fb4 --- /dev/null +++ b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "disc_sdk_test_bt_status.h" + +#include "c_header/ohos_bt_gap.h" + +bool SoftbusTestGetBtStatus(void) +{ + return IsBleEnabled(); +} \ No newline at end of file diff --git a/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.h b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.h new file mode 100644 index 0000000000..6a8777b7ca --- /dev/null +++ b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISC_SDK_TEST_BT_STATUS_H +#define DISC_SDK_TEST_BT_STATUS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +bool SoftbusTestGetBtStatus(void); + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // DISC_SDK_TEST_BT_STATUS_H \ No newline at end of file diff --git a/tests/sdk/discovery/unittest/disc_sdk_test_bt_status_virtual.c b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status_virtual.c new file mode 100644 index 0000000000..8772618bd1 --- /dev/null +++ b/tests/sdk/discovery/unittest/disc_sdk_test_bt_status_virtual.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "disc_sdk_test_bt_status.h" + +bool SoftbusTestGetBtStatus(void) +{ + return false; +} \ No newline at end of file