1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <cstdint>
16 #include <gtest/gtest.h>
17 #include <securec.h>
18 #include <string>
19
20 #include "gmock/gmock.h"
21 #include "gtest/gtest.h"
22 #include "iservice_registry.h"
23 #include "lnn_async_callback_utils.h"
24 #include "lnn_device_info.h"
25 #include "lnn_devicename_info.h"
26 #include "lnn_local_net_ledger.h"
27 #include "lnn_node_info.h"
28 #include "lnn_ohos_account_adapter.h"
29 #include "lnn_settingdata_event_monitor.h"
30 #include "lnn_settingdata_event_monitor_deps_mock.h"
31 #include "locale_config.h"
32 #include "message_handler.h"
33 #include "softbus_adapter_mem.h"
34 #include "softbus_bus_center.h"
35 #include "softbus_def.h"
36 #include "softbus_error_code.h"
37 #include "system_ability_definition.h"
38
39 using namespace std;
40 using namespace testing;
41 using namespace testing::ext;
42 namespace OHOS {
43 const char *NICK_NAME = "TEST_NICK_NAME";
44 const char *DEFAULT_NAME = "TEST_DEFAULT_NAME";
45 static constexpr const char *INTERNAL_NAME_CONCAT_STRING = "的";
46 static constexpr const char *EXTERNAL_NAME_CONCAT_STRING = "-";
47
48 class LnnSettingdataEventMonitorTest : public testing::Test {
49 protected:
50 static void SetUpTestCase(void);
51 static void TearDownTestCase(void);
52 void SetUp();
53 void TearDown();
54 };
SetUpTestCase(void)55 void LnnSettingdataEventMonitorTest::SetUpTestCase(void) { }
TearDownTestCase(void)56 void LnnSettingdataEventMonitorTest::TearDownTestCase(void) { }
SetUp(void)57 void LnnSettingdataEventMonitorTest::SetUp(void) { }
TearDown(void)58 void LnnSettingdataEventMonitorTest::TearDown(void) { }
59
60 /*
61 * @tc.name: LnnGetSettingDeviceNameTest003
62 * @tc.desc:
63 * @tc.type: FUNC
64 * @tc.require: 1
65 */
66 HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest003, TestSize.Level1)
67 {
68 char deviceName[DEVICE_NAME_BUF_LEN] = { 0 };
69 int32_t ret = LnnGetDeviceDisplayName(NICK_NAME, DEFAULT_NAME, deviceName, DEVICE_NAME_BUF_LEN);
70 EXPECT_TRUE(ret == SOFTBUS_OK || ret == SOFTBUS_NOT_IMPLEMENT);
71 if (ret != SOFTBUS_NOT_IMPLEMENT) {
72 char devName[DEVICE_NAME_BUF_LEN] = {0};
73 std::string language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage();
74 if ("zh-Hans" == language || "zh-Hant" == language) {
75 ASSERT_GT(sprintf_s(devName, DEVICE_NAME_BUF_LEN, "%s%s%s", NICK_NAME,
76 INTERNAL_NAME_CONCAT_STRING, DEFAULT_NAME), 0);
77 EXPECT_EQ(strncmp(devName, deviceName, DEVICE_NAME_BUF_LEN), 0);
78 } else {
79 ASSERT_GT(sprintf_s(devName, DEVICE_NAME_BUF_LEN, "%s%s%s", NICK_NAME,
80 EXTERNAL_NAME_CONCAT_STRING, DEFAULT_NAME), 0);
81 EXPECT_EQ(strncmp(devName, deviceName, DEVICE_NAME_BUF_LEN), 0);
82 }
83 }
84 }
85 } // namespace OHOS