1 /**
2 * Copyright (c) 2024-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 "libabckit/include/c/isa/isa_static.h"
17 #include "libabckit/include/c/metadata_core.h"
18 #include "libabckit/include/c/ir_core.h"
19 #include "libabckit/include/c/isa/isa_dynamic.h"
20 #include "libabckit/include/c/abckit.h"
21
22 #include "helpers/helpers.h"
23 #include "helpers/helpers_runtime.h"
24
25 #include <gtest/gtest.h>
26
27 namespace libabckit::test {
28
29 class LibAbcKitStaticTryCatchTest : public ::testing::Test {};
30
31 namespace {
32 auto *g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 auto *g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 auto *g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35 auto *g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
36 auto g_dynG = AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0);
37
38 enum class TryCatchScenario {
39 DEFAULT_POSITIVE = 0,
40 };
41 } // namespace
42
43 // Test: test-kind=internal, abc-kind=ArkTS2, category=internal
TEST_F(LibAbcKitStaticTryCatchTest,TryCatchIrbuilder)44 TEST_F(LibAbcKitStaticTryCatchTest, TryCatchIrbuilder)
45 {
46 auto output = helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/ir_core/insert_try_catch/insert_try_catch_static.abc",
47 "insert_try_catch_static/ETSGLOBAL", "main");
48 EXPECT_TRUE(helpers::Match(output, "TRY1\nTRY2\nCATCH\nTRY1\nTRY3\n"));
49
50 helpers::TransformMethod(
51 ABCKIT_ABC_DIR "ut/ir_core/insert_try_catch/insert_try_catch_static.abc",
52 ABCKIT_ABC_DIR "ut/ir_core/insert_try_catch/insert_try_catch_static_modified.abc", "foo",
53 []([[maybe_unused]] AbckitFile *file, [[maybe_unused]] AbckitCoreFunction *method,
54 [[maybe_unused]] AbckitGraph *graph) {},
55 [&]([[maybe_unused]] AbckitGraph *graph) {});
56
57 output =
58 helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/ir_core/insert_try_catch/insert_try_catch_static_modified.abc",
59 "insert_try_catch_static/ETSGLOBAL", "main");
60 EXPECT_TRUE(helpers::Match(output, "TRY1\nTRY2\nCATCH\nTRY1\nTRY3\n"));
61 }
62
63 } // namespace libabckit::test
64