• 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 <cstdio>
17 #include <cstring>
18 #include <fcntl.h>
19 #include <iostream>
20 #include <sys/mman.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 #include "client_stub.h"
24 #include "gmock/gmock.h"
25 #include "gtest/gtest.h"
26 #include "iupdate_service.h"
27 #include "log.h"
28 #include "napi/native_api.h"
29 #include "napi/native_node_api.h"
30 #include "node_api.h"
31 #include "node_api_types.h"
32 #include "unittest_comm.h"
33 #include "update_helper.h"
34 #include "update_service.h"
35 #include "update_session.h"
36 
37 using namespace std;
38 using namespace updateClient;
39 using namespace testing::ext;
40 using namespace OHOS::update_engine;
41 static constexpr int PERCENT_20 = 20;
42 static constexpr int PERCENT_40 = 40;
43 static constexpr int PERCENT_60 = 60;
44 static constexpr int PERCENT_100 = 100;
45 static constexpr int NUMBER_2 = 2;
46 
47 extern TestNApiEnv g_testEnv;
48 extern uint32_t g_testSessionId;
49 extern UpdateClient* g_testClient;
50 
51 namespace {
CHECK_RESULT_EQ(int ret,int value)52 void  CHECK_RESULT_EQ(int ret, int value)
53 {
54     EXPECT_EQ((reinterpret_cast<TestNApiValue*>(ret))->intValue, (value));
55     return;
56 }
57 const int32_t JSON_MAX_SIZE = 4096;
58 
59 class UpdateClientTest : public ::testing::Test {
60 public:
UpdateClientTest()61     UpdateClientTest() {}
~UpdateClientTest()62     virtual ~UpdateClientTest() {}
63 
SetUp()64     void SetUp() {}
TearDown()65     void TearDown() {}
TestBody()66     void TestBody() {}
67 
GetJsonInfo(VersionInfo & info) const68     int GetJsonInfo(VersionInfo &info) const
69     {
70         std::string jsonFileName = TEST_PATH_FROM;
71         jsonFileName += "packageInfos.json";
72 
73         std::vector<char> buffer(JSON_MAX_SIZE);
74         FILE *fp = fopen(jsonFileName.c_str(), "r");
75         CLIENT_CHECK(fp != nullptr, return -1, "parse json error %s", jsonFileName.c_str());
76         size_t bytes = fread(buffer.data(), 1, JSON_MAX_SIZE, fp);
77         if (bytes > 0) {
78             int32_t ret = UpdateService::ParseJsonFile(buffer, info);
79             CLIENT_CHECK(ret == 0,
80             (void)fclose(fp);
81             return 0, "parse json error");
82         }
83         (void)fclose(fp);
84         return 0;
85     }
86 
TestGetUpdate(bool noneClient)87     int TestGetUpdate(bool noneClient)
88     {
89         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_UPDATER);
90         g_testEnv.engineType = 0;
91         g_testEnv.noneClient = noneClient;
92         g_testEnv.eventType = "/data/ota_package/updater.zip";
93         napi_value value = GetUpdater((napi_env)&g_testEnv, nullptr);
94         CLIENT_CHECK(value == nullptr, return -1, "TestGetUpdate");
95         return 0;
96     }
97 
TestGetUpdaterForOther(bool noneClient)98     int TestGetUpdaterForOther(bool noneClient)
99     {
100         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_UPDATER);
101         g_testEnv.engineType = 1;
102         g_testEnv.noneClient = noneClient;
103         g_testEnv.eventType = "OTA";
104         napi_value value = GetUpdaterForOther((napi_env)&g_testEnv, nullptr);
105         CLIENT_CHECK(value == nullptr, return -1, "TestGetUpdate");
106         return 0;
107     }
108 
TestGetUpdaterFromOther(bool noneClient)109     int TestGetUpdaterFromOther(bool noneClient)
110     {
111         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_UPDATER);
112         g_testEnv.engineType = NUMBER_2;
113         g_testEnv.noneClient = noneClient;
114         g_testEnv.eventType = "OTA";
115         napi_value value = GetUpdaterFromOther((napi_env)&g_testEnv, nullptr);
116         CLIENT_CHECK(value == nullptr, return -1, "TestGetUpdate");
117         return 0;
118     }
119 
TestCheckNewVersion(bool isPormise)120     int TestCheckNewVersion(bool isPormise)
121     {
122         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_CHECK_VERSION);
123         g_testEnv.testAsyncorPermose = isPormise;
124         napi_value value = CheckNewVersion((napi_env)&g_testEnv, nullptr);
125         EXPECT_NE(value, nullptr);
126 
127         // Trigger thread execution
128         UpdateSession *sess = TestGetUpdateSession();
129         CLIENT_CHECK(sess != nullptr, return -1, "TestCheckNewVersion");
130         UpdateResult result = {};
131         sess->NotifyJS((napi_env)&g_testEnv, nullptr, 0, result);
132         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
133 
134         // Call back the search result and save the result information
135         VersionInfo info;
136         int ret = GetJsonInfo(info);
137         EXPECT_EQ(ret, 0);
138         g_testClient->NotifyCheckVersionDone(info);
139 
140         // end of execution
141         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
142 
143         // Check the data
144         CLIENT_LOGI("g_testEnv.pakcageInfo.versionCode %s \n", g_testEnv.pakcageInfo.result[0].versionCode.c_str());
145         CLIENT_LOGI("info.result[0].versionCode %s \n", info.result[0].versionCode.c_str());
146 
147         FreeAllNapiValues();
148         return 0;
149     }
150 
TestDownloadVersion(bool isPormise)151     int TestDownloadVersion(bool isPormise)
152     {
153         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_DOWNLOAD);
154         g_testEnv.testAsyncorPermose = isPormise;
155         napi_value value = DownloadVersion((napi_env)&g_testEnv, nullptr);
156         EXPECT_NE(value, nullptr);
157 
158         // Trigger thread execution
159         UpdateSession *sess = TestGetUpdateSession();
160         CLIENT_CHECK(sess != nullptr, return -1, "TestDownloadVersion");
161         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
162 
163         // Call back the download result and save the result information
164         Progress info;
165         info.percent = PERCENT_20;
166         info.status = UPDATE_STATE_DOWNLOAD_ON;
167         g_testClient->NotifyDownloadProgress(info);
168 
169         info.percent = PERCENT_40;
170         info.status = UPDATE_STATE_DOWNLOAD_ON;
171         g_testClient->NotifyDownloadProgress(info);
172 
173         info.percent = PERCENT_60;
174         info.status = UPDATE_STATE_DOWNLOAD_ON;
175         g_testClient->NotifyDownloadProgress(info);
176 
177         info.percent = PERCENT_100;
178         info.status = UPDATE_STATE_DOWNLOAD_SUCCESS;
179         g_testClient->NotifyDownloadProgress(info);
180 
181         // end of execution
182         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
183 
184         FreeAllNapiValues();
185         return 0;
186     }
187 
TestUpgradeVersion(bool isPormise)188     int TestUpgradeVersion(bool isPormise)
189     {
190         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_UPGRADE);
191         g_testEnv.testAsyncorPermose = isPormise;
192         napi_value value = UpgradeVersion((napi_env)&g_testEnv, nullptr);
193         CLIENT_CHECK(value != nullptr, return -1, "UpgradeVersion");
194 
195         // Trigger thread execution
196         UpdateSession *sess = TestGetUpdateSession();
197         CLIENT_CHECK(sess != nullptr, return -1, "UpgradeVersion");
198         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
199 
200         // Call back the download result and save the result information
201         Progress info;
202         info.percent = PERCENT_20;
203         info.status = UPDATE_STATE_DOWNLOAD_ON;
204         g_testClient->NotifyUpgradeProgresss(info);
205 
206         info.percent = PERCENT_40;
207         info.status = UPDATE_STATE_DOWNLOAD_ON;
208         g_testClient->NotifyUpgradeProgresss(info);
209 
210         info.percent = PERCENT_60;
211         info.status = UPDATE_STATE_DOWNLOAD_ON;
212         g_testClient->NotifyUpgradeProgresss(info);
213 
214         info.percent = PERCENT_100;
215         info.status = UPDATE_STATE_DOWNLOAD_SUCCESS;
216         g_testClient->NotifyUpgradeProgresss(info);
217 
218         // end of execution
219         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
220 
221         FreeAllNapiValues();
222         return 0;
223     }
224 
TestSetUpdatePolicy(bool isPormise)225     int TestSetUpdatePolicy(bool isPormise)
226     {
227         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_SET_POLICY);
228         g_testEnv.testAsyncorPermose = isPormise;
229         napi_value value = SetUpdatePolicy((napi_env)&g_testEnv, nullptr);
230         EXPECT_NE(value, nullptr);
231 
232         printf("TestSetUpdatePolicy \n");
233         // Trigger thread execution
234         UpdateSession *sess = TestGetUpdateSession();
235         CLIENT_CHECK(sess != nullptr, return -1, "TestSetUpdatePolicy");
236         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
237         // end of execution
238         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
239 
240         FreeAllNapiValues();
241         return 0;
242     }
243 
TestGetUpdatePolicy(bool isPormise)244     int TestGetUpdatePolicy(bool isPormise)
245     {
246         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_POLICY);
247         g_testEnv.testAsyncorPermose = isPormise;
248         napi_value value = GetUpdatePolicy((napi_env)&g_testEnv, nullptr);
249         EXPECT_NE(value, nullptr);
250 
251         // Trigger thread execution
252         UpdateSession *sess = TestGetUpdateSession();
253         CLIENT_CHECK(sess != nullptr, return -1, "TestGetUpdatePolicy");
254         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
255         // end of execution
256         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
257 
258         FreeAllNapiValues();
259         return 0;
260     }
261 
TestGetNewVersionInfo(bool isPormise)262     int TestGetNewVersionInfo(bool isPormise)
263     {
264         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_NEW_VERSION);
265         g_testEnv.testAsyncorPermose = isPormise;
266         napi_value value = GetNewVersionInfo((napi_env)&g_testEnv, nullptr);
267         EXPECT_NE(value, nullptr);
268         // Trigger thread execution
269         UpdateSession *sess = TestGetUpdateSession();
270         CLIENT_CHECK(sess != nullptr, return -1, "TestGetNewVersionInfo");
271         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
272         // end of execution
273         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
274 
275         FreeAllNapiValues();
276         return 0;
277     }
278 
TestGetUpgradeStatus(bool isPormise)279     int TestGetUpgradeStatus(bool isPormise)
280     {
281         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_GET_STATUS);
282         g_testEnv.testAsyncorPermose = isPormise;
283         napi_value value = GetUpgradeStatus((napi_env)&g_testEnv, nullptr);
284         EXPECT_NE(value, nullptr);
285 
286         // Trigger thread execution
287         UpdateSession *sess = TestGetUpdateSession();
288         CLIENT_CHECK(sess != nullptr, return -1, "TestGetUpgradeStatus");
289         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
290         // end of execution
291         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
292 
293         FreeAllNapiValues();
294         return 0;
295     }
296 
TestApplyNewVersion(bool isPormise)297     int TestApplyNewVersion(bool isPormise)
298     {
299         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_APPLY_NEW_VERSION);
300         g_testEnv.testAsyncorPermose = isPormise;
301         napi_value value = ApplyNewVersion((napi_env)&g_testEnv, nullptr);
302         EXPECT_NE(value, nullptr);
303 
304         // Trigger thread execution
305         UpdateSession *sess = TestGetUpdateSession();
306         CLIENT_CHECK(sess != nullptr, return -1, "TestApplyNewVersion");
307         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
308         // end of execution
309         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
310 
311         FreeAllNapiValues();
312         return 0;
313     }
314 
TestRebootAndClean(bool isPormise)315     int TestRebootAndClean(bool isPormise)
316     {
317         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_REBOOT_AND_CLEAN);
318         g_testEnv.testAsyncorPermose = isPormise;
319         napi_value value = RebootAndClean((napi_env)&g_testEnv, nullptr);
320         EXPECT_NE(value, nullptr);
321 
322         // Trigger thread execution
323         UpdateSession *sess = TestGetUpdateSession();
324         CLIENT_CHECK(sess != nullptr, return -1, "TestRebootAndClean");
325         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
326         // end of execution
327         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
328 
329         FreeAllNapiValues();
330         return 0;
331     }
332 
TestVerifyUpdatePackage(bool isPormise)333     int TestVerifyUpdatePackage(bool isPormise)
334     {
335         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_VERIFY_PACKAGE);
336         g_testEnv.testAsyncorPermose = isPormise;
337         napi_value value = VerifyUpdatePackage((napi_env)&g_testEnv, nullptr);
338         EXPECT_NE(value, nullptr);
339         // Trigger thread execution
340         UpdateSession *sess = TestGetUpdateSession();
341         CLIENT_CHECK(sess != nullptr, return -1, "TestVerifyUpdatePackage");
342         UpdateSession *sess1 = static_cast<UpdateSession*>(sess);
343         EXPECT_NE(sess1, nullptr);
344         sess1->UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok);
345         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
346 
347         // Call back the download result and save the result information
348         g_testClient->NotifyVerifyProgresss(0, PERCENT_60);
349         g_testClient->NotifyVerifyProgresss(0, PERCENT_100);
350 
351         // end of execution
352         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
353         FreeAllNapiValues();
354         return 0;
355     }
356 
TestSubscribeEvent(const std::string & eventType)357     int TestSubscribeEvent(const std::string &eventType)
358     {
359         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_SUBSCRIBE);
360         g_testEnv.testAsyncorPermose = false;
361         g_testEnv.eventType = eventType;
362         napi_value value = SubscribeEvent((napi_env)&g_testEnv, nullptr);
363         CLIENT_CHECK(value != nullptr, return -1, "TestSubscribeEvent");
364 
365         Progress info;
366         info.percent = PERCENT_20;
367         info.status = UPDATE_STATE_DOWNLOAD_ON;
368         g_testClient->NotifyUpgradeProgresss(info);
369 
370         info.percent = PERCENT_40;
371         info.status = UPDATE_STATE_DOWNLOAD_ON;
372         g_testClient->NotifyUpgradeProgresss(info);
373 
374         info.percent = PERCENT_60;
375         info.status = UPDATE_STATE_DOWNLOAD_ON;
376         g_testClient->NotifyDownloadProgress(info);
377 
378         info.percent = PERCENT_100;
379         info.status = UPDATE_STATE_DOWNLOAD_SUCCESS;
380         g_testClient->NotifyDownloadProgress(info);
381         FreeAllNapiValues();
382         return 0;
383     }
384 
TestUnsubscribeEvent(bool isPormise,const std::string & eventType)385     int TestUnsubscribeEvent(bool isPormise, const std::string &eventType)
386     {
387         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_UNSUBSCRIBE);
388         g_testEnv.testAsyncorPermose = isPormise;
389         g_testEnv.eventType = eventType;
390         napi_value value = UnsubscribeEvent((napi_env)&g_testEnv, nullptr);
391         CLIENT_CHECK(value != nullptr, return -1, "TestUnsubscribeEvent");
392 
393         FreeAllNapiValues();
394         return 0;
395     }
396 
TestCancelUpgrade(int type)397     int TestCancelUpgrade(int type)
398     {
399         g_testEnv.testStage = static_cast<int32_t>(SessionType::SESSION_CANCEL_UPGRADE);
400         g_testEnv.testAsyncorPermose = true;
401         napi_value value = CancelUpgrade((napi_env)&g_testEnv, nullptr);
402         CLIENT_CHECK(value != nullptr, return -1, "TestCancelUpgrade");
403 
404         // Trigger thread execution
405         UpdateSession *sess = TestGetUpdateSession();
406         CLIENT_CHECK(sess != nullptr, return -1, "TestCancelUpgrade");
407         UpdateSession::ExecuteWork((napi_env)&g_testEnv, reinterpret_cast<void*>(sess));
408         // end of execution
409         UpdateSession::CompleteWork((napi_env)&g_testEnv, napi_status::napi_ok, reinterpret_cast<void*>(sess));
410 
411         FreeAllNapiValues();
412         return 0;
413     }
414 };
415 
416 HWTEST_F(UpdateClientTest, TestGetUpdate, TestSize.Level1)
417 {
418     napi_value exports = nullptr;
419     UpdateClientInit((napi_env)&g_testEnv, exports);
420     UpdateClientTest test;
421     test.TestGetUpdate(false);
422     test.TestGetUpdaterFromOther(false);
423     test.TestGetUpdaterForOther(false);
424 }
425 
426 HWTEST_F(UpdateClientTest, TestGetUpdate2, TestSize.Level1)
427 {
428     UpdateClientTest test;
429     test.TestGetUpdate(true);
430     test.TestGetUpdaterFromOther(true);
431     test.TestGetUpdaterForOther(true);
432 }
433 
434 HWTEST_F(UpdateClientTest, TestCheckNewVersion, TestSize.Level1)
435 {
436     UpdateClientTest test;
437     test.TestGetUpdate(false);
438     EXPECT_EQ(0, test.TestCheckNewVersion(false));
439     EXPECT_EQ(0, test.TestCheckNewVersion(true));
440 }
441 
442 HWTEST_F(UpdateClientTest, TestDownloadVersion, TestSize.Level1)
443 {
444     UpdateClientTest test;
445     EXPECT_EQ(0, test.TestDownloadVersion(false));
446     EXPECT_EQ(0, test.TestDownloadVersion(true));
447 }
448 
449 HWTEST_F(UpdateClientTest, TestUpgradeVersion, TestSize.Level1)
450 {
451     UpdateClientTest test;
452     EXPECT_EQ(0, test.TestUpgradeVersion(false));
453     EXPECT_EQ(0, test.TestUpgradeVersion(true));
454 }
455 
456 HWTEST_F(UpdateClientTest, TestSetUpdatePolicy, TestSize.Level1)
457 {
458     UpdateClientTest test;
459     EXPECT_EQ(0, test.TestSetUpdatePolicy(false));
460     EXPECT_EQ(0, test.TestSetUpdatePolicy(true));
461 }
462 
463 HWTEST_F(UpdateClientTest, TestGetUpdatePolicy, TestSize.Level1)
464 {
465     UpdateClientTest test;
466     EXPECT_EQ(0, test.TestGetUpdatePolicy(false));
467     EXPECT_EQ(0, test.TestGetUpdatePolicy(true));
468 }
469 
470 HWTEST_F(UpdateClientTest, TestGetUpgradeStatus, TestSize.Level1)
471 {
472     UpdateClientTest test;
473     EXPECT_EQ(0, test.TestGetUpgradeStatus(false));
474     EXPECT_EQ(0, test.TestGetUpgradeStatus(true));
475 }
476 
477 HWTEST_F(UpdateClientTest, TestGetNewVersionInfo, TestSize.Level1)
478 {
479     UpdateClientTest test;
480     EXPECT_EQ(0, test.TestGetNewVersionInfo(false));
481     EXPECT_EQ(0, test.TestGetNewVersionInfo(true));
482 }
483 
484 HWTEST_F(UpdateClientTest, TestApplyNewVersion, TestSize.Level1)
485 {
486     UpdateClientTest test;
487     EXPECT_EQ(0, test.TestApplyNewVersion(false));
488     EXPECT_EQ(0, test.TestApplyNewVersion(true));
489 }
490 
491 HWTEST_F(UpdateClientTest, TestRebootAndClean, TestSize.Level1)
492 {
493     UpdateClientTest test;
494     EXPECT_EQ(0, test.TestRebootAndClean(false));
495     EXPECT_EQ(0, test.TestRebootAndClean(true));
496 }
497 
498 HWTEST_F(UpdateClientTest, TestVerifyUpdatePackage, TestSize.Level1)
499 {
500     UpdateClientTest test;
501     EXPECT_EQ(0, test.TestVerifyUpdatePackage(false));
502     EXPECT_EQ(0, test.TestVerifyUpdatePackage(true));
503 }
504 
505 HWTEST_F(UpdateClientTest, TestSubscribeEvent, TestSize.Level1)
506 {
507     UpdateClientTest test;
508     EXPECT_EQ(0, test.TestSubscribeEvent("downloadProgress"));
509     EXPECT_EQ(0, test.TestUnsubscribeEvent(false, "downloadProgress"));
510 }
511 
512 HWTEST_F(UpdateClientTest, TestSubscribeEvent2, TestSize.Level1)
513 {
514     UpdateClientTest test;
515     EXPECT_EQ(0, test.TestSubscribeEvent("downloadProgress"));
516     EXPECT_EQ(0, test.TestUnsubscribeEvent(true, "downloadProgress"));
517 }
518 
519 HWTEST_F(UpdateClientTest, TestSubscribeEvent3, TestSize.Level1)
520 {
521     UpdateClientTest test;
522     EXPECT_EQ(0, test.TestSubscribeEvent("upgradeProgress"));
523     EXPECT_EQ(0, test.TestUnsubscribeEvent(false, "upgradeProgress"));
524 }
525 
526 HWTEST_F(UpdateClientTest, TestSubscribeEvent4, TestSize.Level1)
527 {
528     UpdateClientTest test;
529     EXPECT_EQ(0, test.TestSubscribeEvent("upgradeProgress"));
530     EXPECT_EQ(0, test.TestUnsubscribeEvent(true, "upgradeProgress"));
531 }
532 
533 HWTEST_F(UpdateClientTest, TestCancelUpgrade, TestSize.Level1)
534 {
535     UpdateClientTest test;
536     EXPECT_EQ(0, test.TestCancelUpgrade(2));
537     EXPECT_EQ(0, test.TestCancelUpgrade(3));
538 }
539 
540 HWTEST_F(UpdateClientTest, TestNewClient, TestSize.Level1)
541 {
542     napi_value thisVar = nullptr;
543     UpdateClient *client = new UpdateClient((napi_env)&g_testEnv, thisVar);
544     delete client;
545 }
546 
547 HWTEST_F(UpdateClientTest, TestUpdateAsyncSessionNoCallback, TestSize.Level1)
548 {
549     UpdateSession *sess = new UpdateAsyncSessionNoCallback(g_testClient, 2, 1, 0);
550     EXPECT_NE(sess, nullptr);
551     delete sess;
552 }
553 
554 HWTEST_F(UpdateClientTest, TestUpdatePromiseSession, TestSize.Level1)
555 {
556     UpdateSession *sess = new UpdatePromiseSession (g_testClient, 2, 1, 0);
557     EXPECT_NE(sess, nullptr);
558     delete sess;
559 }
560 } // namespace
561