• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
18 #include "libabckit/include/c/abckit.h"
19 #include "helpers/helpers.h"
20 #include "helpers/helpers_runtime.h"
21 #include "api_modifier.h"
22 
23 namespace libabckit::test {
24 
25 class AbckitScenarioTest : public ::testing::Test {};
26 
27 // Test: test-kind=scenario, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(AbckitScenarioTest,LibAbcKitTestParameterCheck)28 TEST_F(AbckitScenarioTest, LibAbcKitTestParameterCheck)
29 {
30     static constexpr auto VERSION = ABCKIT_VERSION_RELEASE_1_0_0;
31     static constexpr auto INPUT_PATH = ABCKIT_ABC_DIR "scenarios/parameter_check/dynamic/parameter_check.abc";
32     static constexpr auto OUTPUT_PATH = ABCKIT_ABC_DIR "scenarios/parameter_check/dynamic/parameter_check_modified.abc";
33     const std::string entryPoint = "parameter_check";
34 
35     auto *impl = AbckitGetApiImpl(VERSION);
36     AbckitFile *file = impl->openAbc(INPUT_PATH, strlen(INPUT_PATH));
37     ASSERT_NE(file, nullptr);
38 
39     auto output = helpers::ExecuteDynamicAbc(INPUT_PATH, entryPoint);
40     EXPECT_TRUE(helpers::Match(output,
41                                "str1\n"
42                                "str2\n"
43                                "str3\n"
44                                "undefined\n"
45                                "str3\n"
46                                "str2\n"
47                                "str4\n"
48                                "undefined\n"));
49 
50     const MethodInfo method = {"modules/base", "Handler", "handle"};
51 
52     ApiModifier modifier(VERSION, file, impl, method);
53 
54     modifier.Run();
55 
56     AbckitFile *modCtxI = modifier.GetFile();
57     ASSERT_NE(modCtxI, nullptr);
58     impl->writeAbc(modCtxI, OUTPUT_PATH, strlen(OUTPUT_PATH));
59     impl->closeFile(file);
60 
61     output = helpers::ExecuteDynamicAbc(OUTPUT_PATH, entryPoint);
62     EXPECT_TRUE(helpers::Match(output,
63                                "str1\n"
64                                "str2\n"
65                                "str3\n"
66                                "-1\n"
67                                "str3\n"
68                                "str2\n"
69                                "str4\n"
70                                "-1\n"));
71 }
72 
73 }  // namespace libabckit::test
74