From e7ce822b9660a897075ec4d3c352e1e7f7f787f3 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 5 Dec 2016 12:34:42 -0800 Subject: [PATCH] Add test for bitset/mask type. Test: hidl_test Change-Id: I8bcd304184ff6b7794a9d0b5d3999f071604471d --- tests/bar/1.0/IBar.hal | 2 ++ tests/bar/1.0/default/Bar.cpp | 6 ++++++ tests/bar/1.0/default/Bar.h | 6 ++++++ tests/baz/1.0/IBase.hal | 16 ++++++++++++++++ tests/foo/1.0/IFoo.hal | 13 +++++++++++++ 5 files changed, 43 insertions(+) diff --git a/tests/bar/1.0/IBar.hal b/tests/bar/1.0/IBar.hal index 82c6fc1e87..21c34739bb 100644 --- a/tests/bar/1.0/IBar.hal +++ b/tests/bar/1.0/IBar.hal @@ -31,4 +31,6 @@ interface IBar extends android.hardware.tests.foo@1.0::IFoo { thisIsNew(); expectNullHandle(handle h, Abc xyz) generates (bool hIsNull, bool xyzHasNull); + takeAMask(BitField bf, bitfield first, MyMask second, Mask third) + generates (BitField bf, uint8_t first, uint8_t second, uint8_t third); }; diff --git a/tests/bar/1.0/default/Bar.cpp b/tests/bar/1.0/default/Bar.cpp index cac0845c92..a9b6c25ff8 100644 --- a/tests/bar/1.0/default/Bar.cpp +++ b/tests/bar/1.0/default/Bar.cpp @@ -185,6 +185,12 @@ Return Bar::expectNullHandle(const hidl_handle& h, const Abc& xyz, expectN return Void(); } +Return Bar::takeAMask(BitField bf, uint8_t first, const MyMask& second, uint8_t third, + takeAMask_cb _hidl_cb) { + _hidl_cb(bf, bf | first, second.value & bf, (bf | bf) & third); + return Void(); +} + IBar* HIDL_FETCH_IBar(const char* /* name */) { return new Bar(); } diff --git a/tests/bar/1.0/default/Bar.h b/tests/bar/1.0/default/Bar.h index 0400b9847b..71737fe832 100644 --- a/tests/bar/1.0/default/Bar.h +++ b/tests/bar/1.0/default/Bar.h @@ -23,6 +23,9 @@ using ::android::hardware::hidl_vec; using ::android::hardware::hidl_string; using ::android::sp; +using BitField = ::android::hardware::tests::foo::V1_0::IFoo::BitField; +using MyMask = ::android::hardware::tests::foo::V1_0::IFoo::MyMask; + struct Bar : public IBar { Bar(); @@ -66,6 +69,9 @@ struct Bar : public IBar { Return thisIsNew() override; Return expectNullHandle(const hidl_handle& h, const Abc& xyz, expectNullHandle_cb _hidl_cb) override; + Return takeAMask(BitField bf, uint8_t first, const MyMask& second, uint8_t third, + takeAMask_cb _hidl_cb) override; + private: sp mFoo; }; diff --git a/tests/baz/1.0/IBase.hal b/tests/baz/1.0/IBase.hal index 7f90f16f2a..d5e35651ef 100644 --- a/tests/baz/1.0/IBase.hal +++ b/tests/baz/1.0/IBase.hal @@ -64,6 +64,19 @@ interface IBase { vec addresses; }; + enum BitField : uint8_t { + V0 = 1 << 0, + V1 = 1 << 1, + V2 = 1 << 2, + V3 = 1 << 3, + }; + + struct MyMask { + bitfield value; + }; + + typedef bitfield Mask; + someBaseMethod(); someBoolMethod(bool x) generates (bool y); @@ -81,4 +94,7 @@ interface IBase { transpose(StringMatrix5x3 in) generates (StringMatrix3x5 out); transpose2(ThreeStrings[5] in) generates (FiveStrings[3] out); + + takeAMask(BitField bf, bitfield first, MyMask second, Mask third) + generates (BitField out, uint8_t f, uint8_t s, uint8_t t); }; diff --git a/tests/foo/1.0/IFoo.hal b/tests/foo/1.0/IFoo.hal index ea69e1ebe4..fc76c1ca4e 100644 --- a/tests/foo/1.0/IFoo.hal +++ b/tests/foo/1.0/IFoo.hal @@ -33,6 +33,13 @@ interface IFoo { blah = goober }; + enum BitField : uint8_t { + V0 = 1 << 0, + V1 = 1 << 1, + V2 = 1 << 2, + V3 = 1 << 3, + }; + struct Fumble { Outer.Inner data; }; @@ -85,6 +92,12 @@ interface IFoo { int32_t guard; }; + struct MyMask { + bitfield value; + }; + + typedef bitfield Mask; + doThis(float param); doThatAndReturnSomething(int64_t param) generates (int32_t result); doQuiteABit(int32_t a, int64_t b, float c, double d) generates (double something);