Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "mbed.h" 00017 #include "greentea-client/test_env.h" 00018 #include "unity.h" 00019 #include "utest.h" 00020 00021 using namespace utest::v1; 00022 00023 00024 // static functions 00025 template <typename T> 00026 T static_func0() 00027 { return 0; } 00028 template <typename T> 00029 T static_func1(T a0) 00030 { return 0 | a0; } 00031 template <typename T> 00032 T static_func2(T a0, T a1) 00033 { return 0 | a0 | a1; } 00034 template <typename T> 00035 T static_func3(T a0, T a1, T a2) 00036 { return 0 | a0 | a1 | a2; } 00037 template <typename T> 00038 T static_func4(T a0, T a1, T a2, T a3) 00039 { return 0 | a0 | a1 | a2 | a3; } 00040 template <typename T> 00041 T static_func5(T a0, T a1, T a2, T a3, T a4) 00042 { return 0 | a0 | a1 | a2 | a3 | a4; } 00043 00044 // class functions 00045 template <typename T> 00046 struct Thing { 00047 T t; 00048 Thing() : t(0x80) {} 00049 00050 T member_func0() 00051 { return t; } 00052 T member_func1(T a0) 00053 { return t | a0; } 00054 T member_func2(T a0, T a1) 00055 { return t | a0 | a1; } 00056 T member_func3(T a0, T a1, T a2) 00057 { return t | a0 | a1 | a2; } 00058 T member_func4(T a0, T a1, T a2, T a3) 00059 { return t | a0 | a1 | a2 | a3; } 00060 T member_func5(T a0, T a1, T a2, T a3, T a4) 00061 { return t | a0 | a1 | a2 | a3 | a4; } 00062 00063 T const_member_func0() const 00064 { return t; } 00065 T const_member_func1(T a0) const 00066 { return t | a0; } 00067 T const_member_func2(T a0, T a1) const 00068 { return t | a0 | a1; } 00069 T const_member_func3(T a0, T a1, T a2) const 00070 { return t | a0 | a1 | a2; } 00071 T const_member_func4(T a0, T a1, T a2, T a3) const 00072 { return t | a0 | a1 | a2 | a3; } 00073 T const_member_func5(T a0, T a1, T a2, T a3, T a4) const 00074 { return t | a0 | a1 | a2 | a3 | a4; } 00075 00076 T volatile_member_func0() volatile 00077 { return t; } 00078 T volatile_member_func1(T a0) volatile 00079 { return t | a0; } 00080 T volatile_member_func2(T a0, T a1) volatile 00081 { return t | a0 | a1; } 00082 T volatile_member_func3(T a0, T a1, T a2) volatile 00083 { return t | a0 | a1 | a2; } 00084 T volatile_member_func4(T a0, T a1, T a2, T a3) volatile 00085 { return t | a0 | a1 | a2 | a3; } 00086 T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile 00087 { return t | a0 | a1 | a2 | a3 | a4; } 00088 00089 T const_volatile_member_func0() const volatile 00090 { return t; } 00091 T const_volatile_member_func1(T a0) const volatile 00092 { return t | a0; } 00093 T const_volatile_member_func2(T a0, T a1) const volatile 00094 { return t | a0 | a1; } 00095 T const_volatile_member_func3(T a0, T a1, T a2) const volatile 00096 { return t | a0 | a1 | a2; } 00097 T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile 00098 { return t | a0 | a1 | a2 | a3; } 00099 T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile 00100 { return t | a0 | a1 | a2 | a3 | a4; } 00101 }; 00102 00103 // bound functions 00104 template <typename T> 00105 T bound_func0(Thing<T> *t) 00106 { return t->t; } 00107 template <typename T> 00108 T bound_func1(Thing<T> *t, T a0) 00109 { return t->t | a0; } 00110 template <typename T> 00111 T bound_func2(Thing<T> *t, T a0, T a1) 00112 { return t->t | a0 | a1; } 00113 template <typename T> 00114 T bound_func3(Thing<T> *t, T a0, T a1, T a2) 00115 { return t->t | a0 | a1 | a2; } 00116 template <typename T> 00117 T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) 00118 { return t->t | a0 | a1 | a2 | a3; } 00119 template <typename T> 00120 T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00121 { return t->t | a0 | a1 | a2 | a3 | a4; } 00122 template <typename T> 00123 T const_bound_func0(const Thing<T> *t) 00124 { return t->t; } 00125 template <typename T> 00126 T const_bound_func1(const Thing<T> *t, T a0) 00127 { return t->t | a0; } 00128 template <typename T> 00129 T const_bound_func2(const Thing<T> *t, T a0, T a1) 00130 { return t->t | a0 | a1; } 00131 template <typename T> 00132 T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2) 00133 { return t->t | a0 | a1 | a2; } 00134 template <typename T> 00135 T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) 00136 { return t->t | a0 | a1 | a2 | a3; } 00137 template <typename T> 00138 T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00139 { return t->t | a0 | a1 | a2 | a3 | a4; } 00140 template <typename T> 00141 T volatile_bound_func0(volatile Thing<T> *t) 00142 { return t->t; } 00143 template <typename T> 00144 T volatile_bound_func1(volatile Thing<T> *t, T a0) 00145 { return t->t | a0; } 00146 template <typename T> 00147 T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1) 00148 { return t->t | a0 | a1; } 00149 template <typename T> 00150 T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2) 00151 { return t->t | a0 | a1 | a2; } 00152 template <typename T> 00153 T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) 00154 { return t->t | a0 | a1 | a2 | a3; } 00155 template <typename T> 00156 T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00157 { return t->t | a0 | a1 | a2 | a3 | a4; } 00158 template <typename T> 00159 T const_volatile_bound_func0(const volatile Thing<T> *t) 00160 { return t->t; } 00161 template <typename T> 00162 T const_volatile_bound_func1(const volatile Thing<T> *t, T a0) 00163 { return t->t | a0; } 00164 template <typename T> 00165 T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1) 00166 { return t->t | a0 | a1; } 00167 template <typename T> 00168 T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2) 00169 { return t->t | a0 | a1 | a2; } 00170 template <typename T> 00171 T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) 00172 { return t->t | a0 | a1 | a2 | a3; } 00173 template <typename T> 00174 T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00175 { return t->t | a0 | a1 | a2 | a3 | a4; } 00176 00177 // void functions 00178 template <typename T> 00179 T void_func0(void *t) 00180 { return static_cast<Thing<T>*>(t)->t; } 00181 template <typename T> 00182 T void_func1(void *t, T a0) 00183 { return static_cast<Thing<T>*>(t)->t | a0; } 00184 template <typename T> 00185 T void_func2(void *t, T a0, T a1) 00186 { return static_cast<Thing<T>*>(t)->t | a0 | a1; } 00187 template <typename T> 00188 T void_func3(void *t, T a0, T a1, T a2) 00189 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; } 00190 template <typename T> 00191 T void_func4(void *t, T a0, T a1, T a2, T a3) 00192 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00193 template <typename T> 00194 T void_func5(void *t, T a0, T a1, T a2, T a3, T a4) 00195 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00196 template <typename T> 00197 T const_void_func0(const void *t) 00198 { return static_cast<const Thing<T>*>(t)->t; } 00199 template <typename T> 00200 T const_void_func1(const void *t, T a0) 00201 { return static_cast<const Thing<T>*>(t)->t | a0; } 00202 template <typename T> 00203 T const_void_func2(const void *t, T a0, T a1) 00204 { return static_cast<const Thing<T>*>(t)->t | a0 | a1; } 00205 template <typename T> 00206 T const_void_func3(const void *t, T a0, T a1, T a2) 00207 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; } 00208 template <typename T> 00209 T const_void_func4(const void *t, T a0, T a1, T a2, T a3) 00210 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00211 template <typename T> 00212 T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4) 00213 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00214 template <typename T> 00215 T volatile_void_func0(volatile void *t) 00216 { return static_cast<volatile Thing<T>*>(t)->t; } 00217 template <typename T> 00218 T volatile_void_func1(volatile void *t, T a0) 00219 { return static_cast<volatile Thing<T>*>(t)->t | a0; } 00220 template <typename T> 00221 T volatile_void_func2(volatile void *t, T a0, T a1) 00222 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; } 00223 template <typename T> 00224 T volatile_void_func3(volatile void *t, T a0, T a1, T a2) 00225 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; } 00226 template <typename T> 00227 T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3) 00228 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00229 template <typename T> 00230 T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4) 00231 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00232 template <typename T> 00233 T const_volatile_void_func0(const volatile void *t) 00234 { return static_cast<const volatile Thing<T>*>(t)->t; } 00235 template <typename T> 00236 T const_volatile_void_func1(const volatile void *t, T a0) 00237 { return static_cast<const volatile Thing<T>*>(t)->t | a0; } 00238 template <typename T> 00239 T const_volatile_void_func2(const volatile void *t, T a0, T a1) 00240 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; } 00241 template <typename T> 00242 T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2) 00243 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; } 00244 template <typename T> 00245 T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3) 00246 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00247 template <typename T> 00248 T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4) 00249 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00250 00251 // Inheriting class 00252 template <typename T> 00253 class Thing2 : public Thing<T> { 00254 }; 00255 00256 00257 // function call and result verification 00258 template <typename T> 00259 struct Verifier { 00260 static void verify0(Callback<T()> func) { 00261 T result = func(); 00262 TEST_ASSERT_EQUAL(result, 0x00); 00263 } 00264 00265 template <typename O, typename M> 00266 static void verify0(O *obj, M method) { 00267 Callback<T()> func(obj, method); 00268 T result = func(); 00269 TEST_ASSERT_EQUAL(result, 0x80); 00270 } 00271 00272 static void verify1(Callback<T(T)> func) { 00273 T result = func((1 << 0)); 00274 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); 00275 } 00276 00277 template <typename O, typename M> 00278 static void verify1(O *obj, M method) { 00279 Callback<T(T)> func(obj, method); 00280 T result = func((1 << 0)); 00281 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); 00282 } 00283 00284 static void verify2(Callback<T(T, T)> func) { 00285 T result = func((1 << 0), (1 << 1)); 00286 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); 00287 } 00288 00289 template <typename O, typename M> 00290 static void verify2(O *obj, M method) { 00291 Callback<T(T, T)> func(obj, method); 00292 T result = func((1 << 0), (1 << 1)); 00293 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); 00294 } 00295 00296 static void verify3(Callback<T(T, T, T)> func) { 00297 T result = func((1 << 0), (1 << 1), (1 << 2)); 00298 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); 00299 } 00300 00301 template <typename O, typename M> 00302 static void verify3(O *obj, M method) { 00303 Callback<T(T, T, T)> func(obj, method); 00304 T result = func((1 << 0), (1 << 1), (1 << 2)); 00305 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); 00306 } 00307 00308 static void verify4(Callback<T(T, T, T, T)> func) { 00309 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); 00310 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); 00311 } 00312 00313 template <typename O, typename M> 00314 static void verify4(O *obj, M method) { 00315 Callback<T(T, T, T, T)> func(obj, method); 00316 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); 00317 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); 00318 } 00319 00320 static void verify5(Callback<T(T, T, T, T, T)> func) { 00321 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); 00322 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); 00323 } 00324 00325 template <typename O, typename M> 00326 static void verify5(O *obj, M method) { 00327 Callback<T(T, T, T, T, T)> func(obj, method); 00328 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); 00329 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); 00330 } 00331 }; 00332 00333 00334 // test dispatch 00335 template <typename T> 00336 void test_dispatch0() { 00337 Thing<T> thing; 00338 Thing2<T> thing2; 00339 Verifier<T>::verify0(static_func0<T>); 00340 Verifier<T>::verify0(&thing, &Thing<T>::member_func0); 00341 Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0); 00342 Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0); 00343 Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0); 00344 Verifier<T>::verify0(&thing2, &Thing2<T>::member_func0); 00345 Verifier<T>::verify0(&bound_func0<T>, &thing); 00346 Verifier<T>::verify0(&const_bound_func0<T>, (const Thing<T>*)&thing); 00347 Verifier<T>::verify0(&volatile_bound_func0<T>, (volatile Thing<T>*)&thing); 00348 Verifier<T>::verify0(&const_volatile_bound_func0<T>, (const volatile Thing<T>*)&thing); 00349 Verifier<T>::verify0(&bound_func0<T>, &thing2); 00350 Verifier<T>::verify0(&void_func0<T>, &thing); 00351 Verifier<T>::verify0(&const_void_func0<T>, (const Thing<T>*)&thing); 00352 Verifier<T>::verify0(&volatile_void_func0<T>, (volatile Thing<T>*)&thing); 00353 Verifier<T>::verify0(&const_volatile_void_func0<T>, (const volatile Thing<T>*)&thing); 00354 Verifier<T>::verify0(callback(static_func0<T>)); 00355 00356 Callback<T()> cb(static_func0); 00357 Verifier<T>::verify0(cb); 00358 cb = static_func0; 00359 Verifier<T>::verify0(cb); 00360 cb.attach(&bound_func0<T>, &thing); 00361 Verifier<T>::verify0(&cb, &Callback<T()>::call); 00362 Verifier<T>::verify0(&Callback<T()>::thunk, (void*)&cb); 00363 } 00364 00365 template <typename T> 00366 void test_dispatch1() { 00367 Thing<T> thing; 00368 Thing2<T> thing2; 00369 Verifier<T>::verify1(static_func1<T>); 00370 Verifier<T>::verify1(&thing, &Thing<T>::member_func1); 00371 Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1); 00372 Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1); 00373 Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1); 00374 Verifier<T>::verify1(&thing2, &Thing2<T>::member_func1); 00375 Verifier<T>::verify1(&bound_func1<T>, &thing); 00376 Verifier<T>::verify1(&const_bound_func1<T>, (const Thing<T>*)&thing); 00377 Verifier<T>::verify1(&volatile_bound_func1<T>, (volatile Thing<T>*)&thing); 00378 Verifier<T>::verify1(&const_volatile_bound_func1<T>, (const volatile Thing<T>*)&thing); 00379 Verifier<T>::verify1(&bound_func1<T>, &thing2); 00380 Verifier<T>::verify1(&void_func1<T>, &thing); 00381 Verifier<T>::verify1(&const_void_func1<T>, (const Thing<T>*)&thing); 00382 Verifier<T>::verify1(&volatile_void_func1<T>, (volatile Thing<T>*)&thing); 00383 Verifier<T>::verify1(&const_volatile_void_func1<T>, (const volatile Thing<T>*)&thing); 00384 Verifier<T>::verify1(callback(static_func1<T>)); 00385 00386 Callback<T(T)> cb(static_func1); 00387 Verifier<T>::verify1(cb); 00388 cb = static_func1; 00389 Verifier<T>::verify1(cb); 00390 cb.attach(&bound_func1<T>, &thing); 00391 Verifier<T>::verify1(&cb, &Callback<T(T)>::call); 00392 Verifier<T>::verify1(&Callback<T(T)>::thunk, (void*)&cb); 00393 } 00394 00395 template <typename T> 00396 void test_dispatch2() { 00397 Thing<T> thing; 00398 Thing2<T> thing2; 00399 Verifier<T>::verify2(static_func2<T>); 00400 Verifier<T>::verify2(&thing, &Thing<T>::member_func2); 00401 Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2); 00402 Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2); 00403 Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2); 00404 Verifier<T>::verify2(&thing2, &Thing2<T>::member_func2); 00405 Verifier<T>::verify2(&bound_func2<T>, &thing); 00406 Verifier<T>::verify2(&const_bound_func2<T>, (const Thing<T>*)&thing); 00407 Verifier<T>::verify2(&volatile_bound_func2<T>, (volatile Thing<T>*)&thing); 00408 Verifier<T>::verify2(&const_volatile_bound_func2<T>, (const volatile Thing<T>*)&thing); 00409 Verifier<T>::verify2(&bound_func2<T>, &thing2); 00410 Verifier<T>::verify2(&void_func2<T>, &thing); 00411 Verifier<T>::verify2(&const_void_func2<T>, (const Thing<T>*)&thing); 00412 Verifier<T>::verify2(&volatile_void_func2<T>, (volatile Thing<T>*)&thing); 00413 Verifier<T>::verify2(&const_volatile_void_func2<T>, (const volatile Thing<T>*)&thing); 00414 Verifier<T>::verify2(callback(static_func2<T>)); 00415 00416 Callback<T(T, T)> cb(static_func2); 00417 Verifier<T>::verify2(cb); 00418 cb = static_func2; 00419 Verifier<T>::verify2(cb); 00420 cb.attach(&bound_func2<T>, &thing); 00421 Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call); 00422 Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void*)&cb); 00423 } 00424 00425 template <typename T> 00426 void test_dispatch3() { 00427 Thing<T> thing; 00428 Thing2<T> thing2; 00429 Verifier<T>::verify3(static_func3<T>); 00430 Verifier<T>::verify3(&thing, &Thing<T>::member_func3); 00431 Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3); 00432 Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3); 00433 Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3); 00434 Verifier<T>::verify3(&thing2, &Thing2<T>::member_func3); 00435 Verifier<T>::verify3(&bound_func3<T>, &thing); 00436 Verifier<T>::verify3(&const_bound_func3<T>, (const Thing<T>*)&thing); 00437 Verifier<T>::verify3(&volatile_bound_func3<T>, (volatile Thing<T>*)&thing); 00438 Verifier<T>::verify3(&const_volatile_bound_func3<T>, (const volatile Thing<T>*)&thing); 00439 Verifier<T>::verify3(&bound_func3<T>, &thing2); 00440 Verifier<T>::verify3(&void_func3<T>, &thing); 00441 Verifier<T>::verify3(&const_void_func3<T>, (const Thing<T>*)&thing); 00442 Verifier<T>::verify3(&volatile_void_func3<T>, (volatile Thing<T>*)&thing); 00443 Verifier<T>::verify3(&const_volatile_void_func3<T>, (const volatile Thing<T>*)&thing); 00444 Verifier<T>::verify3(callback(static_func3<T>)); 00445 00446 Callback<T(T, T, T)> cb(static_func3); 00447 Verifier<T>::verify3(cb); 00448 cb = static_func3; 00449 Verifier<T>::verify3(cb); 00450 cb.attach(&bound_func3<T>, &thing); 00451 Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call); 00452 Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void*)&cb); 00453 } 00454 00455 template <typename T> 00456 void test_dispatch4() { 00457 Thing<T> thing; 00458 Thing2<T> thing2; 00459 Verifier<T>::verify4(static_func4<T>); 00460 Verifier<T>::verify4(&thing, &Thing<T>::member_func4); 00461 Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4); 00462 Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4); 00463 Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4); 00464 Verifier<T>::verify4(&thing2, &Thing2<T>::member_func4); 00465 Verifier<T>::verify4(&bound_func4<T>, &thing); 00466 Verifier<T>::verify4(&const_bound_func4<T>, (const Thing<T>*)&thing); 00467 Verifier<T>::verify4(&volatile_bound_func4<T>, (volatile Thing<T>*)&thing); 00468 Verifier<T>::verify4(&const_volatile_bound_func4<T>, (const volatile Thing<T>*)&thing); 00469 Verifier<T>::verify4(&bound_func4<T>, &thing2); 00470 Verifier<T>::verify4(&void_func4<T>, &thing); 00471 Verifier<T>::verify4(&const_void_func4<T>, (const Thing<T>*)&thing); 00472 Verifier<T>::verify4(&volatile_void_func4<T>, (volatile Thing<T>*)&thing); 00473 Verifier<T>::verify4(&const_volatile_void_func4<T>, (const volatile Thing<T>*)&thing); 00474 Verifier<T>::verify4(callback(static_func4<T>)); 00475 00476 Callback<T(T, T, T, T)> cb(static_func4); 00477 Verifier<T>::verify4(cb); 00478 cb = static_func4; 00479 Verifier<T>::verify4(cb); 00480 cb.attach(&bound_func4<T>, &thing); 00481 Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call); 00482 Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void*)&cb); 00483 } 00484 00485 template <typename T> 00486 void test_dispatch5() { 00487 Thing<T> thing; 00488 Thing2<T> thing2; 00489 Verifier<T>::verify5(static_func5<T>); 00490 Verifier<T>::verify5(&thing, &Thing<T>::member_func5); 00491 Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5); 00492 Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5); 00493 Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5); 00494 Verifier<T>::verify5(&thing2, &Thing2<T>::member_func5); 00495 Verifier<T>::verify5(&bound_func5<T>, &thing); 00496 Verifier<T>::verify5(&const_bound_func5<T>, (const Thing<T>*)&thing); 00497 Verifier<T>::verify5(&volatile_bound_func5<T>, (volatile Thing<T>*)&thing); 00498 Verifier<T>::verify5(&const_volatile_bound_func5<T>, (const volatile Thing<T>*)&thing); 00499 Verifier<T>::verify5(&bound_func5<T>, &thing2); 00500 Verifier<T>::verify5(&void_func5<T>, &thing); 00501 Verifier<T>::verify5(&const_void_func5<T>, (const Thing<T>*)&thing); 00502 Verifier<T>::verify5(&volatile_void_func5<T>, (volatile Thing<T>*)&thing); 00503 Verifier<T>::verify5(&const_volatile_void_func5<T>, (const volatile Thing<T>*)&thing); 00504 Verifier<T>::verify5(callback(static_func5<T>)); 00505 00506 Callback<T(T, T, T, T, T)> cb(static_func5); 00507 Verifier<T>::verify5(cb); 00508 cb = static_func5; 00509 Verifier<T>::verify5(cb); 00510 cb.attach(&bound_func5<T>, &thing); 00511 Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call); 00512 Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void*)&cb); 00513 } 00514 00515 00516 // Test setup 00517 utest::v1::status_t test_setup(const size_t number_of_cases) { 00518 GREENTEA_SETUP(10, "default_auto"); 00519 return verbose_test_setup_handler(number_of_cases); 00520 } 00521 00522 Case cases[] = { 00523 Case("Testing callbacks with 0 ints", test_dispatch0<int>), 00524 Case("Testing callbacks with 1 ints", test_dispatch1<int>), 00525 Case("Testing callbacks with 2 ints", test_dispatch2<int>), 00526 Case("Testing callbacks with 3 ints", test_dispatch3<int>), 00527 Case("Testing callbacks with 4 ints", test_dispatch4<int>), 00528 Case("Testing callbacks with 5 ints", test_dispatch5<int>), 00529 }; 00530 00531 Specification specification(test_setup, cases); 00532 00533 int main() { 00534 return !Harness::run(specification); 00535 }
Generated on Thu Jul 14 2022 14:36:19 by
