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.
Dependents: blinky_max32630fthr
main.cpp
00001 #include "mbed.h" 00002 #include "greentea-client/test_env.h" 00003 #include "unity.h" 00004 #include "utest.h" 00005 00006 using namespace utest::v1; 00007 00008 00009 // static functions 00010 template <typename T> 00011 T static_func0() 00012 { return 0; } 00013 template <typename T> 00014 T static_func1(T a0) 00015 { return 0 | a0; } 00016 template <typename T> 00017 T static_func2(T a0, T a1) 00018 { return 0 | a0 | a1; } 00019 template <typename T> 00020 T static_func3(T a0, T a1, T a2) 00021 { return 0 | a0 | a1 | a2; } 00022 template <typename T> 00023 T static_func4(T a0, T a1, T a2, T a3) 00024 { return 0 | a0 | a1 | a2 | a3; } 00025 template <typename T> 00026 T static_func5(T a0, T a1, T a2, T a3, T a4) 00027 { return 0 | a0 | a1 | a2 | a3 | a4; } 00028 00029 // class functions 00030 template <typename T> 00031 struct Thing { 00032 T t; 00033 Thing() : t(0x80) {} 00034 00035 T member_func0() 00036 { return t; } 00037 T member_func1(T a0) 00038 { return t | a0; } 00039 T member_func2(T a0, T a1) 00040 { return t | a0 | a1; } 00041 T member_func3(T a0, T a1, T a2) 00042 { return t | a0 | a1 | a2; } 00043 T member_func4(T a0, T a1, T a2, T a3) 00044 { return t | a0 | a1 | a2 | a3; } 00045 T member_func5(T a0, T a1, T a2, T a3, T a4) 00046 { return t | a0 | a1 | a2 | a3 | a4; } 00047 00048 T const_member_func0() const 00049 { return t; } 00050 T const_member_func1(T a0) const 00051 { return t | a0; } 00052 T const_member_func2(T a0, T a1) const 00053 { return t | a0 | a1; } 00054 T const_member_func3(T a0, T a1, T a2) const 00055 { return t | a0 | a1 | a2; } 00056 T const_member_func4(T a0, T a1, T a2, T a3) const 00057 { return t | a0 | a1 | a2 | a3; } 00058 T const_member_func5(T a0, T a1, T a2, T a3, T a4) const 00059 { return t | a0 | a1 | a2 | a3 | a4; } 00060 00061 T volatile_member_func0() volatile 00062 { return t; } 00063 T volatile_member_func1(T a0) volatile 00064 { return t | a0; } 00065 T volatile_member_func2(T a0, T a1) volatile 00066 { return t | a0 | a1; } 00067 T volatile_member_func3(T a0, T a1, T a2) volatile 00068 { return t | a0 | a1 | a2; } 00069 T volatile_member_func4(T a0, T a1, T a2, T a3) volatile 00070 { return t | a0 | a1 | a2 | a3; } 00071 T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile 00072 { return t | a0 | a1 | a2 | a3 | a4; } 00073 00074 T const_volatile_member_func0() const volatile 00075 { return t; } 00076 T const_volatile_member_func1(T a0) const volatile 00077 { return t | a0; } 00078 T const_volatile_member_func2(T a0, T a1) const volatile 00079 { return t | a0 | a1; } 00080 T const_volatile_member_func3(T a0, T a1, T a2) const volatile 00081 { return t | a0 | a1 | a2; } 00082 T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile 00083 { return t | a0 | a1 | a2 | a3; } 00084 T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile 00085 { return t | a0 | a1 | a2 | a3 | a4; } 00086 }; 00087 00088 // bound functions 00089 template <typename T> 00090 T bound_func0(Thing<T> *t) 00091 { return t->t; } 00092 template <typename T> 00093 T bound_func1(Thing<T> *t, T a0) 00094 { return t->t | a0; } 00095 template <typename T> 00096 T bound_func2(Thing<T> *t, T a0, T a1) 00097 { return t->t | a0 | a1; } 00098 template <typename T> 00099 T bound_func3(Thing<T> *t, T a0, T a1, T a2) 00100 { return t->t | a0 | a1 | a2; } 00101 template <typename T> 00102 T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) 00103 { return t->t | a0 | a1 | a2 | a3; } 00104 template <typename T> 00105 T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00106 { return t->t | a0 | a1 | a2 | a3 | a4; } 00107 template <typename T> 00108 T const_bound_func0(const Thing<T> *t) 00109 { return t->t; } 00110 template <typename T> 00111 T const_bound_func1(const Thing<T> *t, T a0) 00112 { return t->t | a0; } 00113 template <typename T> 00114 T const_bound_func2(const Thing<T> *t, T a0, T a1) 00115 { return t->t | a0 | a1; } 00116 template <typename T> 00117 T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2) 00118 { return t->t | a0 | a1 | a2; } 00119 template <typename T> 00120 T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) 00121 { return t->t | a0 | a1 | a2 | a3; } 00122 template <typename T> 00123 T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00124 { return t->t | a0 | a1 | a2 | a3 | a4; } 00125 template <typename T> 00126 T volatile_bound_func0(volatile Thing<T> *t) 00127 { return t->t; } 00128 template <typename T> 00129 T volatile_bound_func1(volatile Thing<T> *t, T a0) 00130 { return t->t | a0; } 00131 template <typename T> 00132 T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1) 00133 { return t->t | a0 | a1; } 00134 template <typename T> 00135 T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2) 00136 { return t->t | a0 | a1 | a2; } 00137 template <typename T> 00138 T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) 00139 { return t->t | a0 | a1 | a2 | a3; } 00140 template <typename T> 00141 T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00142 { return t->t | a0 | a1 | a2 | a3 | a4; } 00143 template <typename T> 00144 T const_volatile_bound_func0(const volatile Thing<T> *t) 00145 { return t->t; } 00146 template <typename T> 00147 T const_volatile_bound_func1(const volatile Thing<T> *t, T a0) 00148 { return t->t | a0; } 00149 template <typename T> 00150 T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1) 00151 { return t->t | a0 | a1; } 00152 template <typename T> 00153 T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2) 00154 { return t->t | a0 | a1 | a2; } 00155 template <typename T> 00156 T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) 00157 { return t->t | a0 | a1 | a2 | a3; } 00158 template <typename T> 00159 T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) 00160 { return t->t | a0 | a1 | a2 | a3 | a4; } 00161 00162 // void functions 00163 template <typename T> 00164 T void_func0(void *t) 00165 { return static_cast<Thing<T>*>(t)->t; } 00166 template <typename T> 00167 T void_func1(void *t, T a0) 00168 { return static_cast<Thing<T>*>(t)->t | a0; } 00169 template <typename T> 00170 T void_func2(void *t, T a0, T a1) 00171 { return static_cast<Thing<T>*>(t)->t | a0 | a1; } 00172 template <typename T> 00173 T void_func3(void *t, T a0, T a1, T a2) 00174 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; } 00175 template <typename T> 00176 T void_func4(void *t, T a0, T a1, T a2, T a3) 00177 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00178 template <typename T> 00179 T void_func5(void *t, T a0, T a1, T a2, T a3, T a4) 00180 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00181 template <typename T> 00182 T const_void_func0(const void *t) 00183 { return static_cast<const Thing<T>*>(t)->t; } 00184 template <typename T> 00185 T const_void_func1(const void *t, T a0) 00186 { return static_cast<const Thing<T>*>(t)->t | a0; } 00187 template <typename T> 00188 T const_void_func2(const void *t, T a0, T a1) 00189 { return static_cast<const Thing<T>*>(t)->t | a0 | a1; } 00190 template <typename T> 00191 T const_void_func3(const void *t, T a0, T a1, T a2) 00192 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; } 00193 template <typename T> 00194 T const_void_func4(const void *t, T a0, T a1, T a2, T a3) 00195 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00196 template <typename T> 00197 T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4) 00198 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00199 template <typename T> 00200 T volatile_void_func0(volatile void *t) 00201 { return static_cast<volatile Thing<T>*>(t)->t; } 00202 template <typename T> 00203 T volatile_void_func1(volatile void *t, T a0) 00204 { return static_cast<volatile Thing<T>*>(t)->t | a0; } 00205 template <typename T> 00206 T volatile_void_func2(volatile void *t, T a0, T a1) 00207 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; } 00208 template <typename T> 00209 T volatile_void_func3(volatile void *t, T a0, T a1, T a2) 00210 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; } 00211 template <typename T> 00212 T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3) 00213 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00214 template <typename T> 00215 T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4) 00216 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00217 template <typename T> 00218 T const_volatile_void_func0(const volatile void *t) 00219 { return static_cast<const volatile Thing<T>*>(t)->t; } 00220 template <typename T> 00221 T const_volatile_void_func1(const volatile void *t, T a0) 00222 { return static_cast<const volatile Thing<T>*>(t)->t | a0; } 00223 template <typename T> 00224 T const_volatile_void_func2(const volatile void *t, T a0, T a1) 00225 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; } 00226 template <typename T> 00227 T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2) 00228 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; } 00229 template <typename T> 00230 T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3) 00231 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } 00232 template <typename T> 00233 T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4) 00234 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } 00235 00236 00237 // function call and result verification 00238 template <typename T> 00239 struct Verifier { 00240 static void verify0(Callback<T()> func) { 00241 T result = func(); 00242 TEST_ASSERT_EQUAL(result, 0x00); 00243 } 00244 00245 template <typename O, typename M> 00246 static void verify0(O *obj, M method) { 00247 Callback<T()> func(obj, method); 00248 T result = func(); 00249 TEST_ASSERT_EQUAL(result, 0x80); 00250 } 00251 00252 static void verify1(Callback<T(T)> func) { 00253 T result = func((1 << 0)); 00254 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); 00255 } 00256 00257 template <typename O, typename M> 00258 static void verify1(O *obj, M method) { 00259 Callback<T(T)> func(obj, method); 00260 T result = func((1 << 0)); 00261 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); 00262 } 00263 00264 static void verify2(Callback<T(T, T)> func) { 00265 T result = func((1 << 0), (1 << 1)); 00266 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); 00267 } 00268 00269 template <typename O, typename M> 00270 static void verify2(O *obj, M method) { 00271 Callback<T(T, T)> func(obj, method); 00272 T result = func((1 << 0), (1 << 1)); 00273 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); 00274 } 00275 00276 static void verify3(Callback<T(T, T, T)> func) { 00277 T result = func((1 << 0), (1 << 1), (1 << 2)); 00278 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); 00279 } 00280 00281 template <typename O, typename M> 00282 static void verify3(O *obj, M method) { 00283 Callback<T(T, T, T)> func(obj, method); 00284 T result = func((1 << 0), (1 << 1), (1 << 2)); 00285 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); 00286 } 00287 00288 static void verify4(Callback<T(T, T, T, T)> func) { 00289 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); 00290 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); 00291 } 00292 00293 template <typename O, typename M> 00294 static void verify4(O *obj, M method) { 00295 Callback<T(T, T, T, T)> func(obj, method); 00296 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); 00297 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); 00298 } 00299 00300 static void verify5(Callback<T(T, T, T, T, T)> func) { 00301 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); 00302 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); 00303 } 00304 00305 template <typename O, typename M> 00306 static void verify5(O *obj, M method) { 00307 Callback<T(T, T, T, T, T)> func(obj, method); 00308 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); 00309 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); 00310 } 00311 }; 00312 00313 00314 // test dispatch 00315 template <typename T> 00316 void test_fparg1() { 00317 Thing<T> thing; 00318 FunctionPointerArg1<T,T> fp(static_func1<T>); 00319 Verifier<T>::verify1(fp); 00320 Verifier<T>::verify1(fp.get_function()); 00321 } 00322 00323 template <typename T> 00324 void test_fparg0() { 00325 Thing<T> thing; 00326 FunctionPointerArg1<T,void> fp(static_func0<T>); 00327 Verifier<T>::verify0(fp); 00328 Verifier<T>::verify0(fp.get_function()); 00329 } 00330 00331 00332 // Test setup 00333 utest::v1::status_t test_setup(const size_t number_of_cases) { 00334 GREENTEA_SETUP(10, "default_auto"); 00335 return verbose_test_setup_handler(number_of_cases); 00336 } 00337 00338 Case cases[] = { 00339 Case("Testing FunctionPointerArg1 compatibility", test_fparg1<int>), 00340 Case("Testing FunctionPointer compatibility", test_fparg0<int>), 00341 }; 00342 00343 Specification specification(test_setup, cases); 00344 00345 int main() { 00346 return !Harness::run(specification); 00347 }
Generated on Tue Jul 12 2022 14:21:14 by
1.7.2
