diff options
author | Steven Moreland | 2017-12-13 20:12:45 -0600 |
---|---|---|
committer | Steven Moreland | 2017-12-14 18:02:46 -0600 |
commit | 3bcfa475e29a169e888215d9b52cda50fa645ca5 (patch) | |
tree | 0239594578dbf2fab657ce632e958a0f80500251 /tests | |
parent | e514a4b8a8db6a447d94d509c264712885849582 (diff) | |
download | platform-hardware-interfaces-3bcfa475e29a169e888215d9b52cda50fa645ca5.tar.gz platform-hardware-interfaces-3bcfa475e29a169e888215d9b52cda50fa645ca5.tar.xz platform-hardware-interfaces-3bcfa475e29a169e888215d9b52cda50fa645ca5.zip |
Test for vec<union> vec<struct w/ union>.
Bug: 31973802
Test: hidl_test
Change-Id: I4367f1f525caa8d1edb95b7bfdac78f21b234576
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bar/1.0/default/Bar.cpp | 5 | ||||
-rw-r--r-- | tests/bar/1.0/default/Bar.h | 2 | ||||
-rw-r--r-- | tests/foo/1.0/IFoo.hal | 23 | ||||
-rw-r--r-- | tests/foo/1.0/default/Foo.cpp | 24 | ||||
-rw-r--r-- | tests/foo/1.0/default/Foo.h | 5 |
5 files changed, 59 insertions, 0 deletions
diff --git a/tests/bar/1.0/default/Bar.cpp b/tests/bar/1.0/default/Bar.cpp index 6a8a3603..46144281 100644 --- a/tests/bar/1.0/default/Bar.cpp +++ b/tests/bar/1.0/default/Bar.cpp | |||
@@ -19,6 +19,11 @@ Bar::Bar() { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. | 21 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. |
22 | Return<void> Bar::convertToBoolIfSmall(Discriminator d, const hidl_vec<Union>& u, | ||
23 | convertToBoolIfSmall_cb _hidl_cb) { | ||
24 | return mFoo->convertToBoolIfSmall(d, u, _hidl_cb); | ||
25 | } | ||
26 | |||
22 | Return<void> Bar::doThis(float param) { | 27 | Return<void> Bar::doThis(float param) { |
23 | return mFoo->doThis(param); | 28 | return mFoo->doThis(param); |
24 | } | 29 | } |
diff --git a/tests/bar/1.0/default/Bar.h b/tests/bar/1.0/default/Bar.h index b276823b..acb976f8 100644 --- a/tests/bar/1.0/default/Bar.h +++ b/tests/bar/1.0/default/Bar.h | |||
@@ -31,6 +31,8 @@ struct Bar : public IBar { | |||
31 | Bar(); | 31 | Bar(); |
32 | 32 | ||
33 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. | 33 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. |
34 | virtual Return<void> convertToBoolIfSmall(Discriminator d, const hidl_vec<Union>& u, | ||
35 | convertToBoolIfSmall_cb _hidl_cb) override; | ||
34 | virtual Return<void> doThis(float param) override; | 36 | virtual Return<void> doThis(float param) override; |
35 | virtual Return<int32_t> doThatAndReturnSomething(int64_t param) override; | 37 | virtual Return<int32_t> doThatAndReturnSomething(int64_t param) override; |
36 | virtual Return<double> doQuiteABit(int32_t a, int64_t b, float c, double d) override; | 38 | virtual Return<double> doQuiteABit(int32_t a, int64_t b, float c, double d) override; |
diff --git a/tests/foo/1.0/IFoo.hal b/tests/foo/1.0/IFoo.hal index c1ce7b09..4a930a28 100644 --- a/tests/foo/1.0/IFoo.hal +++ b/tests/foo/1.0/IFoo.hal | |||
@@ -122,6 +122,19 @@ interface IFoo { | |||
122 | bitfield<BitField> bf; | 122 | bitfield<BitField> bf; |
123 | }; | 123 | }; |
124 | 124 | ||
125 | enum Discriminator : uint8_t { | ||
126 | BOOL, | ||
127 | INT, | ||
128 | }; | ||
129 | union Union { | ||
130 | bool boolValue; | ||
131 | int64_t intValue; | ||
132 | }; | ||
133 | struct ContainsUnion { | ||
134 | Discriminator discriminator; | ||
135 | Union value; | ||
136 | }; | ||
137 | |||
125 | typedef int32_t[5][6][7] multidimArrayOne; | 138 | typedef int32_t[5][6][7] multidimArrayOne; |
126 | typedef multidimArrayOne[8][9][10] multidimArrayTwo; | 139 | typedef multidimArrayOne[8][9][10] multidimArrayTwo; |
127 | typedef multidimArrayTwo[2][3][4] multidimArrayThree; | 140 | typedef multidimArrayTwo[2][3][4] multidimArrayThree; |
@@ -144,6 +157,16 @@ interface IFoo { | |||
144 | InnerTestEnumTypedef foo; | 157 | InnerTestEnumTypedef foo; |
145 | }; | 158 | }; |
146 | 159 | ||
160 | /** | ||
161 | * If d is INT, converts all values to bools which are small enough (0 or 1). | ||
162 | * If d is BOOL, should leave all values as BOOLs. | ||
163 | * | ||
164 | * @param d discriminator for all values in u | ||
165 | * @param u values to be expanded | ||
166 | * @return c must have same length as u unless there is an error in which case it will be empty. | ||
167 | */ | ||
168 | convertToBoolIfSmall(Discriminator d, vec<Union> u) generates (vec<ContainsUnion> c); | ||
169 | |||
147 | doThis(float param); | 170 | doThis(float param); |
148 | doThatAndReturnSomething(int64_t param) generates (int32_t result); | 171 | doThatAndReturnSomething(int64_t param) generates (int32_t result); |
149 | doQuiteABit(int32_t a, int64_t b, float c, double d) generates (double something); | 172 | doQuiteABit(int32_t a, int64_t b, float c, double d) generates (double something); |
diff --git a/tests/foo/1.0/default/Foo.cpp b/tests/foo/1.0/default/Foo.cpp index a860ce77..a31ab9f0 100644 --- a/tests/foo/1.0/default/Foo.cpp +++ b/tests/foo/1.0/default/Foo.cpp | |||
@@ -15,6 +15,30 @@ namespace V1_0 { | |||
15 | namespace implementation { | 15 | namespace implementation { |
16 | 16 | ||
17 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. | 17 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. |
18 | Return<void> Foo::convertToBoolIfSmall(Discriminator d, const hidl_vec<Union>& u, | ||
19 | convertToBoolIfSmall_cb _hidl_cb) { | ||
20 | hidl_vec<ContainsUnion> res(u.size()); | ||
21 | for (size_t i = 0; i < u.size(); i++) { | ||
22 | ContainsUnion& outValue = res[i]; | ||
23 | |||
24 | if (d == Discriminator::BOOL) { | ||
25 | outValue.discriminator = Discriminator::BOOL; | ||
26 | outValue.value.boolValue = u[i].boolValue; | ||
27 | } else { | ||
28 | uint64_t value = u[i].intValue; | ||
29 | if (value == 0 || value == 1) { | ||
30 | outValue.discriminator = Discriminator::BOOL; | ||
31 | outValue.value.boolValue = static_cast<bool>(value); | ||
32 | } else { | ||
33 | outValue.discriminator = Discriminator::INT; | ||
34 | outValue.value.intValue = value; | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | _hidl_cb(res); | ||
39 | return Void(); | ||
40 | } | ||
41 | |||
18 | Return<void> Foo::doThis(float param) { | 42 | Return<void> Foo::doThis(float param) { |
19 | LOG(INFO) << "SERVER(Foo) doThis(" << param << ")"; | 43 | LOG(INFO) << "SERVER(Foo) doThis(" << param << ")"; |
20 | 44 | ||
diff --git a/tests/foo/1.0/default/Foo.h b/tests/foo/1.0/default/Foo.h index 4558a734..7dd672b8 100644 --- a/tests/foo/1.0/default/Foo.h +++ b/tests/foo/1.0/default/Foo.h | |||
@@ -22,9 +22,14 @@ using ::android::hardware::Void; | |||
22 | using ::android::hardware::hidl_vec; | 22 | using ::android::hardware::hidl_vec; |
23 | using ::android::hardware::hidl_string; | 23 | using ::android::hardware::hidl_string; |
24 | using ::android::sp; | 24 | using ::android::sp; |
25 | using ContainsUnion = ::android::hardware::tests::foo::V1_0::IFoo::ContainsUnion; | ||
26 | using Discriminator = ::android::hardware::tests::foo::V1_0::IFoo::Discriminator; | ||
27 | using Union = ::android::hardware::tests::foo::V1_0::IFoo::Union; | ||
25 | 28 | ||
26 | struct Foo : public IFoo { | 29 | struct Foo : public IFoo { |
27 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. | 30 | // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. |
31 | virtual Return<void> convertToBoolIfSmall(Discriminator d, const hidl_vec<Union>& u, | ||
32 | convertToBoolIfSmall_cb _hidl_cb) override; | ||
28 | virtual Return<void> doThis(float param) override; | 33 | virtual Return<void> doThis(float param) override; |
29 | virtual Return<int32_t> doThatAndReturnSomething(int64_t param) override; | 34 | virtual Return<int32_t> doThatAndReturnSomething(int64_t param) override; |
30 | virtual Return<double> doQuiteABit(int32_t a, int64_t b, float c, double d) override; | 35 | virtual Return<double> doQuiteABit(int32_t a, int64_t b, float c, double d) override; |