• 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 "store_util.h"
17 
18 #include <gtest/gtest.h>
19 #include <vector>
20 
21 #include "store_manager.h"
22 #include "types.h"
23 using namespace testing::ext;
24 using namespace OHOS::DistributedKv;
25 
26 class StoreUtilTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30 
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void StoreUtilTest::SetUpTestCase(void) {}
36 
TearDownTestCase(void)37 void StoreUtilTest::TearDownTestCase(void) {}
38 
SetUp(void)39 void StoreUtilTest::SetUp(void) {}
40 
TearDown(void)41 void StoreUtilTest::TearDown(void) {}
42 /**
43 * @tc.name: GetDBSecurity
44 * @tc.desc: get db security
45 * @tc.type: FUNC
46 * @tc.require:
47 * @tc.author: Wang Kai
48 */
49 HWTEST_F(StoreUtilTest, GetDBSecurity, TestSize.Level1)
50 {
51     StoreUtil storeUtil_;
52     auto dbsecurity = storeUtil_.GetDBSecurity(-1);
53     ASSERT_EQ(dbsecurity.securityLabel, DistributedDB::NOT_SET);
54     ASSERT_EQ(dbsecurity.securityFlag, DistributedDB::ECE);
55 
56     dbsecurity = storeUtil_.GetDBSecurity(7);
57     ASSERT_EQ(dbsecurity.securityLabel, DistributedDB::NOT_SET);
58     ASSERT_EQ(dbsecurity.securityFlag, DistributedDB::ECE);
59 
60     dbsecurity = storeUtil_.GetDBSecurity(5);
61     ASSERT_EQ(dbsecurity.securityLabel, DistributedDB::S3);
62     ASSERT_EQ(dbsecurity.securityFlag, DistributedDB::SECE);
63 
64     dbsecurity = storeUtil_.GetDBSecurity(6);
65     ASSERT_EQ(dbsecurity.securityLabel, DistributedDB::S4);
66     ASSERT_EQ(dbsecurity.securityFlag, DistributedDB::ECE);
67 }
68 /**
69 * @tc.name: GetSecLevel
70 * @tc.desc: get secLevel
71 * @tc.type: FUNC
72 * @tc.require:
73 * @tc.author: Wang Kai
74 */
75 HWTEST_F(StoreUtilTest, GetSecLevel, TestSize.Level1)
76 {
77     StoreUtil storeUtil_;
78     StoreUtil::DBSecurity dbSec = { DistributedDB::NOT_SET, DistributedDB::ECE };
79     int32_t security = storeUtil_.GetSecLevel(dbSec);
80     ASSERT_EQ(security, dbSec.securityLabel);
81 
82     dbSec = { DistributedDB::S3, DistributedDB::ECE };
83     security = storeUtil_.GetSecLevel(dbSec);
84     ASSERT_EQ(security, S3_EX);
85     dbSec = { DistributedDB::S3, DistributedDB::SECE };
86     security = storeUtil_.GetSecLevel(dbSec);
87     ASSERT_EQ(security, S3);
88 
89     dbSec = { DistributedDB::S4, DistributedDB::ECE };
90     security = storeUtil_.GetSecLevel(dbSec);
91     ASSERT_EQ(security, S4);
92 }
93 /**
94 * @tc.name: GetDBMode
95 * @tc.desc: get db mode
96 * @tc.type: FUNC
97 * @tc.require:
98 * @tc.author: Wang Kai
99 */
100 HWTEST_F(StoreUtilTest, GetDBMode, TestSize.Level1)
101 {
102     StoreUtil storeUtil_;
103     StoreUtil::DBMode dbMode = storeUtil_.GetDBMode(SyncMode::PUSH);
104     ASSERT_EQ(dbMode, StoreUtil::DBMode::SYNC_MODE_PUSH_ONLY);
105 
106     dbMode = storeUtil_.GetDBMode(SyncMode::PULL);
107     ASSERT_EQ(dbMode, StoreUtil::DBMode::SYNC_MODE_PULL_ONLY);
108 
109     dbMode = storeUtil_.GetDBMode(SyncMode::PUSH_PULL);
110     ASSERT_EQ(dbMode, StoreUtil::DBMode::SYNC_MODE_PUSH_PULL);
111 }
112 /**
113 * @tc.name: GetObserverMode
114 * @tc.desc: get observer mode
115 * @tc.type: FUNC
116 * @tc.require:
117 * @tc.author: Wang Kai
118 */
119 HWTEST_F(StoreUtilTest, GetObserverMode, TestSize.Level1)
120 {
121     StoreUtil storeUtil_;
122     uint32_t mode = storeUtil_.GetObserverMode(SubscribeType::SUBSCRIBE_TYPE_LOCAL);
123     ASSERT_EQ(mode, DistributedDB::OBSERVER_CHANGES_NATIVE);
124 
125     mode = storeUtil_.GetObserverMode(SubscribeType::SUBSCRIBE_TYPE_REMOTE);
126     ASSERT_EQ(mode, DistributedDB::OBSERVER_CHANGES_FOREIGN);
127 
128     mode = storeUtil_.GetObserverMode(SUBSCRIBE_TYPE_ALL);
129     ASSERT_EQ(mode, DistributedDB::OBSERVER_CHANGES_FOREIGN | DistributedDB::OBSERVER_CHANGES_NATIVE);
130 }