mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/cpp/main.cpp@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "test_env.h" |
elessair | 0:f269e3021894 | 2 | |
elessair | 0:f269e3021894 | 3 | #define PATTERN_CHECK_VALUE 0xF0F0ADAD |
elessair | 0:f269e3021894 | 4 | |
elessair | 0:f269e3021894 | 5 | class Test { |
elessair | 0:f269e3021894 | 6 | |
elessair | 0:f269e3021894 | 7 | private: |
elessair | 0:f269e3021894 | 8 | const char* name; |
elessair | 0:f269e3021894 | 9 | const int pattern; |
elessair | 0:f269e3021894 | 10 | |
elessair | 0:f269e3021894 | 11 | public: |
elessair | 0:f269e3021894 | 12 | Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) { |
elessair | 0:f269e3021894 | 13 | print("init"); |
elessair | 0:f269e3021894 | 14 | } |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | void print(const char *message) { |
elessair | 0:f269e3021894 | 17 | printf("%s::%s\n", name, message); |
elessair | 0:f269e3021894 | 18 | } |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | bool check_init(void) { |
elessair | 0:f269e3021894 | 21 | bool result = (pattern == PATTERN_CHECK_VALUE); |
elessair | 0:f269e3021894 | 22 | print(result ? "check_init: OK" : "check_init: ERROR"); |
elessair | 0:f269e3021894 | 23 | return result; |
elessair | 0:f269e3021894 | 24 | } |
elessair | 0:f269e3021894 | 25 | |
elessair | 0:f269e3021894 | 26 | void stack_test(void) { |
elessair | 0:f269e3021894 | 27 | print("stack_test"); |
elessair | 0:f269e3021894 | 28 | Test t("Stack"); |
elessair | 0:f269e3021894 | 29 | t.hello(); |
elessair | 0:f269e3021894 | 30 | } |
elessair | 0:f269e3021894 | 31 | |
elessair | 0:f269e3021894 | 32 | void hello(void) { |
elessair | 0:f269e3021894 | 33 | print("hello"); |
elessair | 0:f269e3021894 | 34 | } |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | ~Test() { |
elessair | 0:f269e3021894 | 37 | print("destroy"); |
elessair | 0:f269e3021894 | 38 | } |
elessair | 0:f269e3021894 | 39 | }; |
elessair | 0:f269e3021894 | 40 | |
elessair | 0:f269e3021894 | 41 | /* Check C++ startup initialisation */ |
elessair | 0:f269e3021894 | 42 | Test s("Static"); |
elessair | 0:f269e3021894 | 43 | |
elessair | 0:f269e3021894 | 44 | /* EXPECTED OUTPUT: |
elessair | 0:f269e3021894 | 45 | ******************* |
elessair | 0:f269e3021894 | 46 | Static::init |
elessair | 0:f269e3021894 | 47 | Static::stack_test |
elessair | 0:f269e3021894 | 48 | Stack::init |
elessair | 0:f269e3021894 | 49 | Stack::hello |
elessair | 0:f269e3021894 | 50 | Stack::destroy |
elessair | 0:f269e3021894 | 51 | Static::check_init: OK |
elessair | 0:f269e3021894 | 52 | Heap::init |
elessair | 0:f269e3021894 | 53 | Heap::hello |
elessair | 0:f269e3021894 | 54 | Heap::destroy |
elessair | 0:f269e3021894 | 55 | *******************/ |
elessair | 0:f269e3021894 | 56 | int main (void) { |
elessair | 0:f269e3021894 | 57 | MBED_HOSTTEST_TIMEOUT(10); |
elessair | 0:f269e3021894 | 58 | MBED_HOSTTEST_SELECT(default_auto); |
elessair | 0:f269e3021894 | 59 | MBED_HOSTTEST_DESCRIPTION(C++); |
elessair | 0:f269e3021894 | 60 | MBED_HOSTTEST_START("MBED_12"); |
elessair | 0:f269e3021894 | 61 | |
elessair | 0:f269e3021894 | 62 | bool result = true; |
elessair | 0:f269e3021894 | 63 | for (;;) |
elessair | 0:f269e3021894 | 64 | { |
elessair | 0:f269e3021894 | 65 | // Global stack object simple test |
elessair | 0:f269e3021894 | 66 | s.stack_test(); |
elessair | 0:f269e3021894 | 67 | if (s.check_init() == false) |
elessair | 0:f269e3021894 | 68 | { |
elessair | 0:f269e3021894 | 69 | result = false; |
elessair | 0:f269e3021894 | 70 | break; |
elessair | 0:f269e3021894 | 71 | } |
elessair | 0:f269e3021894 | 72 | |
elessair | 0:f269e3021894 | 73 | // Heap test object simple test |
elessair | 0:f269e3021894 | 74 | Test *m = new Test("Heap"); |
elessair | 0:f269e3021894 | 75 | m->hello(); |
elessair | 0:f269e3021894 | 76 | |
elessair | 0:f269e3021894 | 77 | if (m->check_init() == false) |
elessair | 0:f269e3021894 | 78 | { |
elessair | 0:f269e3021894 | 79 | result = false; |
elessair | 0:f269e3021894 | 80 | } |
elessair | 0:f269e3021894 | 81 | delete m; |
elessair | 0:f269e3021894 | 82 | break; |
elessair | 0:f269e3021894 | 83 | } |
elessair | 0:f269e3021894 | 84 | |
elessair | 0:f269e3021894 | 85 | MBED_HOSTTEST_RESULT(result); |
elessair | 0:f269e3021894 | 86 | } |