2016-07-19 18:39:53 +00:00
|
|
|
#include "greentea-client/test_env.h"
|
|
|
|
|
|
|
|
#define PATTERN_CHECK_VALUE 0xF0F0ADAD
|
|
|
|
|
|
|
|
class Test {
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name;
|
|
|
|
const int pattern;
|
|
|
|
|
|
|
|
public:
|
2016-10-31 19:52:06 +00:00
|
|
|
Test(const char* _name, bool print_message=true) : name(_name), pattern(PATTERN_CHECK_VALUE) {
|
|
|
|
if (print_message) {
|
|
|
|
print("init");
|
|
|
|
}
|
2016-07-19 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print(const char *message) {
|
|
|
|
printf("%s::%s\n", name, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool check_init(void) {
|
|
|
|
bool result = (pattern == PATTERN_CHECK_VALUE);
|
|
|
|
print(result ? "check_init: OK" : "check_init: ERROR");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stack_test(void) {
|
|
|
|
print("stack_test");
|
|
|
|
Test t("Stack");
|
|
|
|
t.hello();
|
|
|
|
}
|
|
|
|
|
|
|
|
void hello(void) {
|
|
|
|
print("hello");
|
|
|
|
}
|
|
|
|
|
|
|
|
~Test() {
|
|
|
|
print("destroy");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Check C++ startup initialisation */
|
2016-10-31 19:52:06 +00:00
|
|
|
Test s("Static", false);
|
2016-07-19 18:39:53 +00:00
|
|
|
|
|
|
|
/* EXPECTED OUTPUT:
|
|
|
|
*******************
|
|
|
|
Static::init
|
|
|
|
Static::stack_test
|
|
|
|
Stack::init
|
|
|
|
Stack::hello
|
|
|
|
Stack::destroy
|
|
|
|
Static::check_init: OK
|
|
|
|
Heap::init
|
|
|
|
Heap::hello
|
|
|
|
Heap::destroy
|
|
|
|
*******************/
|
|
|
|
int main (void) {
|
|
|
|
GREENTEA_SETUP(10, "default_auto");
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
for (;;)
|
|
|
|
{
|
2016-10-31 19:52:06 +00:00
|
|
|
s.print("init");
|
2016-07-19 18:39:53 +00:00
|
|
|
// Global stack object simple test
|
|
|
|
s.stack_test();
|
|
|
|
if (s.check_init() == false)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heap test object simple test
|
|
|
|
Test *m = new Test("Heap");
|
|
|
|
m->hello();
|
|
|
|
|
|
|
|
if (m->check_init() == false)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
delete m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GREENTEA_TESTSUITE_RESULT(result);
|
|
|
|
}
|