1
2 #include <android/hardware/tests/bar/1.0/IImportRules.h>
3 #include <android/hardware/tests/expression/1.0/IExpression.h>
4 #include <android/hardware/tests/foo/1.0/IFoo.h>
5
6 using ::android::hardware::Return;
7 using ::android::hardware::Void;
8 using ::android::hardware::hidl_array;
9 using ::android::hardware::tests::bar::V1_0::IImportRules;
10 using ::android::hardware::tests::expression::V1_0::IExpression;
11 using ::android::hardware::tests::foo::V1_0::IFoo;
12 using ::android::sp;
13
14 namespace {
15
16 // Check array dimension order
17 static_assert(std::is_same<IFoo::multidimArrayOne, hidl_array<int32_t, 5, 6, 7>>::value,
18 "hidl-gen output array dimention order is incorrect");
19 static_assert(std::is_same<IFoo::multidimArrayTwo, hidl_array<int32_t, 8, 9, 10, 5, 6, 7>>::value,
20 "hidl-gen output array dimention order is incorrect");
21 static_assert(
22 std::is_same<IFoo::multidimArrayThree, hidl_array<int32_t, 2, 3, 4, 8, 9, 10, 5, 6, 7>>::value,
23 "hidl-gen output array dimention order is incorrect");
24
25 // Check correct type in ambiguous case
26 static_assert(std::is_same<decltype(IFoo::S1::foo), IFoo::InnerTestStruct>::value,
27 "hidl-gen wrong (inner) type in output");
28 static_assert(!std::is_same<decltype(IFoo::S1::foo), IFoo::S1::InnerTestStruct>::value,
29 "hidl-gen wrong (inner) type in output");
30 static_assert((int32_t) decltype(IFoo::S2::foo)::VALUE == 0,
31 "hidl-gen wrong (inner) type in output");
32
33 // Ensure (statically) that the types in IImportRules resolves to the correct types by
34 // overriding the methods with fully namespaced types as arguments.
35 struct MyImportRules : public IImportRules {
rule0a__anon4b7d01e00111::MyImportRules36 Return<void> rule0a(
37 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override {
38 return Void();
39 }
40
rule0a1__anon4b7d01e00111::MyImportRules41 Return<void> rule0a1(
42 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override {
43 return Void();
44 }
45
rule0b__anon4b7d01e00111::MyImportRules46 Return<void> rule0b(
47 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override {
48 return Void();
49 }
50
rule0b1__anon4b7d01e00111::MyImportRules51 Return<void> rule0b1(
52 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override {
53 return Void();
54 }
55
rule0c__anon4b7d01e00111::MyImportRules56 Return<void> rule0c(const ::android::hardware::tests::foo::V1_0::Outer&) override {
57 return Void();
58 }
59
rule0d__anon4b7d01e00111::MyImportRules60 Return<void> rule0d(const ::android::hardware::tests::foo::V1_0::Outer&) override {
61 return Void();
62 }
63
rule0e__anon4b7d01e00111::MyImportRules64 Return<void> rule0e(
65 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer::Inner&) override {
66 return Void();
67 }
68
rule0f__anon4b7d01e00111::MyImportRules69 Return<void> rule0f(
70 const ::android::hardware::tests::bar::V1_0::IImportRules::Outer::Inner&) override {
71 return Void();
72 }
73
rule0g__anon4b7d01e00111::MyImportRules74 Return<void> rule0g(const ::android::hardware::tests::foo::V1_0::Outer::Inner&) override {
75 return Void();
76 }
77
rule0h__anon4b7d01e00111::MyImportRules78 Return<void> rule0h(const ::android::hardware::tests::foo::V1_0::Outer::Inner&) override {
79 return Void();
80 }
81
rule1a__anon4b7d01e00111::MyImportRules82 Return<void> rule1a(const ::android::hardware::tests::bar::V1_0::Def&) override {
83 return Void();
84 }
85
rule1b__anon4b7d01e00111::MyImportRules86 Return<void> rule1b(const ::android::hardware::tests::foo::V1_0::Def&) override {
87 return Void();
88 }
89
rule2a__anon4b7d01e00111::MyImportRules90 Return<void> rule2a(const ::android::hardware::tests::foo::V1_0::Unrelated&) override {
91 return Void();
92 }
93
rule2b__anon4b7d01e00111::MyImportRules94 Return<void> rule2b(const sp<::android::hardware::tests::foo::V1_0::IFooCallback>&) override {
95 return Void();
96 }
97 };
98
99 template <typename E>
operator ==(E actual,typename std::underlying_type<E>::type expected)100 constexpr bool operator==(E actual, typename std::underlying_type<E>::type expected) {
101 return expected == static_cast<typename std::underlying_type<E>::type>(actual);
102 }
103
104 // See IExpression.hal
105 // Use the C++ compiler to compute these expressions and make sure hidl-gen emits the same result.
106 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec1 == 0, "");
107 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec2 == 1, "");
108 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec3 == -1, "");
109 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec4 == ~0, "");
110 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec5 == 2147483647, "");
111 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec6 == -2147483648, "");
112 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec7 == 2147483648, "");
113 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec8 == -2147483649, "");
114 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixDec9 == ~(-1), "");
115 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixHex1 == 0x7fffffff, "");
116 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixHex2 == 0x80000000, "");
117 static_assert(IExpression::UInt64LiteralTypeGuessing::noSuffixHex3 == 0xffffffff, "");
118 static_assert(IExpression::UInt64LiteralTypeGuessing::longHex1 == 0xffffffffL, "");
119 static_assert(IExpression::UInt64LiteralTypeGuessing::longHex2 == 0Xfffffffff, "");
120 static_assert(IExpression::UInt64LiteralTypeGuessing::longHex3 == 0x7fffffffffffffff, "");
121 static_assert(IExpression::UInt64LiteralTypeGuessing::longHex4 == 0x8000000000000000, "");
122 static_assert(IExpression::UInt64LiteralTypeGuessing::longHex5 == 0xFFFFFFFFFFFFFFFF, "");
123
124 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt32_1 == 1, "");
125 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt32_2 == 1, "");
126 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt64_1 == 1, "");
127 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt64_2 == 1, "");
128 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt64_3 == 1, "");
129 static_assert(IExpression::SuffixedLiteralTypeGuessing::decInt64_4 == 1, "");
130 static_assert(IExpression::SuffixedLiteralTypeGuessing::hexInt32_1 == 1, "");
131 static_assert(IExpression::SuffixedLiteralTypeGuessing::hexUInt32_1 == 1, "");
132 static_assert(IExpression::SuffixedLiteralTypeGuessing::hexUInt32_2 == 1, "");
133 static_assert(IExpression::SuffixedLiteralTypeGuessing::hexInt64_1 == 1, "");
134 static_assert(IExpression::SuffixedLiteralTypeGuessing::hexUInt64_1 == 1, "");
135
136 static_assert(IExpression::Int64LiteralTypeGuessing::noSuffixDec11 == -2147483648,
137 "1 + 0x7fffffff");
138 static_assert(IExpression::Int64LiteralTypeGuessing::noSuffixDec12 == 2147483647, "0x80000000 - 1");
139
140 static_assert(IExpression::Int32BitShifting::int32BitShift1 == 1 << 31, "");
141 static_assert(IExpression::UInt32BitShifting::uint32BitShift1 == 1 << 31, "");
142 static_assert(IExpression::Int64BitShifting::int64BitShift1 == 1LL << 63, "1l << 63");
143 static_assert(IExpression::UInt64BitShifting::uint64BitShift1 == 1LL << 63, "1l << 63");
144
145 #pragma clang diagnostic push
146 #pragma clang diagnostic ignored "-Wconstant-logical-operand"
147 #pragma clang diagnostic ignored "-Wlogical-op-parentheses"
148 #pragma clang diagnostic ignored "-Wbitwise-op-parentheses"
149
150 static_assert(IExpression::Precedence::literal == (4), "");
151 static_assert(IExpression::Precedence::neg == (-4), "");
152 static_assert(IExpression::Precedence::literalL == (-4L), "");
153 static_assert(IExpression::Precedence::hex == (0xffffffff), "");
154 static_assert(IExpression::Precedence::hexLong == (0xffffffffL), "");
155 static_assert(IExpression::Precedence::hexLong2 == (0xfffffffff), "");
156 static_assert(IExpression::Precedence::simpleArithmetic == (4 + 1), "");
157 static_assert(IExpression::Precedence::simpleArithmetic2 == (2 + 3 - 4), "");
158 static_assert(IExpression::Precedence::simpleArithmetic3 == (2 - 3 + 4), "");
159 static_assert(IExpression::Precedence::simpleBoolExpr == (1 == 4), "");
160 static_assert(IExpression::Precedence::simpleLogical == (1 && 1), "");
161 static_assert(IExpression::Precedence::simpleLogical2 == (1 || 1 && 0),
162 "&& higher than || in HIDL");
163 static_assert(IExpression::Precedence::simpleComp == (1 < 2), "");
164 static_assert(IExpression::Precedence::boolExpr1 == (!((3 != 4 || (2 < 3 <= 3 > 4)) >= 0)), "");
165 static_assert(IExpression::Precedence::boolExpr == (1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0)),
166 "");
167 static_assert(IExpression::Precedence::simpleBitShift == (1 << 2), "");
168 static_assert(IExpression::Precedence::simpleBitShift2 == (4 >> 1), "");
169 // Shifting negative number of bits is UB in HIDL, so the value is not tested.
170 // static_assert(IExpression::Precedence::simpleBitShiftNeg == (4 << -1), "");
171 static_assert(IExpression::Precedence::simpleArithmeticRightShift == (1 << 31 >> 31), "");
172 static_assert(IExpression::Precedence::simpleBitExpr == (1 | 16 >> 2), "");
173 static_assert(IExpression::Precedence::simpleBitExpr2 == (0x0f ^ 0x33 & 0x99),
174 "& higher than ^ in HIDL");
175 static_assert(IExpression::Precedence::bitExpr == (~42 & (1 << 3 | 16 >> 2) ^ 7),
176 "& higher than ^ in HIDL");
177 static_assert(IExpression::Precedence::arithmeticExpr == (2 + 3 - 4 * -7 / (10 % 3)), "");
178 static_assert(IExpression::Precedence::messyExpr == (2 + (-3 & 4 / 7)), "");
179 static_assert(IExpression::Precedence::paranExpr == ((((((1 + 1)))))), "");
180 static_assert(IExpression::Precedence::ternary == (1 ? 2 : 3), "");
181 static_assert(IExpression::Precedence::ternary2 == (1 && 2 ? 3 : 4), "");
182 static_assert(IExpression::Precedence::complicatedTernary2 == (1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3),
183 "&& higher than || in HIDL");
184
185 #pragma clang diagnostic pop
186
187 static_assert(IExpression::OperatorSanityCheck::plus == 1, "");
188 static_assert(IExpression::OperatorSanityCheck::minus == 1, "");
189 static_assert(IExpression::OperatorSanityCheck::product == 1, "");
190 static_assert(IExpression::OperatorSanityCheck::division == 1, "");
191 static_assert(IExpression::OperatorSanityCheck::mod == 1, "");
192 static_assert(IExpression::OperatorSanityCheck::bit_or == 1, "");
193 static_assert(IExpression::OperatorSanityCheck::bit_or2 == 1, "");
194 static_assert(IExpression::OperatorSanityCheck::bit_and == 1, "");
195 static_assert(IExpression::OperatorSanityCheck::bit_xor == 1, "");
196 static_assert(IExpression::OperatorSanityCheck::lt1 == 1, "");
197 static_assert(IExpression::OperatorSanityCheck::lt2 == 1, "");
198 static_assert(IExpression::OperatorSanityCheck::gt1 == 1, "");
199 static_assert(IExpression::OperatorSanityCheck::gt2 == 1, "");
200 static_assert(IExpression::OperatorSanityCheck::gte1 == 1, "");
201 static_assert(IExpression::OperatorSanityCheck::gte2 == 1, "");
202 static_assert(IExpression::OperatorSanityCheck::lte1 == 1, "");
203 static_assert(IExpression::OperatorSanityCheck::lte2 == 1, "");
204 static_assert(IExpression::OperatorSanityCheck::ne1 == 1, "");
205 static_assert(IExpression::OperatorSanityCheck::ne2 == 1, "");
206 static_assert(IExpression::OperatorSanityCheck::lshift == 1, "");
207 static_assert(IExpression::OperatorSanityCheck::rshift == 1, "");
208 static_assert(IExpression::OperatorSanityCheck::logor1 == 1, "");
209 static_assert(IExpression::OperatorSanityCheck::logor2 == 1, "");
210 static_assert(IExpression::OperatorSanityCheck::logor3 == 1, "");
211 static_assert(IExpression::OperatorSanityCheck::logor4 == 1, "");
212 static_assert(IExpression::OperatorSanityCheck::logand1 == 1, "");
213 static_assert(IExpression::OperatorSanityCheck::logand2 == 1, "");
214 static_assert(IExpression::OperatorSanityCheck::logand3 == 1, "");
215 static_assert(IExpression::OperatorSanityCheck::logand4 == 1, "");
216
217 static_assert(IExpression::Grayscale::WHITE == 126, "");
218 static_assert(IExpression::Grayscale::GRAY == 127, "");
219 static_assert(IExpression::Grayscale::DARK_GRAY == -128, "");
220 static_assert(IExpression::Grayscale::BLACK == -127, "");
221
222 static_assert(IExpression::Color::RED == -126, "");
223 static_assert(IExpression::Color::RUBY == 0, "");
224 static_assert(IExpression::Color::GREEN == 1, "");
225 static_assert(IExpression::Color::BLUE == 5, "");
226 static_assert(IExpression::Color::CYAN == 6, "");
227 static_assert(IExpression::Color::ORANGE == 7, "");
228 static_assert(IExpression::Color::ROSE == 126, "");
229
230 static_assert(std::is_same<std::underlying_type<IExpression::Foo1>::type,
231 std::underlying_type<IExpression::Foo2>::type>::value,
232 "");
233 static_assert(std::is_same<std::underlying_type<IExpression::Foo1>::type,
234 std::underlying_type<IExpression::Foo3>::type>::value,
235 "");
236 static_assert(std::is_same<std::underlying_type<IExpression::Foo1>::type,
237 std::underlying_type<IExpression::Foo4>::type>::value,
238 "");
239 static_assert(IExpression::Foo3::BAR1 == 0, "");
240 static_assert(IExpression::Foo3::BAR2 == 10, "");
241 static_assert(IExpression::Foo4::BAR3 == 11, "");
242 static_assert(IExpression::Foo4::BAR4 == 21, "");
243
244 static_assert(IExpression::Number::MAX == 255, "");
245 static_assert(IExpression::Number::MAX_PLUS_1 == 0, "");
246 static_assert(IExpression::Number::MAX_PLUS_2 == 1, "");
247
248 static_assert(IExpression::Constants::CONST_FOO == 0, "");
249 static_assert(IExpression::Constants::CONST_BAR == 70, "");
250 static_assert(IExpression::Constants::MAX_ARRAY_SIZE == 20, "");
251 static_assert(IExpression::Constants::MAX_ARRAY_SIZE2 == 21, "");
252 static_assert(IExpression::Constants::MAX_ARRAY_SIZE3 == 40, "");
253 static_assert(IExpression::Constants::MY_INT32_MAX_MINUS_1 == 0x7FFFFFFE, "");
254 static_assert(IExpression::Constants::MY_INT32_MAX == 0x7FFFFFFF, "");
255 static_assert(IExpression::Constants::MY_INT32_MIN == 0x80000000, "");
256 static_assert(IExpression::Constants::MY_INT32_MIN_PLUS_1 == 0x80000001, "");
257
258 // Ensure (statically) that the array sizes in function arguments are correct.
259 struct Expression : public IExpression {
foo1__anon4b7d01e00111::Expression260 Return<void> foo1(const hidl_array<int32_t, 1>&) override { return Void(); }
foo2__anon4b7d01e00111::Expression261 Return<void> foo2(const hidl_array<int32_t, 13>&) override { return Void(); }
foo3__anon4b7d01e00111::Expression262 Return<void> foo3(const hidl_array<int32_t, 20>&) override { return Void(); }
263 };
264
265 } // anonymous namespace
266