summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSteven Moreland2017-12-14 21:10:10 -0600
committerandroid-build-merger2017-12-14 21:10:10 -0600
commitb3258731347c41acdc66dd03e486f17db81e4e6d (patch)
tree1b0018ff9478752cd88076235619129584cfc26f /tests
parenta26880319accc608d1be834abb0dd201b455a6ef (diff)
parentdc3e125f5452c8998cb6ef07c5c4ad467f8a4d5e (diff)
downloadplatform-hardware-interfaces-b3258731347c41acdc66dd03e486f17db81e4e6d.tar.gz
platform-hardware-interfaces-b3258731347c41acdc66dd03e486f17db81e4e6d.tar.xz
platform-hardware-interfaces-b3258731347c41acdc66dd03e486f17db81e4e6d.zip
Merge "Test for vec<union> vec<struct w/ union>." am: cd619af7bc am: bc3f5661c8
am: dc3e125f54 Change-Id: Ibb3cf3d695feacfa3fbf905f5cf2e55a51bd1241
Diffstat (limited to 'tests')
-rw-r--r--tests/bar/1.0/default/Bar.cpp5
-rw-r--r--tests/bar/1.0/default/Bar.h2
-rw-r--r--tests/foo/1.0/IFoo.hal23
-rw-r--r--tests/foo/1.0/default/Foo.cpp24
-rw-r--r--tests/foo/1.0/default/Foo.h5
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.
22Return<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
22Return<void> Bar::doThis(float param) { 27Return<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 {
15namespace implementation { 15namespace 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.
18Return<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
18Return<void> Foo::doThis(float param) { 42Return<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;
22using ::android::hardware::hidl_vec; 22using ::android::hardware::hidl_vec;
23using ::android::hardware::hidl_string; 23using ::android::hardware::hidl_string;
24using ::android::sp; 24using ::android::sp;
25using ContainsUnion = ::android::hardware::tests::foo::V1_0::IFoo::ContainsUnion;
26using Discriminator = ::android::hardware::tests::foo::V1_0::IFoo::Discriminator;
27using Union = ::android::hardware::tests::foo::V1_0::IFoo::Union;
25 28
26struct Foo : public IFoo { 29struct 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;