1 /*
2 * Copyright (c) 2022-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
16 #include "dms_device_info_test.h"
17
18 #include "deviceManager/dms_device_info.h"
19 #include "parcel_helper.h"
20 #include "test_log.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace DistributedSchedule {
27 namespace {
28 const std::string TAG = "DmsDeviceInfo";
29 }
SetUpTestCase()30 void DmsDeviceInfoTest::SetUpTestCase()
31 {
32 }
33
TearDownTestCase()34 void DmsDeviceInfoTest::TearDownTestCase()
35 {
36 }
37
SetUp()38 void DmsDeviceInfoTest::SetUp()
39 {
40 }
41
TearDown()42 void DmsDeviceInfoTest::TearDown()
43 {
44 }
45
46 /**
47 * @tc.name: testGet_001
48 * @tc.desc: test Get functions.
49 * @tc.type: FUNC
50 */
HWTEST_F(DmsDeviceInfoTest, testGet_001, TestSize.Level1)51 HWTEST_F(DmsDeviceInfoTest, testGet_001, TestSize.Level1)
52 {
53 DTEST_LOG << "DmsDeviceInfoTest testGet_001 begin" << std::endl;
54 DmsDeviceInfo dmsDeviceInfo("invalid deviceName", 1, "invalid networkId");
55 /**
56 * @tc.steps: step1. test GetDeviceName;
57 */
58 EXPECT_EQ("invalid deviceName", dmsDeviceInfo.GetDeviceName());
59
60 /**
61 * @tc.steps: step2. test GetNetworkId;
62 */
63 EXPECT_EQ("invalid networkId", dmsDeviceInfo.GetNetworkId());
64
65 /**
66 * @tc.steps: step3. test GetDeviceType;
67 */
68 EXPECT_EQ(1, dmsDeviceInfo.GetDeviceType());
69 /**
70 * @tc.steps: step4. test GetDeviceState;
71 */
72 EXPECT_EQ(1, dmsDeviceInfo.GetDeviceState());
73 /**
74 * @tc.steps: step5. test Marshalling;
75 */
76 Parcel parcel;
77 std::u16string networkId;
78 std::u16string deviceName;
79 int32_t deviceType;
80 int32_t deviceState;
81 EXPECT_TRUE(dmsDeviceInfo.Marshalling(parcel));
82 PARCEL_READ_HELPER_NORET(parcel, String16, networkId);
83 PARCEL_READ_HELPER_NORET(parcel, String16, deviceName);
84 PARCEL_READ_HELPER_NORET(parcel, Int32, deviceType);
85 PARCEL_READ_HELPER_NORET(parcel, Int32, deviceState);
86 EXPECT_FALSE(networkId.empty());
87 EXPECT_FALSE(deviceName.empty());
88 EXPECT_EQ(1, deviceType);
89 EXPECT_EQ(1, deviceState);
90 DTEST_LOG << "DmsDeviceInfoTest testGet_001 end" << std::endl;
91 }
92 } // DistributedSchedule
93 } // namespace OHOS