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 "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 */
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 deivceId");
55 /**
56 * @tc.steps: step1. test GetDeviceName;
57 */
58 EXPECT_EQ("invalid deviceName", dmsDeviceInfo.GetDeviceName());
59 /**
60 * @tc.steps: step2. test GetDeviceId;
61 */
62 EXPECT_EQ("invalid deivceId", dmsDeviceInfo.GetDeviceId());
63 /**
64 * @tc.steps: step3. test GetDeviceType;
65 */
66 EXPECT_EQ(1, dmsDeviceInfo.GetDeviceType());
67 /**
68 * @tc.steps: step4. test GetDeviceState;
69 */
70 EXPECT_EQ(1, dmsDeviceInfo.GetDeviceState());
71 /**
72 * @tc.steps: step5. test Marshalling;
73 */
74 Parcel parcel;
75 std::u16string deviceId;
76 std::u16string deviceName;
77 int32_t deviceType;
78 int32_t deviceState;
79 EXPECT_TRUE(dmsDeviceInfo.Marshalling(parcel));
80 PARCEL_READ_HELPER_NORET(parcel, String16, deviceId);
81 PARCEL_READ_HELPER_NORET(parcel, String16, deviceName);
82 PARCEL_READ_HELPER_NORET(parcel, Int32, deviceType);
83 PARCEL_READ_HELPER_NORET(parcel, Int32, deviceState);
84 EXPECT_FALSE(deviceId.empty());
85 EXPECT_FALSE(deviceName.empty());
86 EXPECT_EQ(1, deviceType);
87 EXPECT_EQ(1, deviceState);
88 DTEST_LOG << "DmsDeviceInfoTest testGet_001 end" << std::endl;
89 }
90 } // DistributedSchedule
91 } // namespace OHOS