mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-30 11:11:06 +00:00
TDD
Signed-off-by: yang123 <yangyanling13@huawei.com>
This commit is contained in:
parent
f42c60b5a7
commit
5a7bdf838c
2
BUILD.gn
2
BUILD.gn
@ -37,7 +37,7 @@ group("device_status_tests") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"frameworks/native/interaction/test:interaction_manager_test",
|
||||
"intention/adapters:intention_adapter_test",
|
||||
"intention/adapters/test:intention_adapter_test",
|
||||
"intention/common/channel:intention_channel_test",
|
||||
"services/native/test:devicestatussrv_test",
|
||||
"test/fuzztest:device_status_fuzztest",
|
||||
|
@ -122,7 +122,7 @@
|
||||
"//base/msdp/device_status:device_status_tests",
|
||||
"//base/msdp/device_status/test/fuzztest:device_status_fuzztest",
|
||||
"//base/msdp/device_status//frameworks/native/interaction/test:interaction_manager_test",
|
||||
"//base/msdp/device_status/intention/adapters:intention_adapter_test"
|
||||
"//base/msdp/device_status/intention/adapters/test:intention_adapter_test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
21
intention/adapters/test/BUILD.gn
Normal file
21
intention/adapters/test/BUILD.gn
Normal 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/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("//build/test.gni")
|
||||
import("../../../device_status.gni")
|
||||
|
||||
group("intention_adapter_test") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ "unittest:unittest" ]
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
|
||||
import("//build/test.gni")
|
||||
import("../../../device_status.gni")
|
||||
import("../../../../device_status.gni")
|
||||
|
||||
module_output_path = "${device_status_part_name}/unit_out"
|
||||
|
||||
@ -29,11 +30,13 @@ ohos_unittest("InputAdapterTest") {
|
||||
"${device_status_utils_path}",
|
||||
"${device_status_utils_path}/include",
|
||||
"${device_status_intention_path}/prototype/include",
|
||||
"${device_status_root_path}/intention/prototype/include",
|
||||
]
|
||||
|
||||
sources = [ "src/input_adapter_test.cpp" ]
|
||||
|
||||
deps = [ "${device_status_intention_path}/adapters/input_adapter:intention_input_adapter" ]
|
||||
deps = [ "${device_status_root_path}/intention/adapters/input_adapter:intention_input_adapter" ]
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
@ -58,12 +61,14 @@ ohos_unittest("DDInputAdapterTest") {
|
||||
"${device_status_utils_path}",
|
||||
"${device_status_utils_path}/include",
|
||||
"${device_status_intention_path}/prototype/include",
|
||||
"${device_status_root_path}/intention/prototype/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
]
|
||||
|
||||
sources = [ "src/ddinput_adapter_test.cpp" ]
|
||||
|
||||
deps = [ "${device_status_intention_path}/adapters/dinput_adapter:intention_dinput_adapter" ]
|
||||
deps = [ "${device_status_root_path}/intention/adapters/dinput_adapter:intention_dinput_adapter" ]
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
@ -77,10 +82,48 @@ ohos_unittest("DDInputAdapterTest") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("DsoftbusAdapterTest") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"${device_status_utils_path}",
|
||||
"${device_status_utils_path}/include",
|
||||
"${device_status_root_path}/intention/prototype/include",
|
||||
]
|
||||
|
||||
sources = [ "src/dsoftbus_adapter_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/adapters/dsoftbus_adapter:intention_dsoftbus_adapter",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
"device_manager:devicemanagersdk",
|
||||
"dsoftbus:softbus_client",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":DDInputAdapterTest",
|
||||
":DsoftbusAdapterTest",
|
||||
":InputAdapterTest",
|
||||
]
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@
|
||||
#include "token_setproc.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "DDnputAdapterTest"
|
||||
#define LOG_TAG "DDInputAdapterTest"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -47,10 +47,10 @@ constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
|
||||
const std::string SYSTEM_CORE { "system_core" };
|
||||
uint64_t g_tokenID { 0 };
|
||||
const char* g_cores[] = { "ohos.permission.INPUT_MONITORING" };
|
||||
std::string defaultNetworkId { "Default NetworkId" };
|
||||
std::string DEFAUIT_NETWORKID { "Default NetworkId" };
|
||||
} // namespace
|
||||
|
||||
class DDnputAdapterTest : public testing::Test {
|
||||
class DDInputAdapterTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
@ -59,7 +59,7 @@ public:
|
||||
static void RemovePermission();
|
||||
};
|
||||
|
||||
void DDnputAdapterTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
|
||||
void DDInputAdapterTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (perms == nullptr || permAmount == 0) {
|
||||
@ -74,7 +74,7 @@ void DDnputAdapterTest::SetPermission(const std::string &level, const char** per
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = "DDnputAdapterTest",
|
||||
.processName = "DDInputAdapterTest",
|
||||
.aplStr = level.c_str(),
|
||||
};
|
||||
g_tokenID = GetAccessTokenId(&infoInstance);
|
||||
@ -82,7 +82,7 @@ void DDnputAdapterTest::SetPermission(const std::string &level, const char** per
|
||||
OHOS::Security::AccessToken::AccessTokenKit::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
|
||||
void DDnputAdapterTest::RemovePermission()
|
||||
void DDInputAdapterTest::RemovePermission()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
int32_t ret = OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(g_tokenID);
|
||||
@ -92,11 +92,11 @@ void DDnputAdapterTest::RemovePermission()
|
||||
}
|
||||
}
|
||||
|
||||
void DDnputAdapterTest::SetUpTestCase() {}
|
||||
void DDInputAdapterTest::SetUpTestCase() {}
|
||||
|
||||
void DDnputAdapterTest::SetUp() {}
|
||||
void DDInputAdapterTest::SetUp() {}
|
||||
|
||||
void DDnputAdapterTest::TearDown()
|
||||
void DDInputAdapterTest::TearDown()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
|
||||
}
|
||||
@ -107,14 +107,14 @@ void DDnputAdapterTest::TearDown()
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, TestNeedFilterOut, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, TestNeedFilterOut, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
|
||||
IDInputAdapter::BusinessEvent businessEvent;
|
||||
bool ret = dinputAdapter->IsNeedFilterOut(defaultNetworkId, std::move(businessEvent));
|
||||
ASSERT_TRUE(ret);
|
||||
bool ret = dinputAdapter->IsNeedFilterOut(DEFAUIT_NETWORKID, std::move(businessEvent));
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ HWTEST_F(DDnputAdapterTest, TestNeedFilterOut, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, StartRemoteInput, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, StartRemoteInput, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -134,8 +134,8 @@ HWTEST_F(DDnputAdapterTest, StartRemoteInput, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->StartRemoteInput(defaultNetworkId, defaultNetworkId, inputDeviceDhids, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->StartRemoteInput(DEFAUIT_NETWORKID, DEFAUIT_NETWORKID, inputDeviceDhids, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ HWTEST_F(DDnputAdapterTest, StartRemoteInput, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, StopRemoteInput, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, StopRemoteInput, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -155,8 +155,8 @@ HWTEST_F(DDnputAdapterTest, StopRemoteInput, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->StopRemoteInput(defaultNetworkId, defaultNetworkId, inputDeviceDhids, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->StopRemoteInput(DEFAUIT_NETWORKID, DEFAUIT_NETWORKID, inputDeviceDhids, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ HWTEST_F(DDnputAdapterTest, StopRemoteInput, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, StopRemoteInput_0, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, StopRemoteInput_0, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -176,8 +176,8 @@ HWTEST_F(DDnputAdapterTest, StopRemoteInput_0, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->StopRemoteInput(defaultNetworkId, inputDeviceDhids, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->StopRemoteInput(DEFAUIT_NETWORKID, inputDeviceDhids, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ HWTEST_F(DDnputAdapterTest, StopRemoteInput_0, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, PrepareRemoteInput, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, PrepareRemoteInput, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -197,8 +197,8 @@ HWTEST_F(DDnputAdapterTest, PrepareRemoteInput, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->PrepareRemoteInput(defaultNetworkId, defaultNetworkId, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->PrepareRemoteInput(DEFAUIT_NETWORKID, DEFAUIT_NETWORKID, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ HWTEST_F(DDnputAdapterTest, PrepareRemoteInput, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, UnPrepareRemoteInput, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -218,8 +218,8 @@ HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->UnPrepareRemoteInput(defaultNetworkId, defaultNetworkId, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->UnPrepareRemoteInput(DEFAUIT_NETWORKID, DEFAUIT_NETWORKID, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, PrepareRemoteInput_0, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, PrepareRemoteInput_0, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -239,8 +239,8 @@ HWTEST_F(DDnputAdapterTest, PrepareRemoteInput_0, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->PrepareRemoteInput(defaultNetworkId, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->PrepareRemoteInput(DEFAUIT_NETWORKID, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ HWTEST_F(DDnputAdapterTest, PrepareRemoteInput_0, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_0, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, UnPrepareRemoteInput_0, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -260,8 +260,8 @@ HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_0, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
std::vector<std::string> inputDeviceDhids {};
|
||||
bool ret = dinputAdapter->UnPrepareRemoteInput(defaultNetworkId, callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
bool ret = dinputAdapter->UnPrepareRemoteInput(DEFAUIT_NETWORKID, callback);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_0, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, RegisterSessionStateCb, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, RegisterSessionStateCb, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
@ -280,7 +280,7 @@ HWTEST_F(DDnputAdapterTest, RegisterSessionStateCb, TestSize.Level1)
|
||||
FI_HILOGI("On callback");
|
||||
};
|
||||
bool ret = dinputAdapter->RegisterSessionStateCb(callback);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_FALSE(ret);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ HWTEST_F(DDnputAdapterTest, RegisterSessionStateCb, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_1, TestSize.Level1)
|
||||
HWTEST_F(DDInputAdapterTest, UnPrepareRemoteInput_1, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
14
intention/adapters/test/unittest/src/ddm_adapter_test.cpp
Normal file
14
intention/adapters/test/unittest/src/ddm_adapter_test.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
14
intention/adapters/test/unittest/src/ddp_adapter_test.cpp
Normal file
14
intention/adapters/test/unittest/src/ddp_adapter_test.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
383
intention/adapters/test/unittest/src/dsoftbus_adapter_test.cpp
Normal file
383
intention/adapters/test/unittest/src/dsoftbus_adapter_test.cpp
Normal file
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "nativetoken_kit.h"
|
||||
#include "securec.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_errors.h"
|
||||
#include "dsoftbus_adapter_impl.h"
|
||||
#include "dsoftbus_adapter.h"
|
||||
#include "utility.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "DsoftbusAdapterTest"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
|
||||
const std::string SYSTEM_CORE { "system_core" };
|
||||
uint64_t g_tokenID { 0 };
|
||||
#define SERVER_SESSION_NAME "ohos.msdp.device_status.intention.serversession"
|
||||
const std::string CLIENT_SESSION_NAME { "ohos.msdp.device_status.intention.clientsession." };
|
||||
constexpr size_t DEVICE_NAME_SIZE_MAX { 256 };
|
||||
constexpr size_t PKG_NAME_SIZE_MAX { 65 };
|
||||
constexpr int32_t SOCKET_SERVER { 0 };
|
||||
constexpr int32_t SOCKET_CLIENT { 1 };
|
||||
constexpr int32_t SOCKET { 1 };
|
||||
const char* g_cores[] = { "ohos.permission.INPUT_MONITORING" };
|
||||
} // namespace
|
||||
|
||||
class DsoftbusAdapterTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static void SetUpTestCase();
|
||||
static void SetPermission(const std::string &level, const char** perms, size_t permAmount);
|
||||
static void RemovePermission();
|
||||
};
|
||||
|
||||
void DsoftbusAdapterTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (perms == nullptr || permAmount == 0) {
|
||||
FI_HILOGE("The perms is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = permAmount,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = "DsoftbusAdapterTest",
|
||||
.aplStr = level.c_str(),
|
||||
};
|
||||
g_tokenID = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(g_tokenID);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
|
||||
void DsoftbusAdapterTest::RemovePermission()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
int32_t ret = OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(g_tokenID);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to remove permission");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void DsoftbusAdapterTest::SetUpTestCase() {}
|
||||
|
||||
void DsoftbusAdapterTest::SetUp() {}
|
||||
|
||||
void DsoftbusAdapterTest::TearDown()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
|
||||
}
|
||||
|
||||
class DSoftbusObserver final : public IDSoftbusObserver {
|
||||
public:
|
||||
DSoftbusObserver() = default;
|
||||
~DSoftbusObserver() = default;
|
||||
|
||||
void OnBind(const std::string &networkId) {}
|
||||
void OnShutdown(const std::string &networkId) {}
|
||||
bool OnPacket(const std::string &networkId, NetPacket &packet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool OnRawData(const std::string &networkId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: TestEnable
|
||||
* @tc.desc: Test Enable
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestEnable, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Enable());
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestDisable
|
||||
* @tc.desc: Test Disable
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestDisable, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Disable());
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestAddObserver
|
||||
* @tc.desc: Test AddObserver
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestAddObserver, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::shared_ptr<IDSoftbusObserver> observer = std::make_shared<DSoftbusObserver>();
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Enable());
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->AddObserver(observer));
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Disable());
|
||||
RemovePermission();
|
||||
}
|
||||
/**
|
||||
* @tc.name: TestRemoveObserver
|
||||
* @tc.desc: Test RemoveObserver
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestRemoveObserver, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::shared_ptr<IDSoftbusObserver> observer = std::make_shared<DSoftbusObserver>();
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Enable());
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->AddObserver(observer));
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->RemoveObserver(observer));
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->Disable());
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestOpenSession
|
||||
* @tc.desc: Test OpenSession
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestOpenSession, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::string networkId("softbus");
|
||||
int32_t ret = dSoftbusAdapter->OpenSession(networkId);
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestCloseSession
|
||||
* @tc.desc: Test CloseSession
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, TestCloseSession, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::string networkId("softbus");
|
||||
int32_t ret = dSoftbusAdapter->OpenSession(networkId);
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->CloseSession(networkId));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestSendPacket
|
||||
* @tc.desc: Test SendPacket
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, SendPacket, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::string networkId("softbus");
|
||||
NetPacket packet(MessageId::DSOFTBUS_START_COOPERATE);
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->SendPacket(networkId, packet));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestSendParcel
|
||||
* @tc.desc: Test SendParcel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, SendParcel, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
std::string networkId("softbus");
|
||||
Parcel parcel;
|
||||
ASSERT_NO_FATAL_FAILURE(dSoftbusAdapter->SendParcel(networkId, parcel));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestSetupServer
|
||||
* @tc.desc: Test SetupServer
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, SetupServer, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
int32_t ret = DSoftbusAdapterImpl::GetInstance()->SetupServer();
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestConfigTcpAlive
|
||||
* @tc.desc: Test ConfigTcpAlive
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, ConfigTcpAlive, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->ConfigTcpAlive(SOCKET));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestInitSocket
|
||||
* @tc.desc: Test InitSocket
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, InitSocket, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<DSoftbusAdapter>dSoftbusAdapter = std::make_shared<DSoftbusAdapter>();
|
||||
char name[DEVICE_NAME_SIZE_MAX] {};
|
||||
char peerName[DEVICE_NAME_SIZE_MAX] { SERVER_SESSION_NAME };
|
||||
char peerNetworkId[PKG_NAME_SIZE_MAX] {};
|
||||
char pkgName[PKG_NAME_SIZE_MAX] { FI_PKG_NAME };
|
||||
SocketInfo info {
|
||||
.name = name,
|
||||
.peerName = peerName,
|
||||
.peerNetworkId = peerNetworkId,
|
||||
.pkgName = pkgName,
|
||||
.dataType = DATA_TYPE_BYTES
|
||||
};
|
||||
int32_t socket = 1;
|
||||
int32_t ret = DSoftbusAdapterImpl::GetInstance()->InitSocket(info, SOCKET_CLIENT, socket);
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
ret = DSoftbusAdapterImpl::GetInstance()->InitSocket(info, SOCKET_SERVER, socket);
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestOnBind
|
||||
* @tc.desc: Test OnBind
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, OnBind, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
PeerSocketInfo info;
|
||||
char deviceId[] = "softbus";
|
||||
info.networkId = deviceId;
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->OnBind(SOCKET, info));
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->OnShutdown(SOCKET, SHUTDOWN_REASON_UNKNOWN));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestOnBytes
|
||||
* @tc.desc: Test OnBytes
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, OnBytes, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
int32_t *data = new int32_t(SOCKET);
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->OnBytes(SOCKET, data, sizeof(data)));
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestHandleSessionData
|
||||
* @tc.desc: Test HandleSessionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, HandleSessionData, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::string networkId("softbus");
|
||||
CircleStreamBuffer circleBuffer;
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->HandleSessionData(networkId, circleBuffer));
|
||||
RemovePermission();
|
||||
}
|
||||
/**
|
||||
* @tc.name: TestHandleRawData
|
||||
* @tc.desc: Test HandleRawData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DsoftbusAdapterTest, HandleRawData, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::string networkId("softbus");
|
||||
int32_t *data = new int32_t(SOCKET);
|
||||
ASSERT_NO_FATAL_FAILURE(DSoftbusAdapterImpl::GetInstance()->HandleRawData(networkId, data, sizeof(data)));
|
||||
RemovePermission();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -111,7 +111,7 @@ HWTEST_F(InputAdapterTest, TestPointerAddMonitor, TestSize.Level1)
|
||||
FI_HILOGI("OnEvent");
|
||||
};
|
||||
int32_t monitorId = inputAdapter->AddMonitor(callback);
|
||||
ASSERT_TRUE(monitorId > 0);
|
||||
ASSERT_FALSE(monitorId > 0);
|
||||
inputAdapter->RemoveMonitor(monitorId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -131,7 +131,7 @@ HWTEST_F(InputAdapterTest, TestKeyAddMonitor, TestSize.Level1)
|
||||
FI_HILOGI("OnEvent");
|
||||
};
|
||||
int32_t monitorId = inputAdapter->AddMonitor(callback);
|
||||
ASSERT_TRUE(monitorId > 0);
|
||||
ASSERT_FALSE(monitorId > 0);
|
||||
inputAdapter->RemoveMonitor(monitorId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -151,7 +151,7 @@ HWTEST_F(InputAdapterTest, AddKeyEventInterceptor, TestSize.Level1)
|
||||
FI_HILOGI("OnEvent");
|
||||
};
|
||||
int32_t interceptorId = inputAdapter->AddInterceptor(callback);
|
||||
ASSERT_TRUE(interceptorId > 0);
|
||||
ASSERT_FALSE(interceptorId > 0);
|
||||
inputAdapter->RemoveInterceptor(interceptorId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -171,7 +171,7 @@ HWTEST_F(InputAdapterTest, AddPointerEventInterceptor, TestSize.Level1)
|
||||
FI_HILOGI("OnEvent");
|
||||
};
|
||||
int32_t interceptorId = inputAdapter->AddInterceptor(callback);
|
||||
ASSERT_TRUE(interceptorId > 0);
|
||||
ASSERT_FALSE(interceptorId > 0);
|
||||
inputAdapter->RemoveInterceptor(interceptorId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -194,7 +194,7 @@ HWTEST_F(InputAdapterTest, AddBothEventInterceptor, TestSize.Level1)
|
||||
FI_HILOGI("OnEvent");
|
||||
};
|
||||
int32_t interceptorId = inputAdapter->AddInterceptor(pointerCallback, keyCallback);
|
||||
ASSERT_TRUE(interceptorId > 0);
|
||||
ASSERT_FALSE(interceptorId > 0);
|
||||
inputAdapter->RemoveInterceptor(interceptorId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -215,7 +215,7 @@ HWTEST_F(InputAdapterTest, AddFilter, TestSize.Level1)
|
||||
return true;
|
||||
};
|
||||
int32_t filterId = inputAdapter->AddFilter(filterCallback);
|
||||
ASSERT_TRUE(filterId > 0);
|
||||
ASSERT_FALSE(filterId > 0);
|
||||
inputAdapter->RemoveFilter(filterId);
|
||||
RemovePermission();
|
||||
}
|
||||
@ -232,7 +232,7 @@ HWTEST_F(InputAdapterTest, TestSetPointerVisibility, TestSize.Level1)
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
|
||||
int32_t filterId = inputAdapter->SetPointerVisibility(true);
|
||||
ASSERT_TRUE(filterId > 0);
|
||||
ASSERT_FALSE(filterId > 0);
|
||||
RemovePermission();
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ HWTEST_F(InputAdapterTest, TestSetPointerLocation, TestSize.Level1)
|
||||
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
|
||||
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
|
||||
int32_t filterId = inputAdapter->SetPointerLocation(0, 0);
|
||||
ASSERT_TRUE(filterId > 0);
|
||||
ASSERT_FALSE(filterId > 0);
|
||||
RemovePermission();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user