• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 #include "abc2program_driver.h"
22 #include "abc2program_test_utils.h"
23 #include "common/abc_file_utils.h"
24 #include "dump_utils.h"
25 #include "modifiers.h"
26 
27 using namespace testing::ext;
28 
29 namespace panda::abc2program {
30 const std::string ETSIMPLEMENTS_ABC_TEST_FILE_NAME = GRAPH_TEST_ABC_DIR "etsImplements.abc";
31 const std::string ETS_IMPLEMENTS_MESSAGE =
32     "L<packagename>/src/main/ets/<filepath>/I1;,L<packagename>/src/main/ets/<filepath>/I2;";
33 constexpr uint8_t SIZE_OF_LITERAL_ARRAY_TABLE = 3;
34 constexpr uint8_t TOTAL_NUM_OF_ETSIMPLEMENTS_LITERALS = 10;
35 
36 class Abc2ProgramEtsImplementsTest : public testing::Test {
37 public:
SetUpTestCase(void)38     static void SetUpTestCase(void) {}
TearDownTestCase(void)39     static void TearDownTestCase(void) {}
SetUp()40     void SetUp()
41     {
42         (void)driver_.Compile(ETSIMPLEMENTS_ABC_TEST_FILE_NAME);
43         prog_ = &(driver_.GetProgram());
44     }
45 
TearDown()46     void TearDown() {}
47 
48     Abc2ProgramDriver driver_;
49     const pandasm::Program *prog_ = nullptr;
50 };
51 
52 /**
53  * @tc.name: abc2program_ets_implements_test_literal_array
54  * @tc.desc: get and check the ets implements in literal array
55  * @tc.type: FUNC
56  * @tc.require: IC9M4H
57  */
58 HWTEST_F(Abc2ProgramEtsImplementsTest, abc2program_ets_implements_test_literal_array, TestSize.Level1)
59 {
60     auto &literal_array_table = prog_->literalarray_table;
61     EXPECT_EQ(literal_array_table.size(), SIZE_OF_LITERAL_ARRAY_TABLE);
62     panda::pandasm::LiteralArray ets_implements_literal_array;
63 
64     for (auto &item : literal_array_table) {
65         for (auto &literal : item.second.literals_) {
66             if (literal.tag_ == panda_file::LiteralTag::ETS_IMPLEMENTS) {
67                 ets_implements_literal_array = item.second;
68                 break;
69             }
70         }
71         if (ets_implements_literal_array.literals_.size() != 0) {
72             break;
73         }
74     }
75 
76     EXPECT_EQ(ets_implements_literal_array.literals_.size(), TOTAL_NUM_OF_ETSIMPLEMENTS_LITERALS);
77     auto it = ets_implements_literal_array.literals_.begin();
78     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
79     ++it;
80     EXPECT_EQ(it->tag_, panda_file::LiteralTag::STRING);
81     ++it;
82     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
83     ++it;
84     EXPECT_EQ(it->tag_, panda_file::LiteralTag::METHOD);
85     ++it;
86     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
87     ++it;
88     EXPECT_EQ(it->tag_, panda_file::LiteralTag::METHODAFFILIATE);
89     ++it;
90     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
91     ++it;
92     EXPECT_EQ(it->tag_, panda_file::LiteralTag::INTEGER);
93     ++it;
94     EXPECT_EQ(it->tag_, panda_file::LiteralTag::TAGVALUE);
95     ++it;
96     EXPECT_EQ(it->tag_, panda_file::LiteralTag::ETS_IMPLEMENTS);
97     EXPECT_EQ(std::get<std::string>(it->value_), ETS_IMPLEMENTS_MESSAGE);
98 }
99 }; // panda::abc2program
100