xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/tools/generator2/code_test_util.py (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2019 Google LLC
2#
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#     https://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"""Contains golden outputs for tests."""
16
17
18CODE_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
19// Edits will be discarded when regenerating this file.
20
21#include "absl/status/status.h"
22#include "absl/status/statusor.h"
23#include "sandboxed_api/sandbox.h"
24#include "sandboxed_api/util/status_macros.h"
25#include "sandboxed_api/vars.h"
26
27namespace sapi {
28namespace Tests {
29
30class TestApi {
31 public:
32  explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
33  // Deprecated
34  ::sapi::Sandbox* GetSandbox() const { return sandbox(); }
35  ::sapi::Sandbox* sandbox() const { return sandbox_; }
36
37  // int function_a(int, int)
38  absl::StatusOr<int> function_a(int x, int y) {
39    ::sapi::v::Int ret;
40    ::sapi::v::Int x_((x));
41    ::sapi::v::Int y_((y));
42
43    SAPI_RETURN_IF_ERROR(sandbox_->Call("function_a", &ret, &x_, &y_));
44    return ret.GetValue();
45  }
46
47  // int types_1(bool, unsigned char, char, unsigned short, short)
48  absl::StatusOr<int> types_1(bool a0, unsigned char a1, char a2, unsigned short a3, short a4) {
49    ::sapi::v::Int ret;
50    ::sapi::v::Bool a0_((a0));
51    ::sapi::v::UChar a1_((a1));
52    ::sapi::v::Char a2_((a2));
53    ::sapi::v::UShort a3_((a3));
54    ::sapi::v::Short a4_((a4));
55
56    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_1", &ret, &a0_, &a1_, &a2_, &a3_, &a4_));
57    return ret.GetValue();
58  }
59
60  // int types_2(int, unsigned int, long, unsigned long)
61  absl::StatusOr<int> types_2(int a0, unsigned int a1, long a2, unsigned long a3) {
62    ::sapi::v::Int ret;
63    ::sapi::v::Int a0_((a0));
64    ::sapi::v::UInt a1_((a1));
65    ::sapi::v::Long a2_((a2));
66    ::sapi::v::ULong a3_((a3));
67
68    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_2", &ret, &a0_, &a1_, &a2_, &a3_));
69    return ret.GetValue();
70  }
71
72  // int types_3(long long, unsigned long long, float, double)
73  absl::StatusOr<int> types_3(long long a0, unsigned long long a1, float a2, double a3) {
74    ::sapi::v::Int ret;
75    ::sapi::v::LLong a0_((a0));
76    ::sapi::v::ULLong a1_((a1));
77    ::sapi::v::Reg<float> a2_((a2));
78    ::sapi::v::Reg<double> a3_((a3));
79
80    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_3", &ret, &a0_, &a1_, &a2_, &a3_));
81    return ret.GetValue();
82  }
83
84  // int types_4(signed char, short, int, long)
85  absl::StatusOr<int> types_4(signed char a0, short a1, int a2, long a3) {
86    ::sapi::v::Int ret;
87    ::sapi::v::SChar a0_((a0));
88    ::sapi::v::Short a1_((a1));
89    ::sapi::v::Int a2_((a2));
90    ::sapi::v::Long a3_((a3));
91
92    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_4", &ret, &a0_, &a1_, &a2_, &a3_));
93    return ret.GetValue();
94  }
95
96  // int types_5(long long, long double)
97  absl::StatusOr<int> types_5(long long a0, long double a1) {
98    ::sapi::v::Int ret;
99    ::sapi::v::LLong a0_((a0));
100    ::sapi::v::Reg<long double> a1_((a1));
101
102    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_5", &ret, &a0_, &a1_));
103    return ret.GetValue();
104  }
105
106  // void types_6(char *)
107  absl::Status types_6(::sapi::v::Ptr* a0) {
108    ::sapi::v::Void ret;
109
110    SAPI_RETURN_IF_ERROR(sandbox_->Call("types_6", &ret, a0));
111    return absl::OkStatus();
112  }
113
114 private:
115  ::sapi::Sandbox* sandbox_;
116};
117
118}  // namespace Tests
119}  // namespace sapi
120"""
121
122CODE_GOLD_MAPPED = """// AUTO-GENERATED by the Sandboxed API generator.
123// Edits will be discarded when regenerating this file.
124
125#include "absl/status/status.h"
126#include "absl/status/statusor.h"
127#include "sandboxed_api/sandbox.h"
128#include "sandboxed_api/util/status_macros.h"
129#include "sandboxed_api/vars.h"
130
131namespace sapi {
132namespace Tests {
133
134typedef unsigned int uint;
135typedef uint * uintp;
136
137class TestApi {
138 public:
139  explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
140  // Deprecated
141  ::sapi::Sandbox* GetSandbox() const { return sandbox(); }
142  ::sapi::Sandbox* sandbox() const { return sandbox_; }
143
144  // uint function(uintp)
145  absl::StatusOr<uint> function(::sapi::v::Ptr* a) {
146    ::sapi::v::UInt ret;
147
148    SAPI_RETURN_IF_ERROR(sandbox_->Call("function", &ret, a));
149    return ret.GetValue();
150  }
151
152 private:
153  ::sapi::Sandbox* sandbox_;
154};
155
156}  // namespace Tests
157}  // namespace sapi
158"""
159
160CODE_ENUM_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
161// Edits will be discarded when regenerating this file.
162
163#include "absl/status/status.h"
164#include "absl/status/statusor.h"
165#include "sandboxed_api/sandbox.h"
166#include "sandboxed_api/util/status_macros.h"
167#include "sandboxed_api/vars.h"
168
169namespace sapi {
170namespace Tests {
171
172enum ProcessStatus {
173\tOK = 0 ,
174\tERROR = 1 ,
175};
176
177class TestApi {
178 public:
179  explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
180  // Deprecated
181  ::sapi::Sandbox* GetSandbox() const { return sandbox(); }
182  ::sapi::Sandbox* sandbox() const { return sandbox_; }
183
184  // ProcessStatus ProcessDatapoint(ProcessStatus)
185  absl::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
186    ::sapi::v::IntBase<ProcessStatus> ret;
187    ::sapi::v::IntBase<ProcessStatus> status_((status));
188
189    SAPI_RETURN_IF_ERROR(sandbox_->Call("ProcessDatapoint", &ret, &status_));
190    return static_cast<ProcessStatus>(ret.GetValue());
191  }
192
193 private:
194  ::sapi::Sandbox* sandbox_;
195};
196
197}  // namespace Tests
198}  // namespace sapi
199"""
200