]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/mbed/cpp/main.cpp
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / mbed / cpp / main.cpp
1 #include "test_env.h"
2
3 #define PATTERN_CHECK_VALUE 0xF0F0ADAD
4
5 class Test {
6
7 private:
8 const char* name;
9 const int pattern;
10
11 public:
12 Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
13 print("init");
14 }
15
16 void print(const char *message) {
17 printf("%s::%s\n", name, message);
18 }
19
20 bool check_init(void) {
21 bool result = (pattern == PATTERN_CHECK_VALUE);
22 print(result ? "check_init: OK" : "check_init: ERROR");
23 return result;
24 }
25
26 void stack_test(void) {
27 print("stack_test");
28 Test t("Stack");
29 t.hello();
30 }
31
32 void hello(void) {
33 print("hello");
34 }
35
36 ~Test() {
37 print("destroy");
38 }
39 };
40
41 /* Check C++ startup initialisation */
42 Test s("Static");
43
44 /* EXPECTED OUTPUT:
45 *******************
46 Static::init
47 Static::stack_test
48 Stack::init
49 Stack::hello
50 Stack::destroy
51 Static::check_init: OK
52 Heap::init
53 Heap::hello
54 Heap::destroy
55 *******************/
56 int main (void) {
57 MBED_HOSTTEST_TIMEOUT(10);
58 MBED_HOSTTEST_SELECT(default_auto);
59 MBED_HOSTTEST_DESCRIPTION(C++);
60 MBED_HOSTTEST_START("MBED_12");
61
62 bool result = true;
63 for (;;)
64 {
65 // Global stack object simple test
66 s.stack_test();
67 if (s.check_init() == false)
68 {
69 result = false;
70 break;
71 }
72
73 // Heap test object simple test
74 Test *m = new Test("Heap");
75 m->hello();
76
77 if (m->check_init() == false)
78 {
79 result = false;
80 }
81 delete m;
82 break;
83 }
84
85 MBED_HOSTTEST_RESULT(result);
86 }
Imprint / Impressum