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