fix: restore discovery sdk tests

Signed-off-by: JanierVan <fanjingya1@huawei.com>
This commit is contained in:
JanierVan 2024-09-05 17:19:44 +08:00
parent d77b7ffeb5
commit e87cb5d7f1
8 changed files with 1462 additions and 0 deletions

View File

@ -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",

View File

@ -18,3 +18,8 @@ group("benchmarktest") {
testonly = true
deps = [ "benchmarktest:benchmarktest" ]
}
group("unittest") {
testonly = true
deps = [ "unittest:unittest" ]
}

View File

@ -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",
]
}
}

View File

@ -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 <cstdio>
#include <ctime>
#include <gtest/gtest.h>
#include <sys/time.h>
#include <unistd.h>
#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

File diff suppressed because it is too large Load Diff

View File

@ -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();
}

View File

@ -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 <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
bool SoftbusTestGetBtStatus(void);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // DISC_SDK_TEST_BT_STATUS_H

View File

@ -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;
}