1 #ifndef ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H 2 #define ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H 3 4 #include <android/hardware/tests/pointer/1.0/IPointer.h> 5 #include <hidl/Status.h> 6 7 #include <hidl/MQDescriptor.h> 8 9 // TODO move to Pointer.cpp so that I won't have weird macros in headers 10 #define PUSH_ERROR_IF(__cond__) if(__cond__) { errors.push_back(std::to_string(__LINE__) + ": " + #__cond__); } 11 12 namespace android { 13 namespace hardware { 14 namespace tests { 15 namespace pointer { 16 namespace V1_0 { 17 namespace implementation { 18 19 using ::android::hardware::tests::pointer::V1_0::IPointer; 20 using ::android::hardware::Return; 21 using ::android::hardware::Void; 22 using ::android::hardware::hidl_vec; 23 using ::android::hardware::hidl_string; 24 using ::android::sp; 25 26 struct Pointer : public IPointer { 27 private: 28 std::vector<std::string> errors; 29 public: 30 Return<int32_t> getErrors() override; foo1Pointer31 Return<void> foo1(const IPointer::Sam& s, IPointer::Sam const* s_ptr) override { 32 PUSH_ERROR_IF(!(&s == s_ptr)); 33 return Void(); 34 } foo2Pointer35 Return<void> foo2(const IPointer::Sam& s, const IPointer::Ada& a) override { 36 PUSH_ERROR_IF(!(&s == a.s_ptr)); 37 return Void(); 38 } foo3Pointer39 Return<void> foo3(const IPointer::Sam& s, const IPointer::Ada& a, const IPointer::Bob& b) override { 40 PUSH_ERROR_IF(!(&a == b.a_ptr && a.s_ptr == b.s_ptr && a.s_ptr == &s)); 41 return Void(); 42 } foo4Pointer43 Return<void> foo4(IPointer::Sam const* s_ptr) override { 44 PUSH_ERROR_IF(!(s_ptr->data == 500)); 45 return Void(); 46 } foo5Pointer47 Return<void> foo5(const IPointer::Ada& a, const IPointer::Bob& b) override { 48 PUSH_ERROR_IF(!(a.s_ptr == b.s_ptr && b.a_ptr == &a)); 49 return Void(); 50 } foo6Pointer51 Return<void> foo6(IPointer::Ada const* a_ptr) override { 52 PUSH_ERROR_IF(!(a_ptr->s_ptr->data == 500)); 53 return Void(); 54 } foo7Pointer55 Return<void> foo7(IPointer::Ada const* a_ptr, IPointer::Bob const* b_ptr) override { 56 PUSH_ERROR_IF(!(a_ptr->s_ptr == b_ptr->s_ptr && a_ptr == b_ptr->a_ptr && a_ptr->s_ptr->data == 500)); 57 return Void(); 58 } foo8Pointer59 Return<void> foo8(const IPointer::Dom& d) override { 60 const IPointer::Cin& c = d.c; 61 PUSH_ERROR_IF(&c.a != c.b_ptr->a_ptr); 62 PUSH_ERROR_IF(c.a.s_ptr != c.b_ptr->s_ptr); 63 PUSH_ERROR_IF(c.a.s_ptr->data != 500); 64 return Void(); 65 } foo9Pointer66 Return<void> foo9(::android::hardware::hidl_string const* str_ref) override { 67 PUSH_ERROR_IF(!(strcmp(str_ref->c_str(), "meowmeowmeow") == 0)); 68 return Void(); 69 } foo10Pointer70 Return<void> foo10(const ::android::hardware::hidl_vec<IPointer::Sam const*>& s_ptr_vec) override { 71 PUSH_ERROR_IF(s_ptr_vec[0]->data != 500); 72 if(s_ptr_vec.size() != 5) { 73 errors.push_back("foo10: s_ptr_vec.size() != 5"); 74 return Void(); 75 } 76 for(size_t i = 0; i < s_ptr_vec.size(); i++) 77 PUSH_ERROR_IF(s_ptr_vec[0] != s_ptr_vec[i]); 78 return Void(); 79 } foo11Pointer80 Return<void> foo11(::android::hardware::hidl_vec<IPointer::Sam> const* s_vec_ptr) override { 81 if(s_vec_ptr->size() != 5) { 82 errors.push_back("foo11: s_vec_ptr->size() != 5"); 83 return Void(); 84 } 85 for(size_t i = 0; i < 5; i++) 86 PUSH_ERROR_IF((*s_vec_ptr)[i].data != 500); 87 return Void(); 88 } foo12Pointer89 Return<void> foo12(hidl_array<IPointer::Sam, 5> const* s_array_ref) override { 90 for(size_t i = 0; i < 5; ++i) 91 PUSH_ERROR_IF((*s_array_ref)[i].data != 500); 92 return Void(); 93 } foo13Pointer94 Return<void> foo13(const hidl_array<IPointer::Sam const*, 5>& s_ref_array) override { 95 PUSH_ERROR_IF(s_ref_array[0]->data != 500) 96 for(size_t i = 0; i < 5; i++) 97 PUSH_ERROR_IF(s_ref_array[i] != s_ref_array[0]) 98 return Void(); 99 } foo14Pointer100 Return<void> foo14(IPointer::Sam const* const* const* s_3ptr) override { 101 PUSH_ERROR_IF(!((***s_3ptr).data == 500)) 102 return Void(); 103 } foo15Pointer104 Return<void> foo15(int32_t const* const* const* i_3ptr) override { 105 PUSH_ERROR_IF(!((***i_3ptr) == 500)) 106 return Void(); 107 } 108 foo16Pointer109 Return<void> foo16(const IPointer::Ptr& p) override { 110 PUSH_ERROR_IF((*p.array_ptr)[0].s_ptr->data != 500); 111 for(size_t i = 0; i < 5; i++) PUSH_ERROR_IF((*p.array_ptr)[i].s_ptr != (*p.array_ptr)[0].s_ptr); 112 PUSH_ERROR_IF(*(p.int_ptr) != 500); 113 for(size_t i = 0; i < 5; i++) PUSH_ERROR_IF((*p.int_array_ptr)[i] != 500); 114 for(size_t i = 0; i < 5; i++) PUSH_ERROR_IF(p.int_ptr_array[i] != p.int_ptr); 115 PUSH_ERROR_IF(p.a_ptr_vec.size() != 5); 116 PUSH_ERROR_IF(p.a_ptr_vec[0]->s_ptr->data != 500); 117 for(size_t i = 0; i < 5; i++) PUSH_ERROR_IF(p.a_ptr_vec[i]->s_ptr != p.a_ptr_vec[0]->s_ptr); 118 PUSH_ERROR_IF(strcmp(p.str_ref->c_str(), "meowmeowmeow") != 0); 119 PUSH_ERROR_IF(p.a_vec_ptr->size() != 5); 120 PUSH_ERROR_IF((*p.a_vec_ptr)[0].s_ptr->data != 500); 121 for(size_t i = 0; i < 5; i++) PUSH_ERROR_IF((*p.a_vec_ptr)[i].s_ptr != (*p.a_vec_ptr)[0].s_ptr); 122 return Void(); 123 }; foo17Pointer124 Return<void> foo17(IPointer::Ptr const* p) override { 125 return foo16(*p); 126 }; foo18Pointer127 Return<void> foo18(hidl_string const* str_ref, hidl_string const* str_ref2, const hidl_string& str) override { 128 PUSH_ERROR_IF(&str != str_ref); 129 PUSH_ERROR_IF(str_ref != str_ref2); 130 PUSH_ERROR_IF(strcmp(str.c_str(), "meowmeowmeow") != 0) 131 return Void(); 132 }; foo19Pointer133 Return<void> foo19( 134 hidl_vec<IPointer::Ada> const* a_vec_ref, 135 const hidl_vec<IPointer::Ada>& a_vec, 136 hidl_vec<IPointer::Ada> const* a_vec_ref2) { 137 PUSH_ERROR_IF(&a_vec != a_vec_ref); 138 PUSH_ERROR_IF(a_vec_ref2 != a_vec_ref); 139 PUSH_ERROR_IF(a_vec.size() != 5); 140 PUSH_ERROR_IF(a_vec[0].s_ptr->data != 500); 141 for(size_t i = 0; i < 5; i++) 142 PUSH_ERROR_IF(a_vec[i].s_ptr != a_vec[0].s_ptr); 143 return Void(); 144 }; 145 foo20Pointer146 Return<void> foo20(const hidl_vec<IPointer::Sam const*>&) override { 147 return Void(); 148 } foo21Pointer149 Return<void> foo21(hidl_array<IPointer::Ada, 1, 2, 3> const* a_array_ptr) override { 150 const hidl_array<IPointer::Ada, 1, 2, 3>& a_array = *a_array_ptr; 151 PUSH_ERROR_IF(a_array[0][0][0].s_ptr->data != 500); 152 for(size_t i = 0; i < 1; i++) 153 for(size_t j = 0; j < 2; j++) 154 for(size_t k = 0; k < 3; k++) 155 PUSH_ERROR_IF(a_array[i][j][k].s_ptr != a_array[0][0][0].s_ptr); 156 return Void(); 157 } foo22Pointer158 Return<void> foo22(const hidl_array<IPointer::Ada const*, 1, 2, 3>& a_ptr_array) override { 159 PUSH_ERROR_IF(a_ptr_array[0][0][0]->s_ptr->data != 500); 160 for(size_t i = 0; i < 1; i++) 161 for(size_t j = 0; j < 2; j++) 162 for(size_t k = 0; k < 3; k++) 163 PUSH_ERROR_IF(a_ptr_array[i][j][k] != a_ptr_array[0][0][0]); 164 return Void(); 165 } 166 167 IPointer::Sam *s; 168 IPointer::Ada *a; 169 IPointer::Bob *b; 170 IPointer::Cin *c; 171 IPointer::Dom *d; 172 173 IPointer::Ptr p; 174 hidl_array<IPointer::Ada, 5> a_array; 175 int32_t someInt; 176 hidl_array<int32_t, 5> someIntArray; 177 hidl_string str; 178 hidl_vec<IPointer::Ada> a_vec; PointerPointer179 Pointer() { 180 d = new IPointer::Dom(); 181 s = new IPointer::Sam(); 182 b = new IPointer::Bob(); 183 c = &d->c; 184 a = &c->a; 185 b->s_ptr = a->s_ptr = s; 186 b->a_ptr = a; 187 c->b_ptr = b; 188 s->data = 500; 189 190 someInt = 500; 191 for(size_t i = 0; i < 5; i++) someIntArray[i] = 500; 192 193 for(size_t i = 0; i < 5; i++) a_array[i] = *a; 194 195 for(size_t i = 0; i < 5; i++) p.ptr_array[i] = a; 196 p.array_ptr = &a_array; 197 p.int_ptr = &someInt; 198 p.int_array_ptr = &someIntArray; 199 for(size_t i = 0; i < 5; i++) p.int_ptr_array[i] = &someInt; 200 p.a_ptr_vec.resize(5); 201 for(size_t i = 0; i < 5; i++) p.a_ptr_vec[i] = a; 202 str = "meowmeowmeow"; 203 p.str_ref = &str; 204 a_vec.resize(5); 205 for(size_t i = 0; i < 5; i++) a_vec[i].s_ptr = s; 206 p.a_vec_ptr = &a_vec; 207 } ~PointerPointer208 ~Pointer() { 209 delete d; delete s; delete b; 210 } bar1Pointer211 Return<void> bar1(bar1_cb _cb) override { 212 _cb(*s, s); 213 return Void(); 214 } bar2Pointer215 Return<void> bar2(bar2_cb _cb) override { 216 _cb(*s, *a); 217 return Void(); 218 } bar3Pointer219 Return<void> bar3(bar3_cb _cb) override { 220 _cb(*s, *a, *b); 221 return Void(); 222 } bar4Pointer223 Return<void> bar4(bar4_cb _cb) override { 224 _cb(s); 225 return Void(); 226 } bar5Pointer227 Return<void> bar5(bar5_cb _cb) override { 228 _cb(*a, *b); 229 return Void(); 230 } bar6Pointer231 Return<void> bar6(bar6_cb _cb) override { 232 _cb(a); 233 return Void(); 234 } bar7Pointer235 Return<void> bar7(bar7_cb _cb) override { 236 _cb(a, b); 237 return Void(); 238 } bar8Pointer239 Return<void> bar8(bar8_cb _cb) override { 240 _cb(*d); 241 return Void(); 242 } bar9Pointer243 Return<void> bar9(bar9_cb _cb) override { 244 _cb(&str); 245 return Void(); 246 } bar10Pointer247 Return<void> bar10(bar10_cb _cb) override { 248 hidl_vec<const IPointer::Sam *> v; v.resize(5); 249 for(size_t i = 0; i < 5; i++) v[i] = s; 250 _cb(v); 251 return Void(); 252 } bar11Pointer253 Return<void> bar11(bar11_cb _cb) override { 254 hidl_vec<IPointer::Sam> v; v.resize(5); 255 for(size_t i = 0; i < 5; i++) v[i].data = 500; 256 _cb(&v); 257 return Void(); 258 } bar12Pointer259 Return<void> bar12(bar12_cb _cb) override { 260 hidl_array<IPointer::Sam, 5> array; 261 for(size_t i = 0; i < 5; i++) array[i] = *s; 262 _cb(&array); 263 return Void(); 264 } bar13Pointer265 Return<void> bar13(bar13_cb _cb) override { 266 hidl_array<const IPointer::Sam *, 5> array; 267 for(size_t i = 0; i < 5; i++) array[i] = s; 268 _cb(array); 269 return Void(); 270 } bar14Pointer271 Return<void> bar14(bar14_cb _cb) override { 272 IPointer::Sam const* p1 = s; 273 IPointer::Sam const* const* p2 = &p1; 274 _cb(&p2); 275 return Void(); 276 } bar15Pointer277 Return<void> bar15(bar15_cb _cb) override { 278 int32_t const* p1 = &someInt; 279 int32_t const* const* p2 = &p1; 280 _cb(&p2); 281 return Void(); 282 } bar16Pointer283 Return<void> bar16(bar16_cb _cb) override { 284 _cb(p); 285 return Void(); 286 } bar17Pointer287 Return<void> bar17(bar17_cb _cb) override { 288 _cb(&p); 289 return Void(); 290 } bar18Pointer291 Return<void> bar18(bar18_cb _cb) override { 292 _cb(&str, &str, str); 293 return Void(); 294 } bar19Pointer295 Return<void> bar19(bar19_cb _cb) override { 296 _cb(&a_vec, a_vec, &a_vec); 297 return Void(); 298 } bar20Pointer299 Return<void> bar20(bar20_cb _cb) override { 300 // 1026 == PARCEL_REF_CAP + 2. 301 // 1026 means 1 writeBuffer and 1025 writeReferences. 1025 > PARCEL_REF_CAP. 302 hidl_vec<const IPointer::Sam *> v; v.resize(1026); 303 for(size_t i = 0; i < 1026; i++) v[i] = s; 304 _cb(v); 305 return Void(); 306 } bar21Pointer307 Return<void> bar21(bar21_cb _cb) override { 308 hidl_array<IPointer::Ada, 1, 2, 3> a_array; 309 for(size_t i = 0; i < 1; i++) 310 for(size_t j = 0; j < 2; j++) 311 for(size_t k = 0; k < 3; k++) 312 a_array[i][j][k] = *a; 313 _cb(&a_array); 314 return Void(); 315 } bar22Pointer316 Return<void> bar22(bar22_cb _cb) override { 317 hidl_array<const IPointer::Ada *, 1, 2, 3> a_ptr_array; 318 for(size_t i = 0; i < 1; i++) 319 for(size_t j = 0; j < 2; j++) 320 for(size_t k = 0; k < 3; k++) 321 a_ptr_array[i][j][k] = a; 322 _cb(a_ptr_array); 323 return Void(); 324 } 325 }; 326 327 extern "C" IPointer* HIDL_FETCH_IPointer(const char* name); 328 329 } // namespace implementation 330 } // namespace V1_0 331 } // namespace pointer 332 } // namespace tests 333 } // namespace hardware 334 } // namespace android 335 336 #undef PUSH_ERROR_IF 337 338 #endif // ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H 339