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 "DMSTestBase.h"
17
18 #include <unistd.h>
19 #include <string>
20 #include <sys/timeb.h>
21
22 #include "semaphore.h"
23 #include "want.h"
24 #include "bundle_manager.h"
25 #include "bundle_info.h"
26
HOS_SystemInit(void)27 extern "C" void __attribute__((weak)) HOS_SystemInit(void)
28 {
29 SAMGR_Bootstrap();
30 };
31
32 static const int INIT_TIME = 1000;
33 static BOOL isInited = FALSE;
34
35 static sem_t g_sem;
36
SystemInitProxy()37 BOOL SystemInitProxy()
38 {
39 if (isInited == FALSE) {
40 printf("[hcpptest]samgr start init.\n");
41 HOS_SystemInit();
42
43 usleep(INIT_TIME * INIT_TIME);
44 isInited = TRUE;
45 } else {
46 printf("[hcpptest]samgr already init. \n");
47 }
48 }
49
GetSystemTime()50 long long GetSystemTime()
51 {
52 timeb t;
53 ftime(&t);
54 return t.time * MS2US + t.millitm;
55 }
56
GetStringByLen(int len)57 std::string GetStringByLen(int len)
58 {
59 std::string tempStr = "";
60 for (int i = 0; i < len; i++) {
61 tempStr = tempStr + "x";
62 }
63 return tempStr;
64 }
65
66 /* callback */
TestBundleStateCallback(const uint8_t resultCode,const void * resultMessage)67 static void TestBundleStateCallback(const uint8_t resultCode, const void *resultMessage)
68 {
69 printf("TestBundleStateCallback resultCode: %d \n", resultCode);
70 if (resultCode != 0) {
71 printf("[hcpptest]W install failed.\n");
72 }
73 sem_post(&g_sem);
74 }
75
InstallHap()76 BOOL InstallHap()
77 {
78 printf("[hcpptest]hap start to install!\n");
79
80 sem_init(&g_sem, 0, 0);
81 Install("/test_root/distributedschedule/helloworld_release.hap", nullptr, TestBundleStateCallback);
82 sem_wait(&g_sem);
83
84 usleep(INIT_TIME * INIT_TIME);
85 }
86
UninstallHap()87 BOOL UninstallHap()
88 {
89 sem_init(&g_sem, 0, 0);
90 Uninstall("com.ohos.helloworld", nullptr, TestBundleStateCallback);
91 sem_wait(&g_sem);
92 }
93