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 <cstdio>
17 #include <cstring>
18 #include <fcntl.h>
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 #include <iostream>
22 #include <memory>
23 #include <sys/mman.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include "cJSON.h"
27 #include "if_system_ability_manager.h"
28 #include "ipc_types.h"
29 #include "iservice_registry.h"
30 #include "iupdate_callback.h"
31 #include "iupdate_service.h"
32 #include "parameters.h"
33 #include "unittest_comm.h"
34 #include "update_callback.h"
35 #include "update_callback_proxy.h"
36 #include "update_helper.h"
37 #include "update_service.h"
38 #include "update_service_kits_impl.h"
39 #include "update_service_proxy.h"
40
41 using namespace std;
42 using namespace testing::ext;
43 using namespace OHOS;
44 using namespace OHOS::update_engine;
45 static const int32_t DLNOW_10 = 10;
46 static const int32_t DLNOW_20 = 20;
47 static const int32_t DLNOW_50 = 50;
48 static const int32_t DLNOW_70 = 70;
49 static const int32_t DLNOW_80 = 80;
50 static const int32_t DLTOTAL_NUM = 100;
51 static const int32_t UPGRADE_INTERVAL_2 = 2222;
52 static const int32_t UPGRADE_INTERVAL_3 = 3333;
53 static const int32_t JSON_MAX_SIZE = 4096;
54 #define UNUSED(x) (void)(x)
GetUpdateService()55 static UpdateService *GetUpdateService()
56 {
57 static UpdateService *updateServer = nullptr;
58 if (updateServer == nullptr) {
59 updateServer = new UpdateService(0, true);
60 }
61 return updateServer;
62 }
63
64 class UpdateServerTest : public ::testing::Test {
65 public:
UpdateServerTest()66 UpdateServerTest()
67 {
68 updateServer_ = GetUpdateService();
69 updateCallBack_ = new UpdateCallback();
70 }
~UpdateServerTest()71 virtual ~UpdateServerTest()
72 {
73 delete updateCallBack_;
74 }
75
SetUp()76 void SetUp() {}
TearDown()77 void TearDown() {}
TestBody()78 void TestBody() {}
79
TestRegisterCallback()80 int TestRegisterCallback()
81 {
82 return 0;
83 }
84
TestCheckNewVersion()85 int TestCheckNewVersion()
86 {
87 ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
88 MessageParcel inData;
89 MessageParcel reply;
90 MessageOption msgOption;
91 updateServer_->OnRemoteRequest(IUpdateService::CHECK_VERSION, inData, reply, msgOption);
92 return 0;
93 }
94
TestDownload()95 int TestDownload()
96 {
97 ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
98 MessageParcel inData;
99 MessageParcel reply;
100 MessageOption msgOption;
101 updateServer_->OnRemoteRequest(IUpdateService::DOWNLOAD, inData, reply, msgOption);
102 EXPECT_EQ(0, reply.ReadInt32());
103 sleep(1);
104 updateServer_->OnRemoteRequest(IUpdateService::CANCEL, inData, reply, msgOption);
105 return 0;
106 }
107
TestDoUpdate()108 int TestDoUpdate()
109 {
110 ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
111 MessageParcel inData;
112 MessageParcel reply;
113 MessageOption msgOption;
114 updateServer_->OnRemoteRequest(IUpdateService::UPGRADE, inData, reply, msgOption);
115 EXPECT_EQ(-1, reply.ReadInt32());
116 sptr<IUpdateCallback> callback_ {};
117 UpdateContext ctx {};
118 ctx.upgradeFile = "/data/updater/updater/updater.zip";
119 UpdateService *updateServer = new UpdateService(0, true);
120 int ret = updateServer->RegisterUpdateCallback(ctx, callback_);
121 EXPECT_NE(updateServer, nullptr);
122 updateServer->DoUpdate();
123 ret = updateServer->UnregisterUpdateCallback();
124 EXPECT_EQ(0, ret);
125 delete updateServer;
126 return 0;
127 }
128
TestGetUpdatePolicy(UpdatePolicy & policy)129 int TestGetUpdatePolicy(UpdatePolicy &policy)
130 {
131 MessageParcel inData;
132 MessageParcel reply;
133 MessageOption msgOption;
134 updateServer_->OnRemoteRequest(IUpdateService::GET_POLICY, inData, reply, msgOption);
135 UpdateHelper::ReadUpdatePolicy(reply, policy);
136 return 0;
137 }
138
TestUpdatePolicy()139 int TestUpdatePolicy()
140 {
141 ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
142 UpdatePolicy policy;
143 policy.autoDownload = true;
144 policy.autoDownloadNet = true;
145 policy.mode = INSTALLMODE_AUTO;
146 policy.autoUpgradeInterval[0] = UPGRADE_INTERVAL_2;
147 policy.autoUpgradeInterval[1] = UPGRADE_INTERVAL_3;
148 MessageParcel inData;
149 UpdateHelper::WriteUpdatePolicy(inData, policy);
150 MessageParcel reply;
151 MessageOption msgOption;
152 updateServer_->OnRemoteRequest(IUpdateService::SET_POLICY, inData, reply, msgOption);
153 UpdatePolicy policy2;
154 TestGetUpdatePolicy(policy2);
155 EXPECT_EQ(policy.autoUpgradeInterval[0], policy2.autoUpgradeInterval[0]);
156 return 0;
157 }
158
TestGetNewVersion()159 int TestGetNewVersion()
160 {
161 VersionInfo versionInfo;
162 MessageParcel inData;
163 MessageParcel reply;
164 MessageOption msgOption;
165 updateServer_->OnRemoteRequest(IUpdateService::GET_NEW_VERSION, inData, reply, msgOption);
166 UpdateHelper::ReadVersionInfo(reply, versionInfo);
167 EXPECT_EQ(versionInfo.status, HAS_NEW_VERSION);
168 return 0;
169 }
170
TestGetUpgradeStatus()171 int TestGetUpgradeStatus()
172 {
173 UpgradeInfo info;
174 MessageParcel inData;
175 MessageParcel reply;
176 MessageOption msgOption;
177 updateServer_->OnRemoteRequest(IUpdateService::GET_STATUS, inData, reply, msgOption);
178 UpdateHelper::ReadUpgradeInfo(reply, info);
179 return 0;
180 }
181
TestRebootAndClean()182 int TestRebootAndClean()
183 {
184 VersionInfo versionInfo;
185 MessageParcel inData;
186 MessageParcel reply;
187 MessageOption msgOption;
188 updateServer_->OnRemoteRequest(IUpdateService::REBOOT_CLEAN, inData, reply, msgOption);
189 EXPECT_EQ(reply.ReadInt32(), 0);
190 return 0;
191 }
192
TestRebootAndInstall()193 int TestRebootAndInstall()
194 {
195 VersionInfo versionInfo;
196 MessageParcel inData;
197 MessageParcel reply;
198 MessageOption msgOption;
199 updateServer_->OnRemoteRequest(IUpdateService::REBOOT_INSTALL, inData, reply, msgOption);
200 EXPECT_EQ(reply.ReadInt32(), 0);
201 return 0;
202 }
203
TestRegisterUpdateCallback()204 int TestRegisterUpdateCallback()
205 {
206 VersionInfo versionInfo;
207 MessageParcel inData;
208 MessageParcel reply;
209 MessageOption msgOption;
210 updateServer_->OnRemoteRequest(IUpdateService::REGISTER_CALLBACK, inData, reply, msgOption);
211 EXPECT_EQ(reply.ReadInt32(), -1);
212 return 0;
213 }
214
TestUnRegisterUpdateCallback()215 int TestUnRegisterUpdateCallback()
216 {
217 VersionInfo versionInfo;
218 MessageParcel inData;
219 MessageParcel reply;
220 MessageOption msgOption;
221 updateServer_->OnRemoteRequest(IUpdateService::UNREGISTER_CALLBACK, inData, reply, msgOption);
222 EXPECT_EQ(reply.ReadInt32(), 0);
223 return 0;
224 }
225
TestReadCheckVersiondescriptInfo()226 int TestReadCheckVersiondescriptInfo()
227 {
228 cJSON *temp = cJSON_CreateObject();
229 EXPECT_NE(temp, nullptr);
230 cJSON_AddStringToObject(temp, "descriptPackageId", "descriptPackageId1");
231 cJSON_AddStringToObject(temp, "content", "content1");
232 cJSON_AddNumberToObject(temp, "id", 1);
233 cJSON* array = cJSON_CreateArray();
234 EXPECT_NE(array, nullptr);
235 cJSON_AddItemToArray(array, temp);
236
237 VersionInfo info {};
238 updateServer_->ReadCheckVersiondescriptInfo(array, info);
239 EXPECT_STREQ(info.descriptInfo[0].descriptPackageId.c_str(), "descriptPackageId1");
240 EXPECT_STREQ(info.descriptInfo[0].content.c_str(), "content1");
241 return 0;
242 }
243
TestUpdateServiceProxy()244 int TestUpdateServiceProxy()
245 {
246 sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
247 EXPECT_NE(systemMgr, nullptr);
248 sptr<IRemoteObject> remoteObj = systemMgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID);
249 EXPECT_NE(remoteObj, nullptr);
250 UpdateServiceProxy *proxy = new UpdateServiceProxy(remoteObj);
251 UpdateCallbackProxy *updateCallBack = new UpdateCallbackProxy(remoteObj);
252 std::string miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
253 std::string packageName = "/data/updater/updater/updater.zip";
254 const std::string cmd = "--update_package=/data/updater/updater.zip";
255 VersionInfo info {};
256 Progress progress {};
257 UpdateContext ctx {};
258 updateCallBack->OnCheckVersionDone(info);
259 updateCallBack->OnDownloadProgress(progress);
260 updateCallBack->OnUpgradeProgress(progress);
261 proxy->RegisterUpdateCallback(ctx, updateCallBack);
262 proxy->UnregisterUpdateCallback();
263 proxy->DoUpdate();
264 proxy->RebootAndClean(miscFile, cmd);
265 proxy->RebootAndInstall(miscFile, packageName);
266 EXPECT_EQ(info.status, HAS_NEW_VERSION);
267 EXPECT_EQ(progress.status, UPDATE_STATE_INIT);
268 delete proxy;
269 return 0;
270 }
271
TestUpdateCallbackCheckNewVersion()272 int TestUpdateCallbackCheckNewVersion()
273 {
274 MessageParcel inData;
275 MessageParcel reply;
276 MessageOption msgOption;
277 updateCallBack_->OnRemoteRequest(IUpdateService::CHECK_VERSION, inData, reply, msgOption);
278 EXPECT_EQ(reply.ReadInt32(), 0);
279 return 0;
280 }
281
TestUpdateCallbackDownload()282 int TestUpdateCallbackDownload()
283 {
284 MessageParcel inData;
285 MessageParcel reply;
286 MessageOption msgOption;
287 updateCallBack_->OnRemoteRequest(IUpdateService::DOWNLOAD, inData, reply, msgOption);
288 EXPECT_EQ(reply.ReadInt32(), 0);
289 return 0;
290 }
291
TestUpdateCallbackUpgrade()292 int TestUpdateCallbackUpgrade()
293 {
294 MessageParcel inData;
295 MessageParcel reply;
296 MessageOption msgOption;
297 updateCallBack_->OnRemoteRequest(IUpdateService::UPGRADE, inData, reply, msgOption);
298 EXPECT_EQ(reply.ReadInt32(), 0);
299 return 0;
300 }
GetServerIp(std::string & ip)301 void GetServerIp(std::string &ip)
302 {
303 ip = OHOS::system::GetParameter("update.serverip", "127.0.0.1");
304 }
305
TestDownLoadProgress()306 int TestDownLoadProgress()
307 {
308 DownloadThread *download = new DownloadThread(
309 [&](const std::string &filaName, const Progress &progress) -> int {
310 return 0;
311 });
312 EXPECT_EQ(download == 0, 0);
313 std::string serverAddr;
314 GetServerIp(serverAddr);
315 std::string url = "http://";
316 url += serverAddr;
317 url += "/updater.zip";
318 download->StartDownload("updater.zip", url);
319 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_10, 0, 0);
320 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_20, 0, 0);
321 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_50, 0, 0);
322 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_70, 0, 0);
323 download->StopDownload();
324 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_80, 0, 0);
325 DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLTOTAL_NUM, 0, 0);
326
327 // get file
328 std::string jsonFileName = TEST_PATH_FROM;
329 jsonFileName += "packageInfos.json";
330 size_t length = DownloadThread::GetLocalFileLength(jsonFileName);
331 // write file
332 FILE *downloadFile = fopen("packageInfos.json", "ab+");
333 if (downloadFile != nullptr) {
334 VersionInfo versionInfo {};
335 std::vector<char> buffer(JSON_MAX_SIZE);
336 fread(buffer.data(), 1, JSON_MAX_SIZE, downloadFile);
337 UpdateService::ParseJsonFile(buffer, versionInfo);
338 DownloadThread::WriteFunc((void *)buffer.data(), length, 1, downloadFile);
339 }
340 delete download;
341 return 0;
342 }
343
TestNewUpdateService()344 int TestNewUpdateService()
345 {
346 UpdateService *updateServer = new UpdateService(0, true);
347 updateServer->OnStart();
348 updateServer->OnStop();
349 delete updateServer;
350 return 0;
351 }
352
353 private:
354 UpdateService *updateServer_ = nullptr;
355 UpdateCallback *updateCallBack_ = nullptr;
356 };
357
358 class MockUpdateServiceKits : public UpdateServiceKits {
359 public:
360 MockUpdateServiceKits() = default;
361 virtual ~MockUpdateServiceKits() = default;
362
RegisterUpdateCallback(const UpdateContext & ctx,const UpdateCallbackInfo & cb)363 virtual int32_t RegisterUpdateCallback(const UpdateContext &ctx, const UpdateCallbackInfo &cb) override
364 {
365 UNUSED(ctx);
366 UNUSED(cb);
367 return 0;
368 }
369
UnregisterUpdateCallback()370 virtual int32_t UnregisterUpdateCallback() override
371 {
372 return 0;
373 }
374
CheckNewVersion()375 virtual int32_t CheckNewVersion() override
376 {
377 return 0;
378 }
379
DownloadVersion()380 virtual int32_t DownloadVersion() override
381 {
382 return 0;
383 }
384
DoUpdate()385 virtual int32_t DoUpdate() override
386 {
387 return 0;
388 }
389
GetNewVersion(VersionInfo & versionInfo)390 virtual int32_t GetNewVersion(VersionInfo &versionInfo) override
391 {
392 UNUSED(versionInfo);
393 return 0;
394 }
395
GetUpgradeStatus(UpgradeInfo & info)396 virtual int32_t GetUpgradeStatus(UpgradeInfo &info) override
397 {
398 UNUSED(info);
399 return 0;
400 }
401
SetUpdatePolicy(const UpdatePolicy & policy)402 virtual int32_t SetUpdatePolicy(const UpdatePolicy &policy) override
403 {
404 UNUSED(policy);
405 return 0;
406 }
407
GetUpdatePolicy(UpdatePolicy & policy)408 virtual int32_t GetUpdatePolicy(UpdatePolicy &policy) override
409 {
410 UNUSED(policy);
411 return 0;
412 }
413
Cancel(int32_t service)414 virtual int32_t Cancel(int32_t service) override
415 {
416 return service;
417 }
418
RebootAndClean(const std::string & miscFile,const std::string & cmd)419 virtual int32_t RebootAndClean(const std::string &miscFile, const std::string &cmd)
420 {
421 UNUSED(miscFile);
422 UNUSED(cmd);
423 return 0;
424 }
425
RebootAndInstall(const std::string & miscFile,const std::string & packageName)426 virtual int32_t RebootAndInstall(const std::string &miscFile, const std::string &packageName)
427 {
428 UNUSED(miscFile);
429 UNUSED(packageName);
430 return 0;
431 }
432 };
433
434 HWTEST_F(UpdateServerTest, TestDownload, TestSize.Level1)
435 {
436 UpdateServerTest test;
437 test.TestCheckNewVersion();
438 test.TestDownload();
439 }
440
441 HWTEST_F(UpdateServerTest, TestDoUpdate, TestSize.Level1)
442 {
443 UpdateServerTest test;
444 test.TestDoUpdate();
445 }
446
447 HWTEST_F(UpdateServerTest, TestGetNewVersion, TestSize.Level1)
448 {
449 UpdateServerTest test;
450 test.TestCheckNewVersion();
451 test.TestGetNewVersion();
452 }
453
454 HWTEST_F(UpdateServerTest, TestUpdatePolicy, TestSize.Level1)
455 {
456 UpdateServerTest test;
457 test.TestUpdatePolicy();
458 }
459
460 HWTEST_F(UpdateServerTest, TestGetUpgradeStatus, TestSize.Level1)
461 {
462 UpdateServerTest test;
463 test.TestGetUpgradeStatus();
464 }
465
466 HWTEST_F(UpdateServerTest, TestRebootAndClean, TestSize.Level1)
467 {
468 UpdateServerTest test;
469 test.TestRebootAndClean();
470 }
471
472 HWTEST_F(UpdateServerTest, TestRebootAndInstall, TestSize.Level1)
473 {
474 UpdateServerTest test;
475 test.TestRebootAndInstall();
476 }
477
478 HWTEST_F(UpdateServerTest, TestRegisterUpdateCallback, TestSize.Level1)
479 {
480 UpdateServerTest test;
481 test.TestRegisterUpdateCallback();
482 }
483
484 HWTEST_F(UpdateServerTest, TestUnRegisterUpdateCallback, TestSize.Level1)
485 {
486 UpdateServerTest test;
487 test.TestUnRegisterUpdateCallback();
488 }
489
490 HWTEST_F(UpdateServerTest, TestReadCheckVersiondescriptInfo, TestSize.Level1)
491 {
492 UpdateServerTest test;
493 test.TestReadCheckVersiondescriptInfo();
494 }
495
496 HWTEST_F(UpdateServerTest, TestUpdateCallbackCheckNewVersion, TestSize.Level1)
497 {
498 UpdateServerTest test;
499 test.TestUpdateCallbackCheckNewVersion();
500 }
501
502 HWTEST_F(UpdateServerTest, TestUpdateCallbackDownload, TestSize.Level1)
503 {
504 UpdateServerTest test;
505 test.TestUpdateCallbackDownload();
506 }
507
508 HWTEST_F(UpdateServerTest, TestUpdateCallbackUpgrade, TestSize.Level1)
509 {
510 UpdateServerTest test;
511 test.TestUpdateCallbackUpgrade();
512 }
513
514 HWTEST_F(UpdateServerTest, TestDownLoadProgress, TestSize.Level1)
515 {
516 UpdateServerTest test;
517 test.TestDownLoadProgress();
518 }
519
520 HWTEST_F(UpdateServerTest, TestNewUpdateService, TestSize.Level1)
521 {
522 UpdateServerTest test;
523 test.TestNewUpdateService();
524 }
525
526 HWTEST_F(UpdateServerTest, TestUpdateServiceProxy, TestSize.Level1)
527 {
528 UpdateServerTest test;
529 test.TestUpdateServiceProxy();
530 }
531
532 HWTEST_F(UpdateServerTest, TestKitsResetService, TestSize.Level1)
533 {
534 sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
535 EXPECT_NE(systemMgr, nullptr);
536 sptr<IRemoteObject> remoteObj = systemMgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID);
537 EXPECT_NE(remoteObj, nullptr);
538 sptr<IRemoteObject::DeathRecipient> deathRecipient = new UpdateServiceKitsImpl::DeathRecipient();
539 deathRecipient->OnRemoteDied(remoteObj);
540 EXPECT_NE(deathRecipient, nullptr);
541 UpdateService *saServer = new UpdateService(0, true);
542 EXPECT_NE(saServer, nullptr);
543 const std::string miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
544 const std::string packageName = "--update_package=/data/updater/updater.zip";
545 int32_t ret = saServer->RebootAndInstall(miscFile, packageName);
546 EXPECT_EQ(ret, 0);
547 delete saServer;
548 }
549
550 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnCheckVersionDone, TestSize.Level1)
551 {
552 VersionInfo info {};
553 UpdateCallbackInfo callBackFun {};
554 sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
555 new UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
556 remoteCallBack->OnCheckVersionDone(info);
557 EXPECT_NE(remoteCallBack, nullptr);
558 }
559
560 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnDownloadProgress, TestSize.Level1)
561 {
562 Progress progress {};
563 UpdateCallbackInfo callBackFun {};
564 sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
565 new UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
566 remoteCallBack->OnDownloadProgress(progress);
567 EXPECT_NE(remoteCallBack, nullptr);
568 }
569
570 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnUpgradeProgress, TestSize.Level1)
571 {
572 Progress progress {};
573 UpdateCallbackInfo callBackFun {};
574 sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
575 new UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
576 remoteCallBack->OnUpgradeProgress(progress);
577 EXPECT_NE(remoteCallBack, nullptr);
578 }
579
580 HWTEST_F(UpdateServerTest, TestKitsRegisterUpdateCallback, TestSize.Level1)
581 {
582 UpdateCallbackInfo callBackFun {};
583 UpdateContext ctx {};
584 int ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(ctx, callBackFun);
585 EXPECT_EQ(ret, 0);
586 ret = UpdateServiceKits::GetInstance().UnregisterUpdateCallback();
587 EXPECT_EQ(ret, 0);
588 }
589
590 HWTEST_F(UpdateServerTest, TestKitsDoUpdate, TestSize.Level1)
591 {
592 int ret = UpdateServiceKits::GetInstance().DoUpdate();
593 EXPECT_EQ(ret, 0);
594 }
595
596 HWTEST_F(UpdateServerTest, TestKitsCancel, TestSize.Level1)
597 {
598 int32_t service = 0;
599 int ret = UpdateServiceKits::GetInstance().Cancel(service);
600 EXPECT_EQ(ret, 0);
601 }
602
603 HWTEST_F(UpdateServerTest, TestKitsRebootAndClean, TestSize.Level1)
604 {
605 const std::string miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
606 const std::string cmd = "--update_package=/data/updater/updater.zip";
607 int ret = UpdateServiceKits::GetInstance().RebootAndClean(miscFile, cmd);
608 EXPECT_NE(ret, 0);
609 }
610
611 HWTEST_F(UpdateServerTest, TestKitsReadDataFromSSL, TestSize.Level1)
612 {
613 int32_t engineSocket = 10;
614 UpdateService *updateServer = new UpdateService(0, true);
615 EXPECT_NE(updateServer, nullptr);
616 updateServer->ReadDataFromSSL(engineSocket);
617 delete updateServer;
618 }
619
620 HWTEST_F(UpdateServerTest, TestKits, TestSize.Level1)
621 {
622 UpdateServiceKits *kit = new MockUpdateServiceKits();
623 EXPECT_NE(kit, nullptr);
624 delete kit;
625 }
626
627 HWTEST_F(UpdateServerTest, TestUpdateServiceKitsImpl, TestSize.Level1)
628 {
629 std::string miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
630 std::string packageName = "/data/updater/updater/updater.zip";
631 int ret = UpdateServiceKits::GetInstance().RebootAndInstall(miscFile, packageName);
632 printf("RebootAndInstall: %d\n", ret);
633 }
634
635 HWTEST_F(UpdateServerTest, TestUpdateServiceRegisterUpdateCallback, TestSize.Level1)
636 {
637 UpdateContext ctx {};
638 UpdateService *updateServer = new UpdateService(0, true);
639 updateServer->RegisterUpdateCallback(ctx, nullptr);
640 delete updateServer;
641 }
642
643 HWTEST_F(UpdateServerTest, TestVerifyDownloadPkg, TestSize.Level1)
644 {
645 Progress downloadProgress {};
646 std::string path = "/data/updater/updater/test.txt";
647 UpdateService *updateServer = new UpdateService(0, true);
648 EXPECT_NE(updateServer, nullptr);
649 updateServer->VerifyDownloadPkg(path, downloadProgress);
650 delete updateServer;
651 }
652