1 /*
2 * Copyright (c) 2022 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
16 #include <fcntl.h>
17 #include <cstring>
18
19 #include "gtest/gtest.h"
20 #include "lnn_ip_utils_adapter.h"
21 #include "bus_center_adapter.h"
22 #include "softbus_adapter_file.h"
23 #include "softbus_adapter_mem.h"
24 #include "softbus_errcode.h"
25
26 using namespace std;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 const char *g_FileName = "example.txt";
31
32 class DsoftbusOtherTest : public testing::Test {
33 protected:
34 static void SetUpTestCase(void);
35 static void TearDownTestCase(void);
36 void SetUp();
37 void TearDown();
38 };
SetUpTestCase(void)39 void DsoftbusOtherTest::SetUpTestCase(void)
40 {
41 }
TearDownTestCase(void)42 void DsoftbusOtherTest::TearDownTestCase(void)
43 {
44 int32_t ret = remove(g_FileName);
45 if (ret == 0) {
46 return;
47 }
48 }
SetUp(void)49 void DsoftbusOtherTest::SetUp(void)
50 {
51 }
TearDown(void)52 void DsoftbusOtherTest::TearDown(void)
53 {
54 }
55
56 HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo001, TestSize.Level0)
57 {
58 char value[] = "abcdefg";
59 int32_t len = 10;
60 int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, value, len);
61 EXPECT_EQ(SOFTBUS_OK, ret);
62
63 ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, value, len);
64 EXPECT_EQ(SOFTBUS_OK, ret);
65
66 ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, value, len);
67 EXPECT_EQ(SOFTBUS_OK, ret);
68 }
69
70 /*
71 * @tc.name: GetCommonDevInfoTest002
72 * @tc.desc: value is nullptr
73 * @tc.type: FUNC
74 * @tc.require: 1
75 */
76 HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo002, TestSize.Level0)
77 {
78 int32_t len = 10;
79 int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, NULL, len);
80 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
81
82 ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, NULL, len);
83 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
84
85 ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, NULL, len);
86 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
87
88 ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, NULL, len);
89 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
90
91 ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, NULL, len);
92 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
93 }
94
95 /*
96 * @tc.name: GetCommonDevInfoTest003
97 * @tc.desc: len is illegal
98 * @tc.type: FUNC
99 * @tc.require: 1
100 */
101 HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo003, TestSize.Level0)
102 {
103 char value[] = "abcdefg";
104 int32_t len = 0;
105 int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len);
106 EXPECT_EQ(SOFTBUS_ERR, ret);
107
108 ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len);
109 EXPECT_EQ(SOFTBUS_ERR, ret);
110 }
111
112 /*
113 * @tc.name: GetCommonDevInfoTest004
114 * @tc.desc: value is illegal
115 * @tc.type: FUNC
116 * @tc.require: 1
117 */
118 HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo004, TestSize.Level0)
119 {
120 char value[] = "abcdefg";
121 int32_t len = 10;
122 int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len);
123 EXPECT_EQ(SOFTBUS_ERR, ret);
124
125 ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len);
126 EXPECT_EQ(SOFTBUS_ERR, ret);
127 }
128 }