• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <memory>
17 #include "kvstore_client_death_observer.h"
18 #include "bootstrap.h"
19 #include "gtest/gtest.h"
20 #include "kvstore_data_service.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::DistributedKv;
24 using namespace OHOS::DistributedData;
25 using namespace OHOS;
26 
27 class KvStoreDataServiceTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33     static constexpr int32_t TEST_USERID = 100;
34     static constexpr int32_t TEST_APP_INDEX = 0;
35     static constexpr int32_t TEST_TOKENID = 100;
36     std::string TEST_INDENTATION = "    ";
37 };
38 
SetUpTestCase(void)39 void KvStoreDataServiceTest::SetUpTestCase(void)
40 {}
41 
TearDownTestCase(void)42 void KvStoreDataServiceTest::TearDownTestCase(void)
43 {}
44 
SetUp(void)45 void KvStoreDataServiceTest::SetUp(void)
46 {}
47 
TearDown(void)48 void KvStoreDataServiceTest::TearDown(void)
49 {}
50 
51 /**
52 * @tc.name: RegisterClientDeathObserver001
53 * @tc.desc: register client death observer
54 * @tc.type: FUNC
55 * @tc.require: AR000CQDU2
56 * @tc.author: liuyuhui
57 */
58 HWTEST_F(KvStoreDataServiceTest, RegisterClientDeathObserver001, TestSize.Level1)
59 {
60     AppId appId;
61     appId.appId = "app0";
62     KvStoreDataService kvDataService;
63     Bootstrap::GetInstance().LoadComponents();
64     Bootstrap::GetInstance().LoadCheckers();
65     KvStoreMetaManager::GetInstance().BindExecutor(std::make_shared<ExecutorPool>(12, 5));
66     KvStoreMetaManager::GetInstance().InitMetaParameter();
67     Status status = kvDataService.RegisterClientDeathObserver(appId, new KvStoreClientDeathObserver());
68     EXPECT_EQ(status, Status::SUCCESS) << "RegisterClientDeathObserver failed";
69 }
70 
71 /**
72 * @tc.name: GetIndentation001
73 * @tc.desc:
74 * @tc.type: FUNC
75 * @tc.require:
76 * @tc.author: wangbin
77 */
78 HWTEST_F(KvStoreDataServiceTest, GetIndentation001, TestSize.Level1)
79 {
80     KvStoreDataService kvStoreDataServiceTest;
81     std::string indentation = kvStoreDataServiceTest.GetIndentation(1);
82     EXPECT_EQ(indentation, TEST_INDENTATION);
83 }
84 
85 /**
86 * @tc.name: GetFeatureInterface001
87 * @tc.desc:
88 * @tc.type: FUNC
89 * @tc.require:
90 * @tc.author: wangbin
91 */
92 HWTEST_F(KvStoreDataServiceTest, GetFeatureInterface001, TestSize.Level1)
93 {
94     KvStoreDataService kvStoreDataServiceTest;
95     std::string name = "kvstoredatatest";
96     sptr<IRemoteObject> object = kvStoreDataServiceTest.GetFeatureInterface(name);
97     EXPECT_EQ(object, nullptr);
98 }
99 
100 /**
101 * @tc.name: Dump001
102 * @tc.desc:
103 * @tc.type: FUNC
104 * @tc.require:
105 * @tc.author: wangbin
106 */
107 HWTEST_F(KvStoreDataServiceTest, Dump001, TestSize.Level1)
108 {
109     KvStoreDataService kvStoreDataServiceTest;
110     std::vector<std::u16string> args;
111     const std::u16string argstest1 = u"OHOS.DistributedKv.IKvStoreDataService1";
112     const std::u16string argstest2 = u"OHOS.DistributedKv.IKvStoreDataService2";
113     args.emplace_back(argstest1);
114     args.emplace_back(argstest2);
115     int32_t status = kvStoreDataServiceTest.Dump(1, args);
116     EXPECT_EQ(status, SUCCESS);
117 }
118 
119 /**
120 * @tc.name: OnUninstall001
121 * @tc.desc:
122 * @tc.type: FUNC
123 * @tc.require:
124 * @tc.author: wangbin
125 */
126 HWTEST_F(KvStoreDataServiceTest, OnUninstall001, TestSize.Level1)
127 {
128     KvStoreDataService kvStoreDataServiceTest;
129     std::string bundleNametest = "ohos.kvstoredatatest.demo";
130     int32_t status = kvStoreDataServiceTest.OnUninstall(bundleNametest, TEST_USERID, TEST_APP_INDEX);
131     EXPECT_EQ(status, SUCCESS);
132 }
133 
134 /**
135 * @tc.name: OnUpdate001
136 * @tc.desc:
137 * @tc.type: FUNC
138 * @tc.require:
139 * @tc.author: wangbin
140 */
141 HWTEST_F(KvStoreDataServiceTest, OnUpdate001, TestSize.Level1)
142 {
143     KvStoreDataService kvStoreDataServiceTest;
144     std::string bundleNametest = "ohos.kvstoredatatest.demo";
145     int32_t status = kvStoreDataServiceTest.OnUpdate(bundleNametest, TEST_USERID, TEST_APP_INDEX);
146     EXPECT_EQ(status, SUCCESS);
147 }
148 
149 /**
150 * @tc.name: OnInstall001
151 * @tc.desc:
152 * @tc.type: FUNC
153 * @tc.require:
154 * @tc.author: wangbin
155 */
156 HWTEST_F(KvStoreDataServiceTest, OnInstall001, TestSize.Level1)
157 {
158     KvStoreDataService kvStoreDataServiceTest;
159     std::string bundleNametest = "ohos.kvstoredatatest.demo";
160     int32_t status = kvStoreDataServiceTest.OnInstall(bundleNametest, TEST_USERID, TEST_APP_INDEX);
161     EXPECT_EQ(status, SUCCESS);
162 }
163 
164 /**
165 * @tc.name: AppExit001
166 * @tc.desc:
167 * @tc.type: FUNC
168 * @tc.require:
169 * @tc.author: wangbin
170 */
171 HWTEST_F(KvStoreDataServiceTest, AppExit001, TestSize.Level1)
172 {
173     KvStoreDataService kvStoreDataServiceTest;
174     pid_t uid = 1;
175     pid_t pid = 2;
176     uint32_t token = 3;
177     OHOS::DistributedKv::AppId appId = { "ohos.test.kvstoredataservice" };
178     Status status = kvStoreDataServiceTest.AppExit(uid, pid, token, appId);
179     EXPECT_EQ(status, SUCCESS);
180 }