• 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 "../check_mock.h"
17 #include "../../../src/mock/mock_values.h"
18 #include "../cpp_helpers_mock.h"
19 
20 #include <gtest/gtest.h>
21 
22 namespace libabckit::test {
23 
24 class LibAbcKitCppMockTestInstruction : public ::testing::Test {};
25 
26 // Test: test-kind=mock, api=Instruction::GetImmediateSize, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetImmediateSize)27 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetImmediateSize)
28 {
29     ASSERT_TRUE(CheckMockedStackEmpty());
30     {
31         abckit::File f(DEFAULT_PATH);
32         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
33         abckit::mock::helpers::GetMockInstruction(f).GetImmediateSize(DEFAULT_SIZE_T);
34         ASSERT_TRUE(CheckMockedApi("IgetImmediateSize"));
35     }
36     ASSERT_TRUE(CheckMockedApi("CloseFile"));
37     ASSERT_TRUE(CheckMockedStackEmpty());
38 }
39 
40 // Test: test-kind=mock, api=Instruction::InsertAfter, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_InsertAfter)41 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_InsertAfter)
42 {
43     ASSERT_TRUE(CheckMockedStackEmpty());
44     {
45         abckit::File f(DEFAULT_PATH);
46         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
47         abckit::mock::helpers::GetMockInstruction(f).InsertAfter(abckit::mock::helpers::GetMockInstruction(f));
48         ASSERT_TRUE(CheckMockedApi("IinsertAfter"));
49     }
50     ASSERT_TRUE(CheckMockedApi("CloseFile"));
51     ASSERT_TRUE(CheckMockedStackEmpty());
52 }
53 
54 // Test: test-kind=mock, api=Instruction::InsertBefore, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_InsertBefore)55 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_InsertBefore)
56 {
57     ASSERT_TRUE(CheckMockedStackEmpty());
58     {
59         abckit::File f(DEFAULT_PATH);
60         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
61         abckit::mock::helpers::GetMockInstruction(f).InsertBefore(abckit::mock::helpers::GetMockInstruction(f));
62         ASSERT_TRUE(CheckMockedApi("IinsertBefore"));
63     }
64     ASSERT_TRUE(CheckMockedApi("CloseFile"));
65     ASSERT_TRUE(CheckMockedStackEmpty());
66 }
67 
68 // Test: test-kind=mock, api=Instruction::Remove, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_Remove)69 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_Remove)
70 {
71     ASSERT_TRUE(CheckMockedStackEmpty());
72     {
73         abckit::File f(DEFAULT_PATH);
74         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
75         abckit::mock::helpers::GetMockInstruction(f).Remove();
76         ASSERT_TRUE(CheckMockedApi("Iremove"));
77     }
78     ASSERT_TRUE(CheckMockedApi("CloseFile"));
79     ASSERT_TRUE(CheckMockedStackEmpty());
80 }
81 
82 // Test: test-kind=mock, api=Instruction::GetConstantValueI64, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetConstantValueI64)83 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetConstantValueI64)
84 {
85     ASSERT_TRUE(CheckMockedStackEmpty());
86     {
87         abckit::File f(DEFAULT_PATH);
88         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
89         abckit::mock::helpers::GetMockInstruction(f).GetConstantValueI64();
90         ASSERT_TRUE(CheckMockedApi("IgetConstantValueI64"));
91     }
92     ASSERT_TRUE(CheckMockedApi("CloseFile"));
93     ASSERT_TRUE(CheckMockedStackEmpty());
94 }
95 
96 // Test: test-kind=mock, api=Instruction::GetString, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetString)97 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetString)
98 {
99     ASSERT_TRUE(CheckMockedStackEmpty());
100     {
101         abckit::File f(DEFAULT_PATH);
102         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
103         abckit::mock::helpers::GetMockInstruction(f).GetString();
104         ASSERT_TRUE(CheckMockedApi("AbckitStringToString"));
105         ASSERT_TRUE(CheckMockedApi("IgetString"));
106     }
107     ASSERT_TRUE(CheckMockedApi("CloseFile"));
108     ASSERT_TRUE(CheckMockedStackEmpty());
109 }
110 
111 // Test: test-kind=mock, api=Instruction::GetNext, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetNext)112 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetNext)
113 {
114     ASSERT_TRUE(CheckMockedStackEmpty());
115     {
116         abckit::File f(DEFAULT_PATH);
117         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
118         abckit::mock::helpers::GetMockInstruction(f).GetNext();
119         ASSERT_TRUE(CheckMockedApi("IgetNext"));
120     }
121     ASSERT_TRUE(CheckMockedApi("CloseFile"));
122     ASSERT_TRUE(CheckMockedStackEmpty());
123 }
124 
125 // Test: test-kind=mock, api=Instruction::GetPrev, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetPrev)126 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetPrev)
127 {
128     ASSERT_TRUE(CheckMockedStackEmpty());
129     {
130         abckit::File f(DEFAULT_PATH);
131         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
132         abckit::mock::helpers::GetMockInstruction(f).GetPrev();
133         ASSERT_TRUE(CheckMockedApi("IgetPrev"));
134     }
135     ASSERT_TRUE(CheckMockedApi("CloseFile"));
136     ASSERT_TRUE(CheckMockedStackEmpty());
137 }
138 
139 // Test: test-kind=mock, api=Instruction::GetFunction, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetFunction)140 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetFunction)
141 {
142     ASSERT_TRUE(CheckMockedStackEmpty());
143     {
144         abckit::File f(DEFAULT_PATH);
145         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
146         abckit::mock::helpers::GetMockInstruction(f).GetFunction();
147         ASSERT_TRUE(CheckMockedApi("IgetFunction"));
148     }
149     ASSERT_TRUE(CheckMockedApi("CloseFile"));
150     ASSERT_TRUE(CheckMockedStackEmpty());
151 }
152 
153 // Test: test-kind=mock, api=Instruction::GetBasicBlock, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetBasicBlock)154 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetBasicBlock)
155 {
156     ASSERT_TRUE(CheckMockedStackEmpty());
157     {
158         abckit::File f(DEFAULT_PATH);
159         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
160         abckit::mock::helpers::GetMockInstruction(f).GetBasicBlock();
161         ASSERT_TRUE(CheckMockedApi("IgetBasicBlock"));
162     }
163     ASSERT_TRUE(CheckMockedApi("CloseFile"));
164     ASSERT_TRUE(CheckMockedStackEmpty());
165 }
166 
167 // Test: test-kind=mock, api=Instruction::GetInputCount, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetInputCount)168 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetInputCount)
169 {
170     ASSERT_TRUE(CheckMockedStackEmpty());
171     {
172         abckit::File f(DEFAULT_PATH);
173         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
174         abckit::mock::helpers::GetMockInstruction(f).GetInputCount();
175         ASSERT_TRUE(CheckMockedApi("IgetInputCount"));
176     }
177     ASSERT_TRUE(CheckMockedApi("CloseFile"));
178     ASSERT_TRUE(CheckMockedStackEmpty());
179 }
180 
181 // Test: test-kind=mock, api=Instruction::GetInput, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetInput)182 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetInput)
183 {
184     ASSERT_TRUE(CheckMockedStackEmpty());
185     {
186         abckit::File f(DEFAULT_PATH);
187         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
188         abckit::mock::helpers::GetMockInstruction(f).GetInput(DEFAULT_U32);
189         ASSERT_TRUE(CheckMockedApi("IgetInput"));
190     }
191     ASSERT_TRUE(CheckMockedApi("CloseFile"));
192     ASSERT_TRUE(CheckMockedStackEmpty());
193 }
194 
195 // Test: test-kind=mock, api=Instruction::SetInput, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_SetInput)196 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_SetInput)
197 {
198     ASSERT_TRUE(CheckMockedStackEmpty());
199     {
200         abckit::File f(DEFAULT_PATH);
201         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
202         abckit::mock::helpers::GetMockInstruction(f).SetInput(DEFAULT_U32,
203                                                               abckit::mock::helpers::GetMockInstruction(f));
204         ASSERT_TRUE(CheckMockedApi("IsetInput"));
205     }
206     ASSERT_TRUE(CheckMockedApi("CloseFile"));
207     ASSERT_TRUE(CheckMockedStackEmpty());
208 }
209 
210 // Test: test-kind=mock, api=Instruction::SetInputs, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_SetInputs)211 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_SetInputs)
212 {
213     ASSERT_TRUE(CheckMockedStackEmpty());
214     {
215         abckit::File f(DEFAULT_PATH);
216         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
217         abckit::mock::helpers::GetMockInstruction(f).SetInputs(abckit::mock::helpers::GetMockInstruction(f),
218                                                                abckit::mock::helpers::GetMockInstruction(f));
219         ASSERT_TRUE(CheckMockedApi("IsetInputs"));
220     }
221     ASSERT_TRUE(CheckMockedApi("CloseFile"));
222     ASSERT_TRUE(CheckMockedStackEmpty());
223 }
224 
225 // Test: test-kind=mock, api=Instruction::VisitUsers, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_VisitUsers)226 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_VisitUsers)
227 {
228     ASSERT_TRUE(CheckMockedStackEmpty());
229     {
230         abckit::File f(DEFAULT_PATH);
231         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
232         abckit::mock::helpers::GetMockInstruction(f).VisitUsers(
233             []([[maybe_unused]] const abckit::Instruction &inst) { return false; });
234         ASSERT_TRUE(CheckMockedApi("IvisitUsers"));
235     }
236     ASSERT_TRUE(CheckMockedApi("CloseFile"));
237     ASSERT_TRUE(CheckMockedStackEmpty());
238 }
239 
240 // Test: test-kind=mock, api=Instruction::GetUserCount, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetUserCount)241 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetUserCount)
242 {
243     ASSERT_TRUE(CheckMockedStackEmpty());
244     {
245         abckit::File f(DEFAULT_PATH);
246         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
247         abckit::mock::helpers::GetMockInstruction(f).GetUserCount();
248         ASSERT_TRUE(CheckMockedApi("IgetUserCount"));
249     }
250     ASSERT_TRUE(CheckMockedApi("CloseFile"));
251     ASSERT_TRUE(CheckMockedStackEmpty());
252 }
253 
254 // Test: test-kind=mock, api=Instruction::GetLiteralArray, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetLiteralArray)255 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetLiteralArray)
256 {
257     ASSERT_TRUE(CheckMockedStackEmpty());
258     {
259         abckit::File f(DEFAULT_PATH);
260         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
261         abckit::mock::helpers::GetMockInstruction(f).GetLiteralArray();
262         ASSERT_TRUE(CheckMockedApi("IgetLiteralArray"));
263     }
264     ASSERT_TRUE(CheckMockedApi("CloseFile"));
265     ASSERT_TRUE(CheckMockedStackEmpty());
266 }
267 
268 // Test: test-kind=mock, api=Instruction::GetGraph, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetGraph)269 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetGraph)
270 {
271     ASSERT_TRUE(CheckMockedStackEmpty());
272     {
273         abckit::File f(DEFAULT_PATH);
274         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
275         abckit::mock::helpers::GetMockInstruction(f).GetGraph();
276     }
277     ASSERT_TRUE(CheckMockedApi("CloseFile"));
278     ASSERT_TRUE(CheckMockedStackEmpty());
279 }
280 
281 // Test: test-kind=mock, api=Instruction::GetType, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockTestInstruction,Instruction_GetType)282 TEST_F(LibAbcKitCppMockTestInstruction, Instruction_GetType)
283 {
284     ASSERT_TRUE(CheckMockedStackEmpty());
285     {
286         abckit::File f(DEFAULT_PATH);
287         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
288         abckit::mock::helpers::GetMockInstruction(f).GetType();
289         ASSERT_TRUE(CheckMockedApi("IgetType"));
290     }
291     ASSERT_TRUE(CheckMockedApi("CloseFile"));
292     ASSERT_TRUE(CheckMockedStackEmpty());
293 }
294 
295 }  // namespace libabckit::test
296