Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "greentea-client/test_env.h" 00017 00018 #define PATTERN_CHECK_VALUE 0xF0F0ADAD 00019 00020 class Test { 00021 00022 private: 00023 const char* name; 00024 const int pattern; 00025 00026 public: 00027 Test(const char* _name, bool print_message=true) : name(_name), pattern(PATTERN_CHECK_VALUE) { 00028 if (print_message) { 00029 print("init"); 00030 } 00031 } 00032 00033 void print(const char *message) { 00034 printf("%s::%s\n", name, message); 00035 } 00036 00037 bool check_init(void) { 00038 bool result = (pattern == PATTERN_CHECK_VALUE); 00039 print(result ? "check_init: OK" : "check_init: ERROR"); 00040 return result; 00041 } 00042 00043 void stack_test(void) { 00044 print("stack_test"); 00045 Test t("Stack"); 00046 t.hello(); 00047 } 00048 00049 void hello(void) { 00050 print("hello"); 00051 } 00052 00053 ~Test() { 00054 print("destroy"); 00055 } 00056 }; 00057 00058 /* Check C++ startup initialisation */ 00059 Test s("Static", false); 00060 00061 /* EXPECTED OUTPUT: 00062 ******************* 00063 Static::init 00064 Static::stack_test 00065 Stack::init 00066 Stack::hello 00067 Stack::destroy 00068 Static::check_init: OK 00069 Heap::init 00070 Heap::hello 00071 Heap::destroy 00072 *******************/ 00073 int main (void) { 00074 GREENTEA_SETUP(10, "default_auto"); 00075 00076 bool result = true; 00077 for (;;) 00078 { 00079 s.print("init"); 00080 // Global stack object simple test 00081 s.stack_test(); 00082 if (s.check_init() == false) 00083 { 00084 result = false; 00085 break; 00086 } 00087 00088 // Heap test object simple test 00089 Test *m = new Test("Heap"); 00090 m->hello(); 00091 00092 if (m->check_init() == false) 00093 { 00094 result = false; 00095 } 00096 delete m; 00097 break; 00098 } 00099 00100 GREENTEA_TESTSUITE_RESULT(result); 00101 }
Generated on Tue Jul 12 2022 14:24:25 by
