1 /*
2 * Copyright (c) 2024 SwanLink (Jiangsu) Technology Development 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 "napi/native_api.h"
17 #include "napi_version_test.h"
18
19 //OH_JSVM_GetVersion
20 //call this func,return jsvm ok
TestGetVersionCase01(JSVM_Env env,JSVM_CallbackInfo info)21 [[maybe_unused]] JSVM_Value TestGetVersionCase01(JSVM_Env env, JSVM_CallbackInfo info)
22 {
23 uint32_t result;
24 JSVM_Status status = OH_JSVM_GetVersion(env, &result);
25 if (status != JSVM_OK) {
26 OH_JSVM_ThrowError(env, nullptr, "TestGetVersionCase01:OH_JSVM_GetVersion Failed.");
27 return nullptr;
28 }
29
30 bool setValue = true;
31 JSVM_Value retValue = nullptr;
32 OH_JSVM_GetBoolean(env, setValue, &retValue);
33 return retValue;
34 }
35 //OH_JSVM_GetVMInfo:call func,return jsvm ok
TestGetVMInfoCase01(JSVM_Env env,JSVM_CallbackInfo info)36 [[maybe_unused]] JSVM_Value TestGetVMInfoCase01(JSVM_Env env, JSVM_CallbackInfo info)
37 {
38 JSVM_VMInfo result;
39 JSVM_Status status = OH_JSVM_GetVMInfo(&result);
40 if (status != JSVM_OK) {
41 OH_JSVM_ThrowError(env, nullptr, "TestGetVMInfoCase01:OH_JSVM_GetVMInfo Failed.");
42 return nullptr;
43 }
44
45 bool setValue = true;
46 JSVM_Value retValue = nullptr;
47 OH_JSVM_GetBoolean(env, setValue, &retValue);
48 return retValue;
49 }
50 //API:getversion -- getvminfo ok
TestGetVMInfoCase02(JSVM_Env env,JSVM_CallbackInfo info)51 [[maybe_unused]] JSVM_Value TestGetVMInfoCase02(JSVM_Env env, JSVM_CallbackInfo info)
52 {
53 uint32_t rst;
54 JSVM_Status status = OH_JSVM_GetVersion(env, &rst);
55 if (status != JSVM_OK) {
56 OH_JSVM_ThrowError(env, nullptr, "TestGetVMInfoCase02:OH_JSVM_GetVersion Failed.");
57 return nullptr;
58 }
59
60 JSVM_VMInfo result;
61 status = OH_JSVM_GetVMInfo(&result);
62 if (status != JSVM_OK) {
63 OH_JSVM_ThrowError(env, nullptr, "TestGetVMInfoCase02:OH_JSVM_GetVMInfo Failed.");
64 return nullptr;
65 }
66
67 bool setValue = true;
68 JSVM_Value retValue = nullptr;
69 OH_JSVM_GetBoolean(env, setValue, &retValue);
70 return retValue;
71 }