Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:0e018d759a2a 1 #include "mbed.h"
switches 0:0e018d759a2a 2 #include "greentea-client/test_env.h"
switches 0:0e018d759a2a 3 #include "unity.h"
switches 0:0e018d759a2a 4 #include "utest.h"
switches 0:0e018d759a2a 5
switches 0:0e018d759a2a 6 using namespace utest::v1;
switches 0:0e018d759a2a 7
switches 0:0e018d759a2a 8
switches 0:0e018d759a2a 9 // static functions
switches 0:0e018d759a2a 10 template <typename T>
switches 0:0e018d759a2a 11 T static_func0()
switches 0:0e018d759a2a 12 { return 0; }
switches 0:0e018d759a2a 13 template <typename T>
switches 0:0e018d759a2a 14 T static_func1(T a0)
switches 0:0e018d759a2a 15 { return 0 | a0; }
switches 0:0e018d759a2a 16 template <typename T>
switches 0:0e018d759a2a 17 T static_func2(T a0, T a1)
switches 0:0e018d759a2a 18 { return 0 | a0 | a1; }
switches 0:0e018d759a2a 19 template <typename T>
switches 0:0e018d759a2a 20 T static_func3(T a0, T a1, T a2)
switches 0:0e018d759a2a 21 { return 0 | a0 | a1 | a2; }
switches 0:0e018d759a2a 22 template <typename T>
switches 0:0e018d759a2a 23 T static_func4(T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 24 { return 0 | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 25 template <typename T>
switches 0:0e018d759a2a 26 T static_func5(T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 27 { return 0 | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 28
switches 0:0e018d759a2a 29 // class functions
switches 0:0e018d759a2a 30 template <typename T>
switches 0:0e018d759a2a 31 struct Thing {
switches 0:0e018d759a2a 32 T t;
switches 0:0e018d759a2a 33 Thing() : t(0x80) {}
switches 0:0e018d759a2a 34
switches 0:0e018d759a2a 35 T member_func0()
switches 0:0e018d759a2a 36 { return t; }
switches 0:0e018d759a2a 37 T member_func1(T a0)
switches 0:0e018d759a2a 38 { return t | a0; }
switches 0:0e018d759a2a 39 T member_func2(T a0, T a1)
switches 0:0e018d759a2a 40 { return t | a0 | a1; }
switches 0:0e018d759a2a 41 T member_func3(T a0, T a1, T a2)
switches 0:0e018d759a2a 42 { return t | a0 | a1 | a2; }
switches 0:0e018d759a2a 43 T member_func4(T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 44 { return t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 45 T member_func5(T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 46 { return t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 47
switches 0:0e018d759a2a 48 T const_member_func0() const
switches 0:0e018d759a2a 49 { return t; }
switches 0:0e018d759a2a 50 T const_member_func1(T a0) const
switches 0:0e018d759a2a 51 { return t | a0; }
switches 0:0e018d759a2a 52 T const_member_func2(T a0, T a1) const
switches 0:0e018d759a2a 53 { return t | a0 | a1; }
switches 0:0e018d759a2a 54 T const_member_func3(T a0, T a1, T a2) const
switches 0:0e018d759a2a 55 { return t | a0 | a1 | a2; }
switches 0:0e018d759a2a 56 T const_member_func4(T a0, T a1, T a2, T a3) const
switches 0:0e018d759a2a 57 { return t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 58 T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
switches 0:0e018d759a2a 59 { return t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 60
switches 0:0e018d759a2a 61 T volatile_member_func0() volatile
switches 0:0e018d759a2a 62 { return t; }
switches 0:0e018d759a2a 63 T volatile_member_func1(T a0) volatile
switches 0:0e018d759a2a 64 { return t | a0; }
switches 0:0e018d759a2a 65 T volatile_member_func2(T a0, T a1) volatile
switches 0:0e018d759a2a 66 { return t | a0 | a1; }
switches 0:0e018d759a2a 67 T volatile_member_func3(T a0, T a1, T a2) volatile
switches 0:0e018d759a2a 68 { return t | a0 | a1 | a2; }
switches 0:0e018d759a2a 69 T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
switches 0:0e018d759a2a 70 { return t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 71 T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
switches 0:0e018d759a2a 72 { return t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 73
switches 0:0e018d759a2a 74 T const_volatile_member_func0() const volatile
switches 0:0e018d759a2a 75 { return t; }
switches 0:0e018d759a2a 76 T const_volatile_member_func1(T a0) const volatile
switches 0:0e018d759a2a 77 { return t | a0; }
switches 0:0e018d759a2a 78 T const_volatile_member_func2(T a0, T a1) const volatile
switches 0:0e018d759a2a 79 { return t | a0 | a1; }
switches 0:0e018d759a2a 80 T const_volatile_member_func3(T a0, T a1, T a2) const volatile
switches 0:0e018d759a2a 81 { return t | a0 | a1 | a2; }
switches 0:0e018d759a2a 82 T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
switches 0:0e018d759a2a 83 { return t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 84 T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
switches 0:0e018d759a2a 85 { return t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 86 };
switches 0:0e018d759a2a 87
switches 0:0e018d759a2a 88 // bound functions
switches 0:0e018d759a2a 89 template <typename T>
switches 0:0e018d759a2a 90 T bound_func0(Thing<T> *t)
switches 0:0e018d759a2a 91 { return t->t; }
switches 0:0e018d759a2a 92 template <typename T>
switches 0:0e018d759a2a 93 T bound_func1(Thing<T> *t, T a0)
switches 0:0e018d759a2a 94 { return t->t | a0; }
switches 0:0e018d759a2a 95 template <typename T>
switches 0:0e018d759a2a 96 T bound_func2(Thing<T> *t, T a0, T a1)
switches 0:0e018d759a2a 97 { return t->t | a0 | a1; }
switches 0:0e018d759a2a 98 template <typename T>
switches 0:0e018d759a2a 99 T bound_func3(Thing<T> *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 100 { return t->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 101 template <typename T>
switches 0:0e018d759a2a 102 T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 103 { return t->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 104 template <typename T>
switches 0:0e018d759a2a 105 T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 106 { return t->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 107 template <typename T>
switches 0:0e018d759a2a 108 T const_bound_func0(const Thing<T> *t)
switches 0:0e018d759a2a 109 { return t->t; }
switches 0:0e018d759a2a 110 template <typename T>
switches 0:0e018d759a2a 111 T const_bound_func1(const Thing<T> *t, T a0)
switches 0:0e018d759a2a 112 { return t->t | a0; }
switches 0:0e018d759a2a 113 template <typename T>
switches 0:0e018d759a2a 114 T const_bound_func2(const Thing<T> *t, T a0, T a1)
switches 0:0e018d759a2a 115 { return t->t | a0 | a1; }
switches 0:0e018d759a2a 116 template <typename T>
switches 0:0e018d759a2a 117 T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 118 { return t->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 119 template <typename T>
switches 0:0e018d759a2a 120 T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 121 { return t->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 122 template <typename T>
switches 0:0e018d759a2a 123 T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 124 { return t->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 125 template <typename T>
switches 0:0e018d759a2a 126 T volatile_bound_func0(volatile Thing<T> *t)
switches 0:0e018d759a2a 127 { return t->t; }
switches 0:0e018d759a2a 128 template <typename T>
switches 0:0e018d759a2a 129 T volatile_bound_func1(volatile Thing<T> *t, T a0)
switches 0:0e018d759a2a 130 { return t->t | a0; }
switches 0:0e018d759a2a 131 template <typename T>
switches 0:0e018d759a2a 132 T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1)
switches 0:0e018d759a2a 133 { return t->t | a0 | a1; }
switches 0:0e018d759a2a 134 template <typename T>
switches 0:0e018d759a2a 135 T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 136 { return t->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 137 template <typename T>
switches 0:0e018d759a2a 138 T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 139 { return t->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 140 template <typename T>
switches 0:0e018d759a2a 141 T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 142 { return t->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 143 template <typename T>
switches 0:0e018d759a2a 144 T const_volatile_bound_func0(const volatile Thing<T> *t)
switches 0:0e018d759a2a 145 { return t->t; }
switches 0:0e018d759a2a 146 template <typename T>
switches 0:0e018d759a2a 147 T const_volatile_bound_func1(const volatile Thing<T> *t, T a0)
switches 0:0e018d759a2a 148 { return t->t | a0; }
switches 0:0e018d759a2a 149 template <typename T>
switches 0:0e018d759a2a 150 T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1)
switches 0:0e018d759a2a 151 { return t->t | a0 | a1; }
switches 0:0e018d759a2a 152 template <typename T>
switches 0:0e018d759a2a 153 T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 154 { return t->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 155 template <typename T>
switches 0:0e018d759a2a 156 T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 157 { return t->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 158 template <typename T>
switches 0:0e018d759a2a 159 T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 160 { return t->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 161
switches 0:0e018d759a2a 162 // void functions
switches 0:0e018d759a2a 163 template <typename T>
switches 0:0e018d759a2a 164 T void_func0(void *t)
switches 0:0e018d759a2a 165 { return static_cast<Thing<T>*>(t)->t; }
switches 0:0e018d759a2a 166 template <typename T>
switches 0:0e018d759a2a 167 T void_func1(void *t, T a0)
switches 0:0e018d759a2a 168 { return static_cast<Thing<T>*>(t)->t | a0; }
switches 0:0e018d759a2a 169 template <typename T>
switches 0:0e018d759a2a 170 T void_func2(void *t, T a0, T a1)
switches 0:0e018d759a2a 171 { return static_cast<Thing<T>*>(t)->t | a0 | a1; }
switches 0:0e018d759a2a 172 template <typename T>
switches 0:0e018d759a2a 173 T void_func3(void *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 174 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 175 template <typename T>
switches 0:0e018d759a2a 176 T void_func4(void *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 177 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 178 template <typename T>
switches 0:0e018d759a2a 179 T void_func5(void *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 180 { return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 181 template <typename T>
switches 0:0e018d759a2a 182 T const_void_func0(const void *t)
switches 0:0e018d759a2a 183 { return static_cast<const Thing<T>*>(t)->t; }
switches 0:0e018d759a2a 184 template <typename T>
switches 0:0e018d759a2a 185 T const_void_func1(const void *t, T a0)
switches 0:0e018d759a2a 186 { return static_cast<const Thing<T>*>(t)->t | a0; }
switches 0:0e018d759a2a 187 template <typename T>
switches 0:0e018d759a2a 188 T const_void_func2(const void *t, T a0, T a1)
switches 0:0e018d759a2a 189 { return static_cast<const Thing<T>*>(t)->t | a0 | a1; }
switches 0:0e018d759a2a 190 template <typename T>
switches 0:0e018d759a2a 191 T const_void_func3(const void *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 192 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 193 template <typename T>
switches 0:0e018d759a2a 194 T const_void_func4(const void *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 195 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 196 template <typename T>
switches 0:0e018d759a2a 197 T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 198 { return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 199 template <typename T>
switches 0:0e018d759a2a 200 T volatile_void_func0(volatile void *t)
switches 0:0e018d759a2a 201 { return static_cast<volatile Thing<T>*>(t)->t; }
switches 0:0e018d759a2a 202 template <typename T>
switches 0:0e018d759a2a 203 T volatile_void_func1(volatile void *t, T a0)
switches 0:0e018d759a2a 204 { return static_cast<volatile Thing<T>*>(t)->t | a0; }
switches 0:0e018d759a2a 205 template <typename T>
switches 0:0e018d759a2a 206 T volatile_void_func2(volatile void *t, T a0, T a1)
switches 0:0e018d759a2a 207 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; }
switches 0:0e018d759a2a 208 template <typename T>
switches 0:0e018d759a2a 209 T volatile_void_func3(volatile void *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 210 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 211 template <typename T>
switches 0:0e018d759a2a 212 T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 213 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 214 template <typename T>
switches 0:0e018d759a2a 215 T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 216 { return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 217 template <typename T>
switches 0:0e018d759a2a 218 T const_volatile_void_func0(const volatile void *t)
switches 0:0e018d759a2a 219 { return static_cast<const volatile Thing<T>*>(t)->t; }
switches 0:0e018d759a2a 220 template <typename T>
switches 0:0e018d759a2a 221 T const_volatile_void_func1(const volatile void *t, T a0)
switches 0:0e018d759a2a 222 { return static_cast<const volatile Thing<T>*>(t)->t | a0; }
switches 0:0e018d759a2a 223 template <typename T>
switches 0:0e018d759a2a 224 T const_volatile_void_func2(const volatile void *t, T a0, T a1)
switches 0:0e018d759a2a 225 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; }
switches 0:0e018d759a2a 226 template <typename T>
switches 0:0e018d759a2a 227 T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2)
switches 0:0e018d759a2a 228 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; }
switches 0:0e018d759a2a 229 template <typename T>
switches 0:0e018d759a2a 230 T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3)
switches 0:0e018d759a2a 231 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
switches 0:0e018d759a2a 232 template <typename T>
switches 0:0e018d759a2a 233 T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4)
switches 0:0e018d759a2a 234 { return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
switches 0:0e018d759a2a 235
switches 0:0e018d759a2a 236
switches 0:0e018d759a2a 237 // function call and result verification
switches 0:0e018d759a2a 238 template <typename T>
switches 0:0e018d759a2a 239 struct Verifier {
switches 0:0e018d759a2a 240 static void verify0(Callback<T()> func) {
switches 0:0e018d759a2a 241 T result = func();
switches 0:0e018d759a2a 242 TEST_ASSERT_EQUAL(result, 0x00);
switches 0:0e018d759a2a 243 }
switches 0:0e018d759a2a 244
switches 0:0e018d759a2a 245 template <typename O, typename M>
switches 0:0e018d759a2a 246 static void verify0(O *obj, M method) {
switches 0:0e018d759a2a 247 Callback<T()> func(obj, method);
switches 0:0e018d759a2a 248 T result = func();
switches 0:0e018d759a2a 249 TEST_ASSERT_EQUAL(result, 0x80);
switches 0:0e018d759a2a 250 }
switches 0:0e018d759a2a 251
switches 0:0e018d759a2a 252 static void verify1(Callback<T(T)> func) {
switches 0:0e018d759a2a 253 T result = func((1 << 0));
switches 0:0e018d759a2a 254 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
switches 0:0e018d759a2a 255 }
switches 0:0e018d759a2a 256
switches 0:0e018d759a2a 257 template <typename O, typename M>
switches 0:0e018d759a2a 258 static void verify1(O *obj, M method) {
switches 0:0e018d759a2a 259 Callback<T(T)> func(obj, method);
switches 0:0e018d759a2a 260 T result = func((1 << 0));
switches 0:0e018d759a2a 261 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
switches 0:0e018d759a2a 262 }
switches 0:0e018d759a2a 263
switches 0:0e018d759a2a 264 static void verify2(Callback<T(T, T)> func) {
switches 0:0e018d759a2a 265 T result = func((1 << 0), (1 << 1));
switches 0:0e018d759a2a 266 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
switches 0:0e018d759a2a 267 }
switches 0:0e018d759a2a 268
switches 0:0e018d759a2a 269 template <typename O, typename M>
switches 0:0e018d759a2a 270 static void verify2(O *obj, M method) {
switches 0:0e018d759a2a 271 Callback<T(T, T)> func(obj, method);
switches 0:0e018d759a2a 272 T result = func((1 << 0), (1 << 1));
switches 0:0e018d759a2a 273 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
switches 0:0e018d759a2a 274 }
switches 0:0e018d759a2a 275
switches 0:0e018d759a2a 276 static void verify3(Callback<T(T, T, T)> func) {
switches 0:0e018d759a2a 277 T result = func((1 << 0), (1 << 1), (1 << 2));
switches 0:0e018d759a2a 278 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
switches 0:0e018d759a2a 279 }
switches 0:0e018d759a2a 280
switches 0:0e018d759a2a 281 template <typename O, typename M>
switches 0:0e018d759a2a 282 static void verify3(O *obj, M method) {
switches 0:0e018d759a2a 283 Callback<T(T, T, T)> func(obj, method);
switches 0:0e018d759a2a 284 T result = func((1 << 0), (1 << 1), (1 << 2));
switches 0:0e018d759a2a 285 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
switches 0:0e018d759a2a 286 }
switches 0:0e018d759a2a 287
switches 0:0e018d759a2a 288 static void verify4(Callback<T(T, T, T, T)> func) {
switches 0:0e018d759a2a 289 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
switches 0:0e018d759a2a 290 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
switches 0:0e018d759a2a 291 }
switches 0:0e018d759a2a 292
switches 0:0e018d759a2a 293 template <typename O, typename M>
switches 0:0e018d759a2a 294 static void verify4(O *obj, M method) {
switches 0:0e018d759a2a 295 Callback<T(T, T, T, T)> func(obj, method);
switches 0:0e018d759a2a 296 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
switches 0:0e018d759a2a 297 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
switches 0:0e018d759a2a 298 }
switches 0:0e018d759a2a 299
switches 0:0e018d759a2a 300 static void verify5(Callback<T(T, T, T, T, T)> func) {
switches 0:0e018d759a2a 301 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
switches 0:0e018d759a2a 302 TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
switches 0:0e018d759a2a 303 }
switches 0:0e018d759a2a 304
switches 0:0e018d759a2a 305 template <typename O, typename M>
switches 0:0e018d759a2a 306 static void verify5(O *obj, M method) {
switches 0:0e018d759a2a 307 Callback<T(T, T, T, T, T)> func(obj, method);
switches 0:0e018d759a2a 308 T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
switches 0:0e018d759a2a 309 TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
switches 0:0e018d759a2a 310 }
switches 0:0e018d759a2a 311 };
switches 0:0e018d759a2a 312
switches 0:0e018d759a2a 313
switches 0:0e018d759a2a 314 // test dispatch
switches 0:0e018d759a2a 315 template <typename T>
switches 0:0e018d759a2a 316 void test_dispatch0() {
switches 0:0e018d759a2a 317 Thing<T> thing;
switches 0:0e018d759a2a 318 Verifier<T>::verify0(static_func0<T>);
switches 0:0e018d759a2a 319 Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
switches 0:0e018d759a2a 320 Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0);
switches 0:0e018d759a2a 321 Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0);
switches 0:0e018d759a2a 322 Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0);
switches 0:0e018d759a2a 323 Verifier<T>::verify0(&bound_func0<T>, &thing);
switches 0:0e018d759a2a 324 Verifier<T>::verify0(&const_bound_func0<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 325 Verifier<T>::verify0(&volatile_bound_func0<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 326 Verifier<T>::verify0(&const_volatile_bound_func0<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 327 Verifier<T>::verify0(&void_func0<T>, &thing);
switches 0:0e018d759a2a 328 Verifier<T>::verify0(&const_void_func0<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 329 Verifier<T>::verify0(&volatile_void_func0<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 330 Verifier<T>::verify0(&const_volatile_void_func0<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 331 Verifier<T>::verify0(callback(static_func0<T>));
switches 0:0e018d759a2a 332
switches 0:0e018d759a2a 333 Callback<T()> cb(static_func0);
switches 0:0e018d759a2a 334 Verifier<T>::verify0(cb);
switches 0:0e018d759a2a 335 cb = static_func0;
switches 0:0e018d759a2a 336 Verifier<T>::verify0(cb);
switches 0:0e018d759a2a 337 cb.attach(&bound_func0<T>, &thing);
switches 0:0e018d759a2a 338 Verifier<T>::verify0(&cb, &Callback<T()>::call);
switches 0:0e018d759a2a 339 Verifier<T>::verify0(&Callback<T()>::thunk, (void*)&cb);
switches 0:0e018d759a2a 340 }
switches 0:0e018d759a2a 341
switches 0:0e018d759a2a 342 template <typename T>
switches 0:0e018d759a2a 343 void test_dispatch1() {
switches 0:0e018d759a2a 344 Thing<T> thing;
switches 0:0e018d759a2a 345 Verifier<T>::verify1(static_func1<T>);
switches 0:0e018d759a2a 346 Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
switches 0:0e018d759a2a 347 Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1);
switches 0:0e018d759a2a 348 Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1);
switches 0:0e018d759a2a 349 Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1);
switches 0:0e018d759a2a 350 Verifier<T>::verify1(&bound_func1<T>, &thing);
switches 0:0e018d759a2a 351 Verifier<T>::verify1(&const_bound_func1<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 352 Verifier<T>::verify1(&volatile_bound_func1<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 353 Verifier<T>::verify1(&const_volatile_bound_func1<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 354 Verifier<T>::verify1(&void_func1<T>, &thing);
switches 0:0e018d759a2a 355 Verifier<T>::verify1(&const_void_func1<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 356 Verifier<T>::verify1(&volatile_void_func1<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 357 Verifier<T>::verify1(&const_volatile_void_func1<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 358 Verifier<T>::verify1(callback(static_func1<T>));
switches 0:0e018d759a2a 359
switches 0:0e018d759a2a 360 Callback<T(T)> cb(static_func1);
switches 0:0e018d759a2a 361 Verifier<T>::verify1(cb);
switches 0:0e018d759a2a 362 cb = static_func1;
switches 0:0e018d759a2a 363 Verifier<T>::verify1(cb);
switches 0:0e018d759a2a 364 cb.attach(&bound_func1<T>, &thing);
switches 0:0e018d759a2a 365 Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
switches 0:0e018d759a2a 366 Verifier<T>::verify1(&Callback<T(T)>::thunk, (void*)&cb);
switches 0:0e018d759a2a 367 }
switches 0:0e018d759a2a 368
switches 0:0e018d759a2a 369 template <typename T>
switches 0:0e018d759a2a 370 void test_dispatch2() {
switches 0:0e018d759a2a 371 Thing<T> thing;
switches 0:0e018d759a2a 372 Verifier<T>::verify2(static_func2<T>);
switches 0:0e018d759a2a 373 Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
switches 0:0e018d759a2a 374 Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2);
switches 0:0e018d759a2a 375 Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2);
switches 0:0e018d759a2a 376 Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2);
switches 0:0e018d759a2a 377 Verifier<T>::verify2(&bound_func2<T>, &thing);
switches 0:0e018d759a2a 378 Verifier<T>::verify2(&const_bound_func2<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 379 Verifier<T>::verify2(&volatile_bound_func2<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 380 Verifier<T>::verify2(&const_volatile_bound_func2<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 381 Verifier<T>::verify2(&void_func2<T>, &thing);
switches 0:0e018d759a2a 382 Verifier<T>::verify2(&const_void_func2<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 383 Verifier<T>::verify2(&volatile_void_func2<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 384 Verifier<T>::verify2(&const_volatile_void_func2<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 385 Verifier<T>::verify2(callback(static_func2<T>));
switches 0:0e018d759a2a 386
switches 0:0e018d759a2a 387 Callback<T(T, T)> cb(static_func2);
switches 0:0e018d759a2a 388 Verifier<T>::verify2(cb);
switches 0:0e018d759a2a 389 cb = static_func2;
switches 0:0e018d759a2a 390 Verifier<T>::verify2(cb);
switches 0:0e018d759a2a 391 cb.attach(&bound_func2<T>, &thing);
switches 0:0e018d759a2a 392 Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
switches 0:0e018d759a2a 393 Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void*)&cb);
switches 0:0e018d759a2a 394 }
switches 0:0e018d759a2a 395
switches 0:0e018d759a2a 396 template <typename T>
switches 0:0e018d759a2a 397 void test_dispatch3() {
switches 0:0e018d759a2a 398 Thing<T> thing;
switches 0:0e018d759a2a 399 Verifier<T>::verify3(static_func3<T>);
switches 0:0e018d759a2a 400 Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
switches 0:0e018d759a2a 401 Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3);
switches 0:0e018d759a2a 402 Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3);
switches 0:0e018d759a2a 403 Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3);
switches 0:0e018d759a2a 404 Verifier<T>::verify3(&bound_func3<T>, &thing);
switches 0:0e018d759a2a 405 Verifier<T>::verify3(&const_bound_func3<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 406 Verifier<T>::verify3(&volatile_bound_func3<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 407 Verifier<T>::verify3(&const_volatile_bound_func3<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 408 Verifier<T>::verify3(&void_func3<T>, &thing);
switches 0:0e018d759a2a 409 Verifier<T>::verify3(&const_void_func3<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 410 Verifier<T>::verify3(&volatile_void_func3<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 411 Verifier<T>::verify3(&const_volatile_void_func3<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 412 Verifier<T>::verify3(callback(static_func3<T>));
switches 0:0e018d759a2a 413
switches 0:0e018d759a2a 414 Callback<T(T, T, T)> cb(static_func3);
switches 0:0e018d759a2a 415 Verifier<T>::verify3(cb);
switches 0:0e018d759a2a 416 cb = static_func3;
switches 0:0e018d759a2a 417 Verifier<T>::verify3(cb);
switches 0:0e018d759a2a 418 cb.attach(&bound_func3<T>, &thing);
switches 0:0e018d759a2a 419 Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
switches 0:0e018d759a2a 420 Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void*)&cb);
switches 0:0e018d759a2a 421 }
switches 0:0e018d759a2a 422
switches 0:0e018d759a2a 423 template <typename T>
switches 0:0e018d759a2a 424 void test_dispatch4() {
switches 0:0e018d759a2a 425 Thing<T> thing;
switches 0:0e018d759a2a 426 Verifier<T>::verify4(static_func4<T>);
switches 0:0e018d759a2a 427 Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
switches 0:0e018d759a2a 428 Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4);
switches 0:0e018d759a2a 429 Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4);
switches 0:0e018d759a2a 430 Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4);
switches 0:0e018d759a2a 431 Verifier<T>::verify4(&bound_func4<T>, &thing);
switches 0:0e018d759a2a 432 Verifier<T>::verify4(&const_bound_func4<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 433 Verifier<T>::verify4(&volatile_bound_func4<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 434 Verifier<T>::verify4(&const_volatile_bound_func4<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 435 Verifier<T>::verify4(&void_func4<T>, &thing);
switches 0:0e018d759a2a 436 Verifier<T>::verify4(&const_void_func4<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 437 Verifier<T>::verify4(&volatile_void_func4<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 438 Verifier<T>::verify4(&const_volatile_void_func4<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 439 Verifier<T>::verify4(callback(static_func4<T>));
switches 0:0e018d759a2a 440
switches 0:0e018d759a2a 441 Callback<T(T, T, T, T)> cb(static_func4);
switches 0:0e018d759a2a 442 Verifier<T>::verify4(cb);
switches 0:0e018d759a2a 443 cb = static_func4;
switches 0:0e018d759a2a 444 Verifier<T>::verify4(cb);
switches 0:0e018d759a2a 445 cb.attach(&bound_func4<T>, &thing);
switches 0:0e018d759a2a 446 Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
switches 0:0e018d759a2a 447 Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void*)&cb);
switches 0:0e018d759a2a 448 }
switches 0:0e018d759a2a 449
switches 0:0e018d759a2a 450 template <typename T>
switches 0:0e018d759a2a 451 void test_dispatch5() {
switches 0:0e018d759a2a 452 Thing<T> thing;
switches 0:0e018d759a2a 453 Verifier<T>::verify5(static_func5<T>);
switches 0:0e018d759a2a 454 Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
switches 0:0e018d759a2a 455 Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5);
switches 0:0e018d759a2a 456 Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5);
switches 0:0e018d759a2a 457 Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5);
switches 0:0e018d759a2a 458 Verifier<T>::verify5(&bound_func5<T>, &thing);
switches 0:0e018d759a2a 459 Verifier<T>::verify5(&const_bound_func5<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 460 Verifier<T>::verify5(&volatile_bound_func5<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 461 Verifier<T>::verify5(&const_volatile_bound_func5<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 462 Verifier<T>::verify5(&void_func5<T>, &thing);
switches 0:0e018d759a2a 463 Verifier<T>::verify5(&const_void_func5<T>, (const Thing<T>*)&thing);
switches 0:0e018d759a2a 464 Verifier<T>::verify5(&volatile_void_func5<T>, (volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 465 Verifier<T>::verify5(&const_volatile_void_func5<T>, (const volatile Thing<T>*)&thing);
switches 0:0e018d759a2a 466 Verifier<T>::verify5(callback(static_func5<T>));
switches 0:0e018d759a2a 467
switches 0:0e018d759a2a 468 Callback<T(T, T, T, T, T)> cb(static_func5);
switches 0:0e018d759a2a 469 Verifier<T>::verify5(cb);
switches 0:0e018d759a2a 470 cb = static_func5;
switches 0:0e018d759a2a 471 Verifier<T>::verify5(cb);
switches 0:0e018d759a2a 472 cb.attach(&bound_func5<T>, &thing);
switches 0:0e018d759a2a 473 Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
switches 0:0e018d759a2a 474 Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void*)&cb);
switches 0:0e018d759a2a 475 }
switches 0:0e018d759a2a 476
switches 0:0e018d759a2a 477
switches 0:0e018d759a2a 478 // Test setup
switches 0:0e018d759a2a 479 utest::v1::status_t test_setup(const size_t number_of_cases) {
switches 0:0e018d759a2a 480 GREENTEA_SETUP(10, "default_auto");
switches 0:0e018d759a2a 481 return verbose_test_setup_handler(number_of_cases);
switches 0:0e018d759a2a 482 }
switches 0:0e018d759a2a 483
switches 0:0e018d759a2a 484 Case cases[] = {
switches 0:0e018d759a2a 485 Case("Testing callbacks with 0 ints", test_dispatch0<int>),
switches 0:0e018d759a2a 486 Case("Testing callbacks with 1 ints", test_dispatch1<int>),
switches 0:0e018d759a2a 487 Case("Testing callbacks with 2 ints", test_dispatch2<int>),
switches 0:0e018d759a2a 488 Case("Testing callbacks with 3 ints", test_dispatch3<int>),
switches 0:0e018d759a2a 489 Case("Testing callbacks with 4 ints", test_dispatch4<int>),
switches 0:0e018d759a2a 490 Case("Testing callbacks with 5 ints", test_dispatch5<int>),
switches 0:0e018d759a2a 491 };
switches 0:0e018d759a2a 492
switches 0:0e018d759a2a 493 Specification specification(test_setup, cases);
switches 0:0e018d759a2a 494
switches 0:0e018d759a2a 495 int main() {
switches 0:0e018d759a2a 496 return !Harness::run(specification);
switches 0:0e018d759a2a 497 }