diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index f0af8d78f5bd582c7e922368ee98b3acc709e454..8e572f9a316271d8f0b5d53bd5a89f9ba6572171 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -89,6 +89,7 @@ group("unittest") { ":UTTest_mine_softbus_listener", ":UTTest_mini_tools_kit", ":UTTest_multiple_user_connector", + ":UTTest_oh_device_manager", ":UTTest_permission_manager", ":UTTest_pin_auth", ":UTTest_pin_auth_ui", @@ -1109,6 +1110,43 @@ ohos_unittest("UTTest_permission_manager") { ## UnitTest UTTest_permission_manager }}} +## UnitTest UTTest_oh_device_manager {{{ +ohos_unittest("UTTest_oh_device_manager") { + module_out_path = module_out_path + + include_dirs = [ + "${devicemanager_path}/interfaces/kits/ndk/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${innerkits_path}/native_cpp/include", + ] + sources = [ + "${devicemanager_path}/interfaces/kits/ndk/src/dm_client.cpp", + "${devicemanager_path}/interfaces/kits/ndk/src/oh_device_manager.cpp", + "${devicemanager_path}/test/unittest/UTTest_oh_device_manager.cpp", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanager_ndk\"", + "LOG_DOMAIN=0xD004110", + ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +## UnitTest UTTest_oh_device_manager }}} + ## UnitTest UTTest_device_manager_notify {{{ ohos_unittest("UTTest_device_manager_notify") { module_out_path = module_out_path diff --git a/test/unittest/UTTest_oh_device_manager.cpp b/test/unittest/UTTest_oh_device_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03012d452c50b733b0cabbe8cca3e1f0ce58e02b --- /dev/null +++ b/test/unittest/UTTest_oh_device_manager.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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 "UTTest_oh_device_manager.h" + +#include + +#include "dm_client.h" +#include "dm_log.h" +#include "oh_device_manager_err_code.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void OhDeviceManagerTest::SetUp() {} + +void OhDeviceManagerTest::TearDown() {} + +void OhDeviceManagerTest::SetUpTestCase() {} + +void OhDeviceManagerTest::TearDownTestCase() {} +namespace { +HWTEST_F(OhDeviceManagerTest, OH_DeviceManager_GetLocalDeviceName_001, testing::ext::TestSize.Level0) +{ + char *localDeviceName = nullptr; + unsigned int len = 0; + int32_t result = OH_DeviceManager_GetLocalDeviceName(&localDeviceName, len); + + EXPECT_EQ(result, DM_ERR_OBTAIN_BUNDLE_NAME); + + delete[] localDeviceName; +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_oh_device_manager.h b/test/unittest/UTTest_oh_device_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..a4456279eeb2f9f2d91868333e96ea24cfb8f91d --- /dev/null +++ b/test/unittest/UTTest_oh_device_manager.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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 OHOS_OH_DEVICE_MANAGER_TEST_H +#define OHOS_OH_DEVICE_MANAGER_TEST_H + +#include +#include "oh_device_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class OhDeviceManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif \ No newline at end of file