133eb0b6dSopenharmony_ci/* 233eb0b6dSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 333eb0b6dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 433eb0b6dSopenharmony_ci * you may not use this file except in compliance with the License. 533eb0b6dSopenharmony_ci * You may obtain a copy of the License at 633eb0b6dSopenharmony_ci * 733eb0b6dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 833eb0b6dSopenharmony_ci * 933eb0b6dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1033eb0b6dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1133eb0b6dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1233eb0b6dSopenharmony_ci * See the License for the specific language governing permissions and 1333eb0b6dSopenharmony_ci * limitations under the License. 1433eb0b6dSopenharmony_ci */ 1533eb0b6dSopenharmony_ci 1633eb0b6dSopenharmony_ci#include <cstring> 1733eb0b6dSopenharmony_ci#include <deque> 1833eb0b6dSopenharmony_ci#include <fstream> 1933eb0b6dSopenharmony_ci#include <iostream> 2033eb0b6dSopenharmony_ci#include <string> 2133eb0b6dSopenharmony_ci#include <vector> 2233eb0b6dSopenharmony_ci#include <chrono> 2333eb0b6dSopenharmony_ci 2433eb0b6dSopenharmony_ci#include "gtest/gtest.h" 2533eb0b6dSopenharmony_ci#include "jsvm.h" 2633eb0b6dSopenharmony_ci#include "jsvm_types.h" 2733eb0b6dSopenharmony_ci 2833eb0b6dSopenharmony_ciusing namespace std; 2933eb0b6dSopenharmony_ciusing namespace testing; 3033eb0b6dSopenharmony_ciusing namespace testing::ext; 3133eb0b6dSopenharmony_ci 3233eb0b6dSopenharmony_ci#define BUF_SIZE 256 3333eb0b6dSopenharmony_ci 3433eb0b6dSopenharmony_cistatic void PrintException(JSVM_Env env, JSVM_Value exception, const char *call) 3533eb0b6dSopenharmony_ci{ 3633eb0b6dSopenharmony_ci bool isObject = false; 3733eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_IsObject(env, exception, &isObject); 3833eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 3933eb0b6dSopenharmony_ci ASSERT_TRUE(isObject); 4033eb0b6dSopenharmony_ci 4133eb0b6dSopenharmony_ci JSVM_Value stack; 4233eb0b6dSopenharmony_ci status = OH_JSVM_GetNamedProperty(env, exception, "stack", &stack); 4333eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 4433eb0b6dSopenharmony_ci char stackStr[BUF_SIZE]; 4533eb0b6dSopenharmony_ci OH_JSVM_GetValueStringUtf8(env, stack, stackStr, BUF_SIZE, nullptr); 4633eb0b6dSopenharmony_ci printf("[PrintException] exception.stack: %s\n", stackStr); 4733eb0b6dSopenharmony_ci 4833eb0b6dSopenharmony_ci status = OH_JSVM_GetNamedProperty(env, exception, "message", &stack); 4933eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 5033eb0b6dSopenharmony_ci char messageStr[BUF_SIZE]; 5133eb0b6dSopenharmony_ci OH_JSVM_GetValueStringUtf8(env, stack, messageStr, BUF_SIZE, nullptr); 5233eb0b6dSopenharmony_ci printf("[PrintException] exception.message: %s\n", messageStr); 5333eb0b6dSopenharmony_ci} 5433eb0b6dSopenharmony_ci 5533eb0b6dSopenharmony_cistatic void CheckErrorAndException(JSVM_Env env, JSVM_Status returnStatus, const char *call) 5633eb0b6dSopenharmony_ci{ 5733eb0b6dSopenharmony_ci const JSVM_ExtendedErrorInfo *errorInfo; 5833eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_GetLastErrorInfo(env, &errorInfo); 5933eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 6033eb0b6dSopenharmony_ci ASSERT_EQ(returnStatus, errorInfo->errorCode); 6133eb0b6dSopenharmony_ci bool isPending = false; 6233eb0b6dSopenharmony_ci status = OH_JSVM_IsExceptionPending(env, &isPending); 6333eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 6433eb0b6dSopenharmony_ci JSVM_Value exception; 6533eb0b6dSopenharmony_ci status = OH_JSVM_GetAndClearLastException(env, &exception); 6633eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 6733eb0b6dSopenharmony_ci bool isExceptionUndefined = false; 6833eb0b6dSopenharmony_ci status = OH_JSVM_IsUndefined(env, exception, &isExceptionUndefined); 6933eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_OK); 7033eb0b6dSopenharmony_ci bool hasException = !isExceptionUndefined; 7133eb0b6dSopenharmony_ci if (hasException) { 7233eb0b6dSopenharmony_ci ASSERT_TRUE(isPending); 7333eb0b6dSopenharmony_ci ASSERT_NE(returnStatus, JSVM_OK); 7433eb0b6dSopenharmony_ci PrintException(env, exception, call); 7533eb0b6dSopenharmony_ci ASSERT_TRUE(false); 7633eb0b6dSopenharmony_ci } else { 7733eb0b6dSopenharmony_ci // no exception 7833eb0b6dSopenharmony_ci ASSERT_FALSE(isPending); 7933eb0b6dSopenharmony_ci } 8033eb0b6dSopenharmony_ci ASSERT_EQ(returnStatus, JSVM_OK); 8133eb0b6dSopenharmony_ci} 8233eb0b6dSopenharmony_ci 8333eb0b6dSopenharmony_ci#define JSVM_CALL(the_call) \ 8433eb0b6dSopenharmony_ci do { \ 8533eb0b6dSopenharmony_ci JSVM_Status status = (the_call); \ 8633eb0b6dSopenharmony_ci CheckErrorAndException(env, status, #the_call); \ 8733eb0b6dSopenharmony_ci } while (0) 8833eb0b6dSopenharmony_ci 8933eb0b6dSopenharmony_cistatic string srcProf = R"JS( 9033eb0b6dSopenharmony_cifunction sleep(delay) { 9133eb0b6dSopenharmony_ci var start = (new Date()).getTime(); 9233eb0b6dSopenharmony_ci while ((new Date()).getTime() - start < delay) { 9333eb0b6dSopenharmony_ci continue; 9433eb0b6dSopenharmony_ci } 9533eb0b6dSopenharmony_ci} 9633eb0b6dSopenharmony_cifunction work9() { 9733eb0b6dSopenharmony_ci sleep(100); 9833eb0b6dSopenharmony_ci} 9933eb0b6dSopenharmony_cifunction work8() { 10033eb0b6dSopenharmony_ci work9(); 10133eb0b6dSopenharmony_ci sleep(100); 10233eb0b6dSopenharmony_ci} 10333eb0b6dSopenharmony_cifunction work7() { 10433eb0b6dSopenharmony_ci work8(); 10533eb0b6dSopenharmony_ci sleep(100); 10633eb0b6dSopenharmony_ci} 10733eb0b6dSopenharmony_cifunction work6() { 10833eb0b6dSopenharmony_ci work7(); 10933eb0b6dSopenharmony_ci sleep(100); 11033eb0b6dSopenharmony_ci} 11133eb0b6dSopenharmony_cifunction work5() { 11233eb0b6dSopenharmony_ci work6(); 11333eb0b6dSopenharmony_ci sleep(100); 11433eb0b6dSopenharmony_ci} 11533eb0b6dSopenharmony_cifunction work4() { 11633eb0b6dSopenharmony_ci work5(); 11733eb0b6dSopenharmony_ci sleep(100); 11833eb0b6dSopenharmony_ci} 11933eb0b6dSopenharmony_ci 12033eb0b6dSopenharmony_cifunction work3() { 12133eb0b6dSopenharmony_ci work4(); 12233eb0b6dSopenharmony_ci sleep(100); 12333eb0b6dSopenharmony_ci} 12433eb0b6dSopenharmony_ci 12533eb0b6dSopenharmony_cifunction work2() { 12633eb0b6dSopenharmony_ci work3(); 12733eb0b6dSopenharmony_ci sleep(100); 12833eb0b6dSopenharmony_ci} 12933eb0b6dSopenharmony_ci 13033eb0b6dSopenharmony_cifunction work1() { 13133eb0b6dSopenharmony_ci work2(); 13233eb0b6dSopenharmony_ci sleep(100); 13333eb0b6dSopenharmony_ci} 13433eb0b6dSopenharmony_ci 13533eb0b6dSopenharmony_ciwork1(); 13633eb0b6dSopenharmony_ci)JS"; 13733eb0b6dSopenharmony_ci 13833eb0b6dSopenharmony_cistatic JSVM_Value hello_fn(JSVM_Env env, JSVM_CallbackInfo info) 13933eb0b6dSopenharmony_ci{ 14033eb0b6dSopenharmony_ci JSVM_Value output; 14133eb0b6dSopenharmony_ci void* data = nullptr; 14233eb0b6dSopenharmony_ci OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, nullptr, &data); 14333eb0b6dSopenharmony_ci OH_JSVM_CreateStringUtf8(env, (char*)data, strlen((char*)data), &output); 14433eb0b6dSopenharmony_ci return output; 14533eb0b6dSopenharmony_ci} 14633eb0b6dSopenharmony_ci 14733eb0b6dSopenharmony_ciclass Task { 14833eb0b6dSopenharmony_cipublic: 14933eb0b6dSopenharmony_ci virtual ~Task() = default; 15033eb0b6dSopenharmony_ci virtual void Run() = 0; 15133eb0b6dSopenharmony_ci}; 15233eb0b6dSopenharmony_ci 15333eb0b6dSopenharmony_cistatic deque<Task*> task_queue; 15433eb0b6dSopenharmony_ci 15533eb0b6dSopenharmony_cistatic JSVM_Value read_fn(JSVM_Env env, JSVM_CallbackInfo info) 15633eb0b6dSopenharmony_ci{ 15733eb0b6dSopenharmony_ci JSVM_Value promise; 15833eb0b6dSopenharmony_ci JSVM_Deferred deferred; 15933eb0b6dSopenharmony_ci OH_JSVM_CreatePromise(env, &deferred, &promise); 16033eb0b6dSopenharmony_ci class ReadTask : public Task { 16133eb0b6dSopenharmony_ci public: 16233eb0b6dSopenharmony_ci ReadTask(JSVM_Env env, JSVM_Deferred deferred) : env_(env), deferred_(deferred) {} 16333eb0b6dSopenharmony_ci void Run() override 16433eb0b6dSopenharmony_ci { 16533eb0b6dSopenharmony_ci string str; 16633eb0b6dSopenharmony_ci getline(cin, str); 16733eb0b6dSopenharmony_ci JSVM_Value result; 16833eb0b6dSopenharmony_ci OH_JSVM_CreateStringUtf8(env_, str.c_str(), str.size(), &result); 16933eb0b6dSopenharmony_ci OH_JSVM_ResolveDeferred(env_, deferred_, result); 17033eb0b6dSopenharmony_ci } 17133eb0b6dSopenharmony_ci private: 17233eb0b6dSopenharmony_ci JSVM_Env env_; 17333eb0b6dSopenharmony_ci JSVM_Deferred deferred_; 17433eb0b6dSopenharmony_ci }; 17533eb0b6dSopenharmony_ci task_queue.push_back(new ReadTask(env, deferred)); 17633eb0b6dSopenharmony_ci return promise; 17733eb0b6dSopenharmony_ci} 17833eb0b6dSopenharmony_ci 17933eb0b6dSopenharmony_ci#define BUF_SIZE1 102400 18033eb0b6dSopenharmony_cistatic JSVM_Value print_fn(JSVM_Env env, JSVM_CallbackInfo info) 18133eb0b6dSopenharmony_ci{ 18233eb0b6dSopenharmony_ci size_t argc = 1; 18333eb0b6dSopenharmony_ci JSVM_Value argv[1]; 18433eb0b6dSopenharmony_ci OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); 18533eb0b6dSopenharmony_ci if (argc > 0) { 18633eb0b6dSopenharmony_ci char buf[BUF_SIZE1]; 18733eb0b6dSopenharmony_ci OH_JSVM_GetValueStringUtf8(env, argv[0], buf, BUF_SIZE1, nullptr); 18833eb0b6dSopenharmony_ci std::cout << buf << std::endl; 18933eb0b6dSopenharmony_ci } 19033eb0b6dSopenharmony_ci return nullptr; 19133eb0b6dSopenharmony_ci} 19233eb0b6dSopenharmony_ci 19333eb0b6dSopenharmony_cistatic JSVM_CallbackStruct hello_cb = { hello_fn, (void *)"Hello" }; 19433eb0b6dSopenharmony_cistatic JSVM_CallbackStruct read_cb = { read_fn, nullptr }; 19533eb0b6dSopenharmony_cistatic JSVM_CallbackStruct print_cb = { print_fn, nullptr }; 19633eb0b6dSopenharmony_ci 19733eb0b6dSopenharmony_cistatic JSVM_PropertyDescriptor property_descriptors[] = { 19833eb0b6dSopenharmony_ci { 19933eb0b6dSopenharmony_ci "hello", 20033eb0b6dSopenharmony_ci NULL, 20133eb0b6dSopenharmony_ci &hello_cb, 20233eb0b6dSopenharmony_ci NULL, 20333eb0b6dSopenharmony_ci NULL, 20433eb0b6dSopenharmony_ci NULL, 20533eb0b6dSopenharmony_ci JSVM_DEFAULT 20633eb0b6dSopenharmony_ci }, 20733eb0b6dSopenharmony_ci { 20833eb0b6dSopenharmony_ci "read", 20933eb0b6dSopenharmony_ci NULL, 21033eb0b6dSopenharmony_ci &read_cb, 21133eb0b6dSopenharmony_ci NULL, 21233eb0b6dSopenharmony_ci NULL, 21333eb0b6dSopenharmony_ci NULL, 21433eb0b6dSopenharmony_ci JSVM_DEFAULT 21533eb0b6dSopenharmony_ci }, 21633eb0b6dSopenharmony_ci { 21733eb0b6dSopenharmony_ci "print", 21833eb0b6dSopenharmony_ci NULL, 21933eb0b6dSopenharmony_ci &print_cb, 22033eb0b6dSopenharmony_ci NULL, 22133eb0b6dSopenharmony_ci NULL, 22233eb0b6dSopenharmony_ci NULL, 22333eb0b6dSopenharmony_ci JSVM_DEFAULT 22433eb0b6dSopenharmony_ci }, 22533eb0b6dSopenharmony_ci}; 22633eb0b6dSopenharmony_ci 22733eb0b6dSopenharmony_ciclass JSVMTest : public testing::Test { 22833eb0b6dSopenharmony_cipublic: 22933eb0b6dSopenharmony_ci static void SetUpTestCase() 23033eb0b6dSopenharmony_ci { 23133eb0b6dSopenharmony_ci GTEST_LOG_(INFO) << "JSVMTest SetUpTestCase"; 23233eb0b6dSopenharmony_ci JSVM_InitOptions init_options{}; 23333eb0b6dSopenharmony_ci OH_JSVM_Init(&init_options); 23433eb0b6dSopenharmony_ci } 23533eb0b6dSopenharmony_ci 23633eb0b6dSopenharmony_ci static void TearDownTestCase() 23733eb0b6dSopenharmony_ci { 23833eb0b6dSopenharmony_ci GTEST_LOG_(INFO) << "JSVMTest TearDownTestCase"; 23933eb0b6dSopenharmony_ci } 24033eb0b6dSopenharmony_ci 24133eb0b6dSopenharmony_ci void SetUp() override 24233eb0b6dSopenharmony_ci { 24333eb0b6dSopenharmony_ci GTEST_LOG_(INFO) << "JSVMTest SetUp"; 24433eb0b6dSopenharmony_ci OH_JSVM_CreateVM(nullptr, &vm); 24533eb0b6dSopenharmony_ci // propertyCount is 3 24633eb0b6dSopenharmony_ci OH_JSVM_CreateEnv(vm, 3, property_descriptors, &env); 24733eb0b6dSopenharmony_ci OH_JSVM_OpenVMScope(vm, &vm_scope); 24833eb0b6dSopenharmony_ci OH_JSVM_OpenEnvScope(env, &env_scope); 24933eb0b6dSopenharmony_ci OH_JSVM_OpenHandleScope(env, &handleScope); 25033eb0b6dSopenharmony_ci } 25133eb0b6dSopenharmony_ci void TearDown() override 25233eb0b6dSopenharmony_ci { 25333eb0b6dSopenharmony_ci GTEST_LOG_(INFO) << "JSVMTest TearDown"; 25433eb0b6dSopenharmony_ci OH_JSVM_CloseHandleScope(env, handleScope); 25533eb0b6dSopenharmony_ci OH_JSVM_CloseEnvScope(env, env_scope); 25633eb0b6dSopenharmony_ci OH_JSVM_CloseVMScope(vm, vm_scope); 25733eb0b6dSopenharmony_ci OH_JSVM_DestroyEnv(env); 25833eb0b6dSopenharmony_ci OH_JSVM_DestroyVM(vm); 25933eb0b6dSopenharmony_ci } 26033eb0b6dSopenharmony_ci 26133eb0b6dSopenharmony_ciprotected: 26233eb0b6dSopenharmony_ci JSVM_Env env = nullptr; 26333eb0b6dSopenharmony_ci JSVM_VM vm = nullptr; 26433eb0b6dSopenharmony_ci JSVM_EnvScope env_scope = nullptr; 26533eb0b6dSopenharmony_ci JSVM_VMScope vm_scope = nullptr; 26633eb0b6dSopenharmony_ci JSVM_HandleScope handleScope; 26733eb0b6dSopenharmony_ci}; 26833eb0b6dSopenharmony_ci 26933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMGetVersion001, TestSize.Level1) 27033eb0b6dSopenharmony_ci{ 27133eb0b6dSopenharmony_ci uint32_t versionId = 0; 27233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetVersion(env, &versionId)); 27333eb0b6dSopenharmony_ci ASSERT_EQ(versionId, 9); 27433eb0b6dSopenharmony_ci} 27533eb0b6dSopenharmony_ci 27633eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMEquals001, TestSize.Level1) 27733eb0b6dSopenharmony_ci{ 27833eb0b6dSopenharmony_ci JSVM_Value lhs = nullptr; 27933eb0b6dSopenharmony_ci bool x = true; 28033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetBoolean(env, x, &lhs)); 28133eb0b6dSopenharmony_ci JSVM_Value rhs = nullptr; 28233eb0b6dSopenharmony_ci bool y = true; 28333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetBoolean(env, y, &rhs)); 28433eb0b6dSopenharmony_ci bool isEquals = false; 28533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_Equals(env, lhs, rhs, &isEquals)); 28633eb0b6dSopenharmony_ci ASSERT_TRUE(isEquals); 28733eb0b6dSopenharmony_ci} 28833eb0b6dSopenharmony_ci 28933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCreateCodeCache001, TestSize.Level1) 29033eb0b6dSopenharmony_ci{ 29133eb0b6dSopenharmony_ci JSVM_Value jsSrc; 29233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateStringUtf8(env, srcProf.c_str(), srcProf.size(), &jsSrc)); 29333eb0b6dSopenharmony_ci 29433eb0b6dSopenharmony_ci const uint8_t x1 = 34; 29533eb0b6dSopenharmony_ci const uint8_t* x2 = &x1; 29633eb0b6dSopenharmony_ci const uint8_t** dataPtr = &x2; 29733eb0b6dSopenharmony_ci size_t x3 = 1; 29833eb0b6dSopenharmony_ci size_t* lengthPtr = &x3; 29933eb0b6dSopenharmony_ci JSVM_Script script = nullptr; 30033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); 30133eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateCodeCache(env, script, dataPtr, lengthPtr)); 30233eb0b6dSopenharmony_ci} 30333eb0b6dSopenharmony_ci 30433eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMAcquire001, TestSize.Level1) 30533eb0b6dSopenharmony_ci{ 30633eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_AcquireLock(env)); 30733eb0b6dSopenharmony_ci} 30833eb0b6dSopenharmony_ci 30933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsObject001, TestSize.Level1) 31033eb0b6dSopenharmony_ci{ 31133eb0b6dSopenharmony_ci JSVM_Value obj; 31233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateMap(env, &obj)); 31333eb0b6dSopenharmony_ci bool result = false; 31433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsObject(env, obj, &result)); 31533eb0b6dSopenharmony_ci ASSERT_TRUE(result); 31633eb0b6dSopenharmony_ci 31733eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateSymbol(env, nullptr, &obj)); 31833eb0b6dSopenharmony_ci result = false; 31933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsObject(env, obj, &result)); 32033eb0b6dSopenharmony_ci ASSERT_FALSE(result); 32133eb0b6dSopenharmony_ci} 32233eb0b6dSopenharmony_ci 32333eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsBoolean001, TestSize.Level1) 32433eb0b6dSopenharmony_ci{ 32533eb0b6dSopenharmony_ci JSVM_Value obj; 32633eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateArray(env, &obj)); 32733eb0b6dSopenharmony_ci bool result = false; 32833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsBoolean(env, obj, &result)); 32933eb0b6dSopenharmony_ci ASSERT_FALSE(result); 33033eb0b6dSopenharmony_ci 33133eb0b6dSopenharmony_ci bool boolvalue = true; 33233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetBoolean(env, boolvalue, &obj)); 33333eb0b6dSopenharmony_ci result = false; 33433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsBoolean(env, obj, &result)); 33533eb0b6dSopenharmony_ci ASSERT_TRUE(result); 33633eb0b6dSopenharmony_ci} 33733eb0b6dSopenharmony_ci 33833eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsString001, TestSize.Level1) 33933eb0b6dSopenharmony_ci{ 34033eb0b6dSopenharmony_ci JSVM_Value createString; 34133eb0b6dSopenharmony_ci char str[12] = "hello world"; 34233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateStringUtf8(env, str, 12, &createString)); 34333eb0b6dSopenharmony_ci bool result = false; 34433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsString(env, createString, &result)); 34533eb0b6dSopenharmony_ci ASSERT_TRUE(result); 34633eb0b6dSopenharmony_ci 34733eb0b6dSopenharmony_ci JSVM_Value obj = nullptr; 34833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateSet(env, &obj)); 34933eb0b6dSopenharmony_ci result = false; 35033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsString(env, obj, &result)); 35133eb0b6dSopenharmony_ci ASSERT_FALSE(result); 35233eb0b6dSopenharmony_ci} 35333eb0b6dSopenharmony_ci 35433eb0b6dSopenharmony_ci 35533eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsFunction001, TestSize.Level1) 35633eb0b6dSopenharmony_ci{ 35733eb0b6dSopenharmony_ci JSVM_Value function; 35833eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 35933eb0b6dSopenharmony_ci param.data = nullptr; 36033eb0b6dSopenharmony_ci param.callback = nullptr; 36133eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateFunction(env, "func", JSVM_AUTO_LENGTH, ¶m, &function)); 36233eb0b6dSopenharmony_ci bool result = false; 36333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsFunction(env, function, &result)); 36433eb0b6dSopenharmony_ci ASSERT_TRUE(result); 36533eb0b6dSopenharmony_ci 36633eb0b6dSopenharmony_ci JSVM_Value obj; 36733eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateObject(env, &obj)); 36833eb0b6dSopenharmony_ci result = false; 36933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsFunction(env, obj, &result)); 37033eb0b6dSopenharmony_ci ASSERT_FALSE(result); 37133eb0b6dSopenharmony_ci} 37233eb0b6dSopenharmony_ci 37333eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsSymbol001, TestSize.Level1) 37433eb0b6dSopenharmony_ci{ 37533eb0b6dSopenharmony_ci JSVM_Value obj; 37633eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateSymbol(env, nullptr, &obj)); 37733eb0b6dSopenharmony_ci bool result = false; 37833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsSymbol(env, obj, &result)); 37933eb0b6dSopenharmony_ci ASSERT_TRUE(result); 38033eb0b6dSopenharmony_ci 38133eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateObject(env, &obj)); 38233eb0b6dSopenharmony_ci result = false; 38333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsSymbol(env, obj, &result)); 38433eb0b6dSopenharmony_ci ASSERT_FALSE(result); 38533eb0b6dSopenharmony_ci} 38633eb0b6dSopenharmony_ci 38733eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsNumber001, TestSize.Level1) 38833eb0b6dSopenharmony_ci{ 38933eb0b6dSopenharmony_ci JSVM_Value obj; 39033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateObject(env, &obj)); 39133eb0b6dSopenharmony_ci bool result = false; 39233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNumber(env, obj, &result)); 39333eb0b6dSopenharmony_ci ASSERT_FALSE(result); 39433eb0b6dSopenharmony_ci 39533eb0b6dSopenharmony_ci JSVM_Value value; 39633eb0b6dSopenharmony_ci int intValue = 2; 39733eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateInt32(env, intValue, &value)); 39833eb0b6dSopenharmony_ci result = false; 39933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNumber(env, value, &result)); 40033eb0b6dSopenharmony_ci ASSERT_TRUE(result); 40133eb0b6dSopenharmony_ci} 40233eb0b6dSopenharmony_ci 40333eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsBigInt001, TestSize.Level1) 40433eb0b6dSopenharmony_ci{ 40533eb0b6dSopenharmony_ci JSVM_Value obj; 40633eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateObject(env, &obj)); 40733eb0b6dSopenharmony_ci bool result = false; 40833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsBigInt(env, obj, &result)); 40933eb0b6dSopenharmony_ci ASSERT_FALSE(result); 41033eb0b6dSopenharmony_ci 41133eb0b6dSopenharmony_ci JSVM_Value bigint; 41233eb0b6dSopenharmony_ci int intValue = 2; 41333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateBigintInt64(env, intValue, &bigint)); 41433eb0b6dSopenharmony_ci result = false; 41533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsBigInt(env, bigint, &result)); 41633eb0b6dSopenharmony_ci ASSERT_TRUE(result); 41733eb0b6dSopenharmony_ci} 41833eb0b6dSopenharmony_ci 41933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsNull001, TestSize.Level1) 42033eb0b6dSopenharmony_ci{ 42133eb0b6dSopenharmony_ci JSVM_Value input; 42233eb0b6dSopenharmony_ci bool result = false; 42333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateArray(env, &input)); 42433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNull(env, input, &result)); 42533eb0b6dSopenharmony_ci ASSERT_FALSE(result); 42633eb0b6dSopenharmony_ci 42733eb0b6dSopenharmony_ci JSVM_Value input2; 42833eb0b6dSopenharmony_ci bool result2; 42933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetNull(env, &input2)); 43033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNull(env, input2, &result2)); 43133eb0b6dSopenharmony_ci ASSERT_TRUE(result2); 43233eb0b6dSopenharmony_ci} 43333eb0b6dSopenharmony_ci 43433eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsUndefined001, TestSize.Level1) 43533eb0b6dSopenharmony_ci{ 43633eb0b6dSopenharmony_ci JSVM_Value input; 43733eb0b6dSopenharmony_ci bool result = false; 43833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateArray(env, &input)); 43933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsUndefined(env, input, &result)); 44033eb0b6dSopenharmony_ci ASSERT_FALSE(result); 44133eb0b6dSopenharmony_ci 44233eb0b6dSopenharmony_ci JSVM_Value input2; 44333eb0b6dSopenharmony_ci bool result2; 44433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetUndefined(env, &input2)); 44533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsUndefined(env, input2, &result2)); 44633eb0b6dSopenharmony_ci ASSERT_TRUE(result2); 44733eb0b6dSopenharmony_ci} 44833eb0b6dSopenharmony_ci 44933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, OH_JSVM_IsNullOrUndefined001, TestSize.Level1) 45033eb0b6dSopenharmony_ci{ 45133eb0b6dSopenharmony_ci JSVM_Value input; 45233eb0b6dSopenharmony_ci bool result = false; 45333eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateArray(env, &input)); 45433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNullOrUndefined(env, input, &result)); 45533eb0b6dSopenharmony_ci ASSERT_FALSE(result); 45633eb0b6dSopenharmony_ci 45733eb0b6dSopenharmony_ci JSVM_Value input2; 45833eb0b6dSopenharmony_ci bool result2 = false; 45933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetNull(env, &input2)); 46033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNullOrUndefined(env, input2, &result2)); 46133eb0b6dSopenharmony_ci ASSERT_TRUE(result2); 46233eb0b6dSopenharmony_ci 46333eb0b6dSopenharmony_ci result2 = false; 46433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetUndefined(env, &input2)); 46533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsNullOrUndefined(env, input2, &result2)); 46633eb0b6dSopenharmony_ci ASSERT_TRUE(result2); 46733eb0b6dSopenharmony_ci} 46833eb0b6dSopenharmony_ci 46933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMIsLocked001, TestSize.Level1) 47033eb0b6dSopenharmony_ci{ 47133eb0b6dSopenharmony_ci bool isLocked = false; 47233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsLocked(env, &isLocked)); 47333eb0b6dSopenharmony_ci} 47433eb0b6dSopenharmony_ci 47533eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMReleaseLock001, TestSize.Level1) 47633eb0b6dSopenharmony_ci{ 47733eb0b6dSopenharmony_ci bool isLocked = false; 47833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_IsLocked(env, &isLocked)); 47933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_ReleaseLock(env)); 48033eb0b6dSopenharmony_ci} 48133eb0b6dSopenharmony_ci 48233eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCompileScriptWithOrigin001, TestSize.Level1) 48333eb0b6dSopenharmony_ci{ 48433eb0b6dSopenharmony_ci JSVM_Value jsSrc; 48533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CreateStringUtf8(env, srcProf.c_str(), srcProf.size(), &jsSrc)); 48633eb0b6dSopenharmony_ci JSVM_Script script; 48733eb0b6dSopenharmony_ci JSVM_ScriptOrigin origin { 48833eb0b6dSopenharmony_ci .sourceMapUrl = "/data/local/tmp/workload/index.js.map", 48933eb0b6dSopenharmony_ci // 源文件名字 49033eb0b6dSopenharmony_ci .resourceName = "index.js", 49133eb0b6dSopenharmony_ci // scirpt 在源文件中的起始行列号 49233eb0b6dSopenharmony_ci .resourceLineOffset = 0, 49333eb0b6dSopenharmony_ci .resourceColumnOffset = 0, 49433eb0b6dSopenharmony_ci }; 49533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_CompileScriptWithOrigin(env, jsSrc, nullptr, 0, true, nullptr, &origin, &script)); 49633eb0b6dSopenharmony_ci} 49733eb0b6dSopenharmony_ci 49833eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCompileScriptWithOrigin002, TestSize.Level1) 49933eb0b6dSopenharmony_ci{ 50033eb0b6dSopenharmony_ci JSVM_Value jsSrc = nullptr; 50133eb0b6dSopenharmony_ci bool x = true; 50233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetBoolean(env, x, &jsSrc)); 50333eb0b6dSopenharmony_ci JSVM_Script script; 50433eb0b6dSopenharmony_ci JSVM_ScriptOrigin origin { 50533eb0b6dSopenharmony_ci .sourceMapUrl = "/data/local/tmp/workload/index.js.map", 50633eb0b6dSopenharmony_ci // 源文件名字 50733eb0b6dSopenharmony_ci .resourceName = "index.js", 50833eb0b6dSopenharmony_ci // scirpt 在源文件中的起始行列号 50933eb0b6dSopenharmony_ci .resourceLineOffset = 0, 51033eb0b6dSopenharmony_ci .resourceColumnOffset = 0, 51133eb0b6dSopenharmony_ci }; 51233eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_CompileScriptWithOrigin(env, jsSrc, nullptr, 0, true, nullptr, &origin, &script); 51333eb0b6dSopenharmony_ci ASSERT_EQ(status, 3); 51433eb0b6dSopenharmony_ci} 51533eb0b6dSopenharmony_ci 51633eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCompileScriptWithOrigin003, TestSize.Level1) 51733eb0b6dSopenharmony_ci{ 51833eb0b6dSopenharmony_ci JSVM_Value jsSrc = nullptr; 51933eb0b6dSopenharmony_ci bool x = true; 52033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetBoolean(env, x, &jsSrc)); 52133eb0b6dSopenharmony_ci JSVM_ScriptOrigin origin { 52233eb0b6dSopenharmony_ci .sourceMapUrl = "/data/local/tmp/workload/index.js.map", 52333eb0b6dSopenharmony_ci // 源文件名字 52433eb0b6dSopenharmony_ci .resourceName = "index.js", 52533eb0b6dSopenharmony_ci // scirpt 在源文件中的起始行列号 52633eb0b6dSopenharmony_ci .resourceLineOffset = 0, 52733eb0b6dSopenharmony_ci .resourceColumnOffset = 0, 52833eb0b6dSopenharmony_ci }; 52933eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_CompileScriptWithOrigin(env, jsSrc, nullptr, 0, true, nullptr, &origin, nullptr); 53033eb0b6dSopenharmony_ci ASSERT_EQ(status, 1); 53133eb0b6dSopenharmony_ci} 53233eb0b6dSopenharmony_ci 53333eb0b6dSopenharmony_cistatic JSVM_PropertyHandlerConfigurationStruct propertyCfg{ 53433eb0b6dSopenharmony_ci nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr 53533eb0b6dSopenharmony_ci}; 53633eb0b6dSopenharmony_ci 53733eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler001, TestSize.Level1) 53833eb0b6dSopenharmony_ci{ 53933eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 54033eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 54133eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 54233eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 54333eb0b6dSopenharmony_ci return thisVar; 54433eb0b6dSopenharmony_ci }; 54533eb0b6dSopenharmony_ci param.data = nullptr; 54633eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 54733eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", 5, ¶m, 0, nullptr, 54833eb0b6dSopenharmony_ci &propertyCfg, nullptr, &testWrapClass)); 54933eb0b6dSopenharmony_ci} 55033eb0b6dSopenharmony_ci 55133eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler002, TestSize.Level1) 55233eb0b6dSopenharmony_ci{ 55333eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 55433eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 55533eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 55633eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 55733eb0b6dSopenharmony_ci return thisVar; 55833eb0b6dSopenharmony_ci }; 55933eb0b6dSopenharmony_ci param.data = nullptr; 56033eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 56133eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", JSVM_AUTO_LENGTH, ¶m, 0, 56233eb0b6dSopenharmony_ci nullptr, &propertyCfg, nullptr, &testWrapClass)); 56333eb0b6dSopenharmony_ci} 56433eb0b6dSopenharmony_ci 56533eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler003, TestSize.Level1) 56633eb0b6dSopenharmony_ci{ 56733eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 56833eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 56933eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 57033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 57133eb0b6dSopenharmony_ci return thisVar; 57233eb0b6dSopenharmony_ci }; 57333eb0b6dSopenharmony_ci param.data = nullptr; 57433eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 57533eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", 4, ¶m, 0, nullptr, &propertyCfg, 57633eb0b6dSopenharmony_ci nullptr, &testWrapClass)); 57733eb0b6dSopenharmony_ci} 57833eb0b6dSopenharmony_ci 57933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler004, TestSize.Level1) 58033eb0b6dSopenharmony_ci{ 58133eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 58233eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 58333eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 58433eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 58533eb0b6dSopenharmony_ci return thisVar; 58633eb0b6dSopenharmony_ci }; 58733eb0b6dSopenharmony_ci param.data = nullptr; 58833eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 58933eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", 6, ¶m, 0, nullptr, 59033eb0b6dSopenharmony_ci &propertyCfg, nullptr, &testWrapClass)); 59133eb0b6dSopenharmony_ci} 59233eb0b6dSopenharmony_ci 59333eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler005, TestSize.Level1) 59433eb0b6dSopenharmony_ci{ 59533eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 59633eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 59733eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 59833eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 59933eb0b6dSopenharmony_ci return thisVar; 60033eb0b6dSopenharmony_ci }; 60133eb0b6dSopenharmony_ci param.data = nullptr; 60233eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", JSVM_AUTO_LENGTH, ¶m, 0, 60333eb0b6dSopenharmony_ci nullptr, &propertyCfg, nullptr, nullptr); 60433eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_INVALID_ARG); 60533eb0b6dSopenharmony_ci} 60633eb0b6dSopenharmony_ci 60733eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler006, TestSize.Level1) 60833eb0b6dSopenharmony_ci{ 60933eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 61033eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", JSVM_AUTO_LENGTH, nullptr, 0, 61133eb0b6dSopenharmony_ci nullptr, &propertyCfg, nullptr, &testWrapClass); 61233eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_INVALID_ARG); 61333eb0b6dSopenharmony_ci} 61433eb0b6dSopenharmony_ci 61533eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMDefineClassWithPropertyHandler007, TestSize.Level1) 61633eb0b6dSopenharmony_ci{ 61733eb0b6dSopenharmony_ci JSVM_CallbackStruct param; 61833eb0b6dSopenharmony_ci param.callback = [](JSVM_Env env, JSVM_CallbackInfo info) -> JSVM_Value { 61933eb0b6dSopenharmony_ci JSVM_Value thisVar = nullptr; 62033eb0b6dSopenharmony_ci JSVM_CALL(OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, &thisVar, nullptr)); 62133eb0b6dSopenharmony_ci return thisVar; 62233eb0b6dSopenharmony_ci }; 62333eb0b6dSopenharmony_ci param.data = nullptr; 62433eb0b6dSopenharmony_ci JSVM_Value testWrapClass = nullptr; 62533eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_DefineClassWithPropertyHandler(env, "Test2", JSVM_AUTO_LENGTH, ¶m, 0, 62633eb0b6dSopenharmony_ci nullptr, nullptr, nullptr, &testWrapClass); 62733eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_INVALID_ARG); 62833eb0b6dSopenharmony_ci} 62933eb0b6dSopenharmony_ci 63033eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCreateSnapshot001, TestSize.Level1) 63133eb0b6dSopenharmony_ci{ 63233eb0b6dSopenharmony_ci const char *blobData = nullptr; 63333eb0b6dSopenharmony_ci size_t blobSize = 0; 63433eb0b6dSopenharmony_ci JSVM_Env envs[1] = {env}; 63533eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_CreateSnapshot(vm, 1, envs, &blobData, &blobSize); 63633eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_GENERIC_FAILURE); 63733eb0b6dSopenharmony_ci} 63833eb0b6dSopenharmony_ci 63933eb0b6dSopenharmony_ciHWTEST_F(JSVMTest, JSVMCreateEnvFromSnapshot001, TestSize.Level1) 64033eb0b6dSopenharmony_ci{ 64133eb0b6dSopenharmony_ci JSVM_Env env2 = nullptr; 64233eb0b6dSopenharmony_ci JSVM_Status status = OH_JSVM_CreateEnvFromSnapshot(vm, 0, &env2); 64333eb0b6dSopenharmony_ci ASSERT_EQ(status, JSVM_GENERIC_FAILURE); 64433eb0b6dSopenharmony_ci}