• 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 "api_scanner.h"
19 #include "helpers/helpers.h"
20 
21 namespace libabckit::test {
22 
23 class AbckitScenarioTest : public ::testing::Test {};
24 
25 // Test: test-kind=scenario, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(AbckitScenarioTest,LibAbcKitTestApiScannerDynamic)26 TEST_F(AbckitScenarioTest, LibAbcKitTestApiScannerDynamic)
27 {
28     const auto version = ABCKIT_VERSION_RELEASE_1_0_0;
29     auto *impl = AbckitGetApiImpl(version);
30     auto filePath = ABCKIT_ABC_DIR "scenarios/api_scanner/dynamic/api_scanner.abc";
31     AbckitFile *file = impl->openAbc(filePath, strlen(filePath));
32     std::vector<ApiInfo> apiList = {{"modules/apiNamespace", "ApiNamespace", "foo"},
33                                     {"modules/toplevelApi", "bar", ""},
34                                     {"@ohos.geolocation", "geolocation", "getCurrentLocation"}};
35     ApiScanner a(version, file, apiList);
36 
37     const auto &usages = a.GetApiUsages();
38     EXPECT_FALSE(usages.empty());
39 
40     auto usagesStr = a.ApiUsageMapGetString();
41     std::vector<UsageInfo> expectedUsages = {
42         {"api_scanner", "useAll", 0},
43         {"api_scanner", "useFoo", 0},
44         {"api_scanner", "Person.personUseAll", 0},
45         {"api_scanner", "Person.personUseFoo", 0},
46         {"modules/src2", "Animal.animalUseFoo", 0},
47         {"modules/src2", "Animal.animalUseAll", 0},
48         {"modules/src2", "src2UseAll", 0},
49         {"modules/src2", "src2UseFoo", 0},
50         {"api_scanner", "useAll", 1},
51         {"api_scanner", "useBar", 1},
52         {"api_scanner", "Person.personUseAll", 1},
53         {"api_scanner", "Person.personUseBar", 1},
54         {"api_scanner", "useAll", 2},
55         {"api_scanner", "useLocation", 2},
56         {"api_scanner", "Person.personUseLocation", 2},
57         {"modules/src3", "src3UseLocation", 2},
58         {"modules/src3", "Cat.catUseLocation", 2},
59     };
60     EXPECT_TRUE(a.IsUsagesEqual(expectedUsages));
61     LIBABCKIT_LOG_TEST(DEBUG) << "====================================\n";
62     LIBABCKIT_LOG_TEST(DEBUG) << usagesStr;
63 
64     impl->closeFile(file);
65 }
66 
67 }  // namespace libabckit::test
68