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 "test.h"
17
18 #include "quickjs_native_engine.h"
19
20 static NativeEngine* g_nativeEngine = nullptr;
21
NativeEngineTest()22 NativeEngineTest::NativeEngineTest()
23 {
24 engine_ = g_nativeEngine;
25 }
26
~NativeEngineTest()27 NativeEngineTest::~NativeEngineTest()
28 {
29 printf("NativeEngineTest::~NativeEngineTest \n");
30 engine_->RunCleanup();
31 }
32
main(int argc,char ** argv)33 int main(int argc, char** argv)
34 {
35 testing::GTEST_FLAG(output) = "xml:./";
36 testing::InitGoogleTest(&argc, argv);
37
38 JSRuntime* rt = JS_NewRuntime();
39 if (rt == nullptr) {
40 return 0;
41 }
42
43 JSContext* ctx = JS_NewContext(rt);
44 if (ctx == nullptr) {
45 return 0;
46 }
47
48 js_std_add_helpers(ctx, 0, nullptr);
49 g_nativeEngine = new QuickJSNativeEngine(rt, ctx, 0); // default instance id 0
50
51 int ret = RUN_ALL_TESTS();
52
53 delete g_nativeEngine;
54 g_nativeEngine = nullptr;
55
56 js_std_free_handlers(rt);
57 JS_FreeContext(ctx);
58 JS_FreeRuntime(rt);
59
60 return ret;
61 }
62