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 "mock/abckit_mock.h"
17 #include "mock/mock_values.h"
18
19 #include "include/c/statuses.h"
20 #include "include/c/abckit.h"
21
22 #include <gtest/gtest.h>
23
24 namespace libabckit::mock::abckit_api {
25
26 // NOLINTBEGIN(readability-identifier-naming)
27
GetLastError()28 AbckitStatus GetLastError()
29 {
30 return ABCKIT_STATUS_NO_ERROR;
31 }
32
OpenAbc(const char * path,size_t len)33 AbckitFile *OpenAbc(const char *path, size_t len)
34 {
35 g_calledFuncs.push(__func__);
36 EXPECT_TRUE(strncmp(path, DEFAULT_PATH, DEFAULT_PATH_SIZE) == 0);
37 EXPECT_TRUE(len + 1 == DEFAULT_PATH_SIZE);
38 return DEFAULT_FILE;
39 }
40
WriteAbc(AbckitFile * file,const char * path,size_t len)41 void WriteAbc(AbckitFile *file, const char *path, size_t len)
42 {
43 g_calledFuncs.push(__func__);
44 EXPECT_TRUE(strncmp(path, DEFAULT_PATH, DEFAULT_PATH_SIZE) == 0);
45 EXPECT_TRUE(len + 1 == DEFAULT_PATH_SIZE);
46 EXPECT_TRUE(file == DEFAULT_FILE);
47 }
48
CloseFile(AbckitFile * file)49 void CloseFile(AbckitFile *file)
50 {
51 g_calledFuncs.push(__func__);
52 EXPECT_TRUE(file == DEFAULT_FILE);
53 }
54
DestroyGraph(AbckitGraph * graph)55 void DestroyGraph(AbckitGraph *graph)
56 {
57 g_calledFuncs.push(__func__);
58 EXPECT_TRUE(graph == DEFAULT_GRAPH);
59 }
60
61 // NOLINTEND(readability-identifier-naming)
62
63 static AbckitApi g_impl = {
64 // ========================================
65 // Common API
66 // ========================================
67
68 ABCKIT_VERSION_RELEASE_1_0_0,
69 GetLastError,
70
71 // ========================================
72 // Inspection API entrypoints
73 // ========================================
74
75 OpenAbc,
76 WriteAbc,
77 CloseFile,
78
79 // ========================================
80 // IR API entrypoints
81 // ========================================
82
83 DestroyGraph,
84 };
85
86 // NOLINTEND(readability-identifier-naming)
87
88 } // namespace libabckit::mock::abckit_api
89
AbckitGetMockApiImpl(AbckitApiVersion version)90 AbckitApi const *AbckitGetMockApiImpl([[maybe_unused]] AbckitApiVersion version)
91 {
92 return &libabckit::mock::abckit_api::g_impl;
93 }
94