• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #define private   public
17 #define protected public
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include "gtest/gtest.h"
22 #include "distributed_device_profile_constants.h"
23 #include "distributed_device_profile_errors.h"
24 #include "distributed_device_profile_enums.h"
25 #include "dp_sync_options.h"
26 #undef private
27 #undef protected
28 
29 namespace OHOS {
30 namespace DistributedDeviceProfile {
31 using namespace testing::ext;
32 using namespace std;
33 
34 namespace {
35     shared_ptr<DistributedDeviceProfile::DpSyncOptions> syncPtr =
36         make_shared<DistributedDeviceProfile::DpSyncOptions>();
37 }
38 
39 class SyncOptionsTest : public testing::Test {
40 public:
41     static void SetUpTestCase(void);
42     static void TearDownTestCase(void);
43     void SetUp();
44     void TearDown();
45 };
46 
SetUpTestCase(void)47 void SyncOptionsTest::SetUpTestCase(void) {
48 }
49 
TearDownTestCase(void)50 void SyncOptionsTest::TearDownTestCase(void) {
51 }
52 
SetUp()53 void SyncOptionsTest::SetUp() {
54 }
55 
TearDown()56 void SyncOptionsTest::TearDown() {
57 }
58 
59 /**
60  * @tc.name: AddGetDevice001
61  * @tc.desc: AddDevice and GetDeviceList succeed.
62  * @tc.type: FUNC
63  * @tc.require:
64  */
65 HWTEST_F(SyncOptionsTest, AddGetDevice001, TestSize.Level1)
66 {
67     syncPtr->AddDevice("device1");
68     syncPtr->AddDevice("device2");
69     syncPtr->AddDevice("device3");
70     EXPECT_EQ(3, syncPtr->GetDeviceList().size());
71 }
72 
73 /**
74  * @tc.name: SetGetSyncMode001
75  * @tc.desc: SetSyncMode and GetSyncMode succeed.
76  * @tc.type: FUNC
77  * @tc.require:
78  */
79 HWTEST_F(SyncOptionsTest, SetGetSyncMode001, TestSize.Level1)
80 {
81     syncPtr->SetSyncMode(SyncMode::PUSH);
82     SyncMode mode = syncPtr->GetSyncMode();
83     EXPECT_EQ(SyncMode::PUSH, mode);
84 }
85 
86 /**
87  * @tc.name: Marshalling001
88  * @tc.desc: Marshalling and UnMarshalling succeed.
89  * @tc.type: FUNC
90  * @tc.require:
91  */
92 HWTEST_F(SyncOptionsTest, Marshalling001, TestSize.Level1)
93 {
94     syncPtr->AddDevice("device3");
95     syncPtr->AddDevice("device4");
96     syncPtr->AddDevice("device5");
97     syncPtr->SetSyncMode(SyncMode::PUSH);
98     OHOS::MessageParcel data;
99 
100     bool res1 = syncPtr->Marshalling(data);
101     EXPECT_EQ(true, res1);
102 
103     bool res2 = syncPtr->UnMarshalling(data);
104     EXPECT_EQ(true, res2);
105 }
106 
107 /**
108  * @tc.name: Dump001
109  * @tc.desc: Dump succeed.
110  * @tc.type: FUNC
111  * @tc.require:
112  */
113 HWTEST_F(SyncOptionsTest, Dump001, TestSize.Level1)
114 {
115     syncPtr->AddDevice("device6");
116     syncPtr->AddDevice("device7");
117     syncPtr->AddDevice("device8");
118     syncPtr->SetSyncMode(SyncMode::PUSH);
119 
120     string strJson = syncPtr->dump();
121     char fistChar = strJson.front();
122     char lastChar = strJson.back();
123     EXPECT_EQ('{', fistChar);
124     EXPECT_EQ('}', lastChar);
125 }
126 } // namespace DistributedDeviceProfile
127 } // namespace OHOS
128