1 /*
2 * Copyright (c) 2025 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 <gtest/gtest.h>
17 #include <gtest/hwext/gtest-multithread.h>
18
19 #include "connect_server_manager.h"
20 #include "hilog_tag_wrapper.h"
21 #include "js_environment.h"
22 #include "js_runtime_common.h"
23 #include "js_runtime_lite.h"
24 #include "native_engine/native_engine.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace testing::mt;
29
30 namespace OHOS {
31 namespace AbilityRuntime {
32
33 class JsRuntimeCommonTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39 };
40
SetUpTestCase()41 void JsRuntimeCommonTest::SetUpTestCase() {}
42
TearDownTestCase()43 void JsRuntimeCommonTest::TearDownTestCase() {}
44
SetUp()45 void JsRuntimeCommonTest::SetUp() {}
46
TearDown()47 void JsRuntimeCommonTest::TearDown() {}
48
49 /**
50 * @tc.name: IsDebugModeTest_0100
51 * @tc.desc: IsDebugModeTest
52 * @tc.type: FUNC
53 */
54 HWTEST_F(JsRuntimeCommonTest, IsDebugModeTest_0100, TestSize.Level1)
55 {
56 GTEST_LOG_(INFO) << "IsDebugModeTest_0100 start";
57 JsRuntimeCommon::GetInstance().SetDebugMode(true);
58 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsDebugMode());
59 GTEST_LOG_(INFO) << "IsDebugModeTest_0100 end";
60 }
61
62 /**
63 * @tc.name: IsDebugAppTest_0100
64 * @tc.desc: IsDebugAppTest
65 * @tc.type: FUNC
66 */
67 HWTEST_F(JsRuntimeCommonTest, IsDebugAppTest_0100, TestSize.Level1)
68 {
69 GTEST_LOG_(INFO) << "IsDebugAppTest_0100 start";
70 JsRuntimeCommon::GetInstance().SetDebugApp(true);
71 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsDebugApp());
72 GTEST_LOG_(INFO) << "IsDebugAppTest_0100 end";
73 }
74
75 /**
76 * @tc.name: IsNativeStartTest_0100
77 * @tc.desc: IsNativeStartTest
78 * @tc.type: FUNC
79 */
80 HWTEST_F(JsRuntimeCommonTest, IsNativeStartTest_0100, TestSize.Level1)
81 {
82 GTEST_LOG_(INFO) << "IsNativeStartTest_0100 start";
83 JsRuntimeCommon::GetInstance().SetNativeStart(true);
84 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsNativeStart());
85 GTEST_LOG_(INFO) << "IsNativeStartTest_0100 end";
86 }
87
88 /**
89 * @tc.name: StartDebuggerModuleTest_0100
90 * @tc.desc: StartDebuggerModuleTest
91 * @tc.type: FUNC
92 */
93 HWTEST_F(JsRuntimeCommonTest, StartDebuggerModuleTest_0100, TestSize.Level1)
94 {
95 GTEST_LOG_(INFO) << "StartDebuggerModuleTest_0100 start";
96 JsRuntimeCommon::GetInstance().StartDebuggerModule(true, true);
97 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsDebugMode());
98 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsDebugApp());
99 EXPECT_TRUE(JsRuntimeCommon::GetInstance().IsNativeStart());
100 GTEST_LOG_(INFO) << "StartDebuggerModuleTest_0100 end";
101 }
102
103 /**
104 * @tc.name: StartDebugModeTest_0100
105 * @tc.desc: StartDebugModeTest
106 * @tc.type: FUNC
107 */
108 HWTEST_F(JsRuntimeCommonTest, StartDebugModeTest_0100, TestSize.Level1)
109 {
110 GTEST_LOG_(INFO) << "StartDebuggerModuleTest_0100 start";
111 auto ret = napi_status::napi_invalid_arg;
112 EXPECT_EQ(ret, JsRuntimeCommon::GetInstance().StartDebugMode(nullptr, "thread"));
113 JsRuntimeCommon::GetInstance().SetNativeStart(false);
114
115 AbilityRuntime::Runtime::Options options;
116 std::shared_ptr<OHOS::JsEnv::JsEnvironment> jsEnv = nullptr;
117 JsRuntimeLite::GetInstance().CreateJsEnv(options, jsEnv);
118 auto nativeEngine = jsEnv->GetNativeEngine();
119 JsRuntimeCommon::GetInstance().StartDebugMode(nativeEngine, "thread");
120 JsRuntimeCommon::GetInstance().SetNativeStart(true);
121 ret = napi_status::napi_ok;
122 EXPECT_EQ(ret, JsRuntimeCommon::GetInstance().StartDebugMode(nativeEngine, "thread"));
123 EXPECT_EQ(ret, JsRuntimeCommon::GetInstance().StopDebugMode(nativeEngine));
124 GTEST_LOG_(INFO) << "StartDebuggerModuleTest_0100 end";
125 }
126
127 /**
128 * @tc.name: StopDebugModeTest_0100
129 * @tc.desc: StopDebugModeTest
130 * @tc.type: FUNC
131 */
132 HWTEST_F(JsRuntimeCommonTest, StopDebugModeTest_0100, TestSize.Level1)
133 {
134 GTEST_LOG_(INFO) << "StopDebugModeTest_0100 start";
135 auto ret = napi_status::napi_invalid_arg;
136 EXPECT_EQ(ret, JsRuntimeCommon::GetInstance().StopDebugMode(nullptr));
137 GTEST_LOG_(INFO) << "StopDebugModeTest_0100 end";
138 }
139 } // namespace AbilityRuntime
140 } // namespace OHOS
141