dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 #include "greentea-client/test_env.h"
nexpaq 1:55a6170b404f 2
nexpaq 1:55a6170b404f 3 #define PATTERN_CHECK_VALUE 0xF0F0ADAD
nexpaq 1:55a6170b404f 4
nexpaq 1:55a6170b404f 5 class Test {
nexpaq 1:55a6170b404f 6
nexpaq 1:55a6170b404f 7 private:
nexpaq 1:55a6170b404f 8 const char* name;
nexpaq 1:55a6170b404f 9 const int pattern;
nexpaq 1:55a6170b404f 10
nexpaq 1:55a6170b404f 11 public:
nexpaq 1:55a6170b404f 12 Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
nexpaq 1:55a6170b404f 13 print("init");
nexpaq 1:55a6170b404f 14 }
nexpaq 1:55a6170b404f 15
nexpaq 1:55a6170b404f 16 void print(const char *message) {
nexpaq 1:55a6170b404f 17 printf("%s::%s\n", name, message);
nexpaq 1:55a6170b404f 18 }
nexpaq 1:55a6170b404f 19
nexpaq 1:55a6170b404f 20 bool check_init(void) {
nexpaq 1:55a6170b404f 21 bool result = (pattern == PATTERN_CHECK_VALUE);
nexpaq 1:55a6170b404f 22 print(result ? "check_init: OK" : "check_init: ERROR");
nexpaq 1:55a6170b404f 23 return result;
nexpaq 1:55a6170b404f 24 }
nexpaq 1:55a6170b404f 25
nexpaq 1:55a6170b404f 26 void stack_test(void) {
nexpaq 1:55a6170b404f 27 print("stack_test");
nexpaq 1:55a6170b404f 28 Test t("Stack");
nexpaq 1:55a6170b404f 29 t.hello();
nexpaq 1:55a6170b404f 30 }
nexpaq 1:55a6170b404f 31
nexpaq 1:55a6170b404f 32 void hello(void) {
nexpaq 1:55a6170b404f 33 print("hello");
nexpaq 1:55a6170b404f 34 }
nexpaq 1:55a6170b404f 35
nexpaq 1:55a6170b404f 36 ~Test() {
nexpaq 1:55a6170b404f 37 print("destroy");
nexpaq 1:55a6170b404f 38 }
nexpaq 1:55a6170b404f 39 };
nexpaq 1:55a6170b404f 40
nexpaq 1:55a6170b404f 41 /* Check C++ startup initialisation */
nexpaq 1:55a6170b404f 42 Test s("Static");
nexpaq 1:55a6170b404f 43
nexpaq 1:55a6170b404f 44 /* EXPECTED OUTPUT:
nexpaq 1:55a6170b404f 45 *******************
nexpaq 1:55a6170b404f 46 Static::init
nexpaq 1:55a6170b404f 47 Static::stack_test
nexpaq 1:55a6170b404f 48 Stack::init
nexpaq 1:55a6170b404f 49 Stack::hello
nexpaq 1:55a6170b404f 50 Stack::destroy
nexpaq 1:55a6170b404f 51 Static::check_init: OK
nexpaq 1:55a6170b404f 52 Heap::init
nexpaq 1:55a6170b404f 53 Heap::hello
nexpaq 1:55a6170b404f 54 Heap::destroy
nexpaq 1:55a6170b404f 55 *******************/
nexpaq 1:55a6170b404f 56 int main (void) {
nexpaq 1:55a6170b404f 57 GREENTEA_SETUP(10, "default_auto");
nexpaq 1:55a6170b404f 58
nexpaq 1:55a6170b404f 59 bool result = true;
nexpaq 1:55a6170b404f 60 for (;;)
nexpaq 1:55a6170b404f 61 {
nexpaq 1:55a6170b404f 62 // Global stack object simple test
nexpaq 1:55a6170b404f 63 s.stack_test();
nexpaq 1:55a6170b404f 64 if (s.check_init() == false)
nexpaq 1:55a6170b404f 65 {
nexpaq 1:55a6170b404f 66 result = false;
nexpaq 1:55a6170b404f 67 break;
nexpaq 1:55a6170b404f 68 }
nexpaq 1:55a6170b404f 69
nexpaq 1:55a6170b404f 70 // Heap test object simple test
nexpaq 1:55a6170b404f 71 Test *m = new Test("Heap");
nexpaq 1:55a6170b404f 72 m->hello();
nexpaq 1:55a6170b404f 73
nexpaq 1:55a6170b404f 74 if (m->check_init() == false)
nexpaq 1:55a6170b404f 75 {
nexpaq 1:55a6170b404f 76 result = false;
nexpaq 1:55a6170b404f 77 }
nexpaq 1:55a6170b404f 78 delete m;
nexpaq 1:55a6170b404f 79 break;
nexpaq 1:55a6170b404f 80 }
nexpaq 1:55a6170b404f 81
nexpaq 1:55a6170b404f 82 GREENTEA_TESTSUITE_RESULT(result);
nexpaq 1:55a6170b404f 83 }