• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "version_info_test.h"
17 
18 #include <cerrno>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 
22 #define private public
23 #include "version_info_manager.h"
24 #include "version_manager.h"
25 #include "version_info.h"
26 #undef private
27 #include "dh_context.h"
28 #include "distributed_hardware_errno.h"
29 #include "distributed_hardware_log.h"
30 
31 using namespace testing::ext;
32 using namespace std;
33 namespace OHOS {
34 namespace DistributedHardware {
35 #undef DH_LOG_TAG
36 #define DH_LOG_TAG "VersionInfoTest"
37 
38 namespace {
39 const string DEV_ID_1 = "bb536a637105409e904d4da83790a4a7";
40 const string NAME_SCREEN = "distributed_screen";
41 const string VERSION_1 = "1.0";
42 }
43 
SetUpTestCase(void)44 void VersionInfoTest::SetUpTestCase(void)
45 {
46 }
47 
TearDownTestCase(void)48 void VersionInfoTest::TearDownTestCase(void)
49 {
50 }
51 
SetUp()52 void VersionInfoTest::SetUp()
53 {
54 }
55 
TearDown()56 void VersionInfoTest::TearDown()
57 {
58 }
59 
60 /**
61  * @tc.name:version_info_test_001
62  * @tc.desc: Verify the VersionInfoTest ToJson function.
63  * @tc.type: FUNC
64  * @tc.require: AR000GHSCV
65  */
66 HWTEST_F(VersionInfoTest, version_info_test_001, TestSize.Level0)
67 {
68     CompVersion compVersions1 = {
69         .name = NAME_SCREEN,
70         .dhType = DHType::SCREEN,
71         .handlerVersion = VERSION_1,
72         .sourceVersion = VERSION_1,
73         .sinkVersion = VERSION_1
74     };
75 
76     VersionInfo verInfo1;
77     verInfo1.deviceId = DEV_ID_1;
78     verInfo1.dhVersion = VERSION_1;
79     verInfo1.compVersions.insert(std::pair<DHType, CompVersion>(compVersions1.dhType, compVersions1));
80 
81     std::string jsonStr = verInfo1.ToJsonString();
82     EXPECT_NE(jsonStr.empty(), true);
83 
84     VersionInfo verInfo2;
85     verInfo2.FromJsonString(jsonStr);
86 
87     EXPECT_EQ(verInfo2.ToJsonString(), jsonStr);
88 }
89 } // namespace DistributedHardware
90 } // namespace OHOS
91