Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "test_env.h"
00002 
00003 #define PATTERN_CHECK_VALUE  0xF0F0ADAD
00004 
00005 class Test {
00006 
00007 private:
00008     const char* name;
00009     const int pattern;
00010 
00011 public:
00012     Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE)  {
00013         print("init");
00014     }
00015 
00016     void print(const char *message) {
00017         printf("%s::%s\n", name, message);
00018     }
00019 
00020     bool check_init(void) {
00021         bool result = (pattern == PATTERN_CHECK_VALUE);
00022         print(result ? "check_init: OK" : "check_init: ERROR");
00023         return result;
00024     }
00025 
00026     void stack_test(void) {
00027         print("stack_test");
00028         Test t("Stack");
00029         t.hello();
00030     }
00031 
00032     void hello(void) {
00033         print("hello");
00034     }
00035 
00036     ~Test() {
00037         print("destroy");
00038     }
00039 };
00040 
00041 /* Check C++ startup initialisation */
00042 Test s("Static");
00043 
00044 /* EXPECTED OUTPUT:
00045 *******************
00046 Static::init
00047 Static::stack_test
00048 Stack::init
00049 Stack::hello
00050 Stack::destroy
00051 Static::check_init: OK
00052 Heap::init
00053 Heap::hello
00054 Heap::destroy
00055 *******************/
00056 int main (void) {
00057     MBED_HOSTTEST_TIMEOUT(10);
00058     MBED_HOSTTEST_SELECT(default_auto);
00059     MBED_HOSTTEST_DESCRIPTION(C++);
00060     MBED_HOSTTEST_START("MBED_12");
00061 
00062     bool result = true;
00063     for (;;)
00064     {
00065         // Global stack object simple test
00066         s.stack_test();
00067         if (s.check_init() == false)
00068         {
00069             result = false;
00070             break;
00071         }
00072 
00073         // Heap test object simple test
00074         Test *m = new Test("Heap");
00075         m->hello();
00076 
00077         if (m->check_init() == false)
00078         {
00079             result = false;
00080         }
00081         delete m;
00082         break;
00083     }
00084 
00085     MBED_HOSTTEST_RESULT(result);
00086 }