Rizky Ardi Maulana / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "greentea-client/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     GREENTEA_SETUP(10, "default_auto");
00058 
00059     bool result = true;
00060     for (;;)
00061     {
00062         // Global stack object simple test
00063         s.stack_test();
00064         if (s.check_init() == false)
00065         {
00066             result = false;
00067             break;
00068         }
00069 
00070         // Heap test object simple test
00071         Test *m = new Test("Heap");
00072         m->hello();
00073 
00074         if (m->check_init() == false)
00075         {
00076             result = false;
00077         }
00078         delete m;
00079         break;
00080     }
00081 
00082     GREENTEA_TESTSUITE_RESULT(result);
00083 }