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 { 00029 if (print_message) { 00030 print("init"); 00031 } 00032 } 00033 00034 void print(const char *message) 00035 { 00036 printf("%s::%s\n", name, message); 00037 } 00038 00039 bool check_init(void) 00040 { 00041 bool result = (pattern == PATTERN_CHECK_VALUE); 00042 print(result ? "check_init: OK" : "check_init: ERROR"); 00043 return result; 00044 } 00045 00046 void stack_test(void) 00047 { 00048 print("stack_test"); 00049 Test t("Stack"); 00050 t.hello(); 00051 } 00052 00053 void hello(void) 00054 { 00055 print("hello"); 00056 } 00057 00058 ~Test() 00059 { 00060 print("destroy"); 00061 } 00062 }; 00063 00064 /* Check C++ startup initialisation */ 00065 Test s("Static", false); 00066 00067 /* EXPECTED OUTPUT: 00068 ******************* 00069 Static::init 00070 Static::stack_test 00071 Stack::init 00072 Stack::hello 00073 Stack::destroy 00074 Static::check_init: OK 00075 Heap::init 00076 Heap::hello 00077 Heap::destroy 00078 *******************/ 00079 int main(void) 00080 { 00081 GREENTEA_SETUP(10, "default_auto"); 00082 00083 bool result = true; 00084 for (;;) { 00085 s.print("init"); 00086 // Global stack object simple test 00087 s.stack_test(); 00088 if (s.check_init() == false) { 00089 result = false; 00090 break; 00091 } 00092 00093 // Heap test object simple test 00094 Test *m = new Test("Heap"); 00095 m->hello(); 00096 00097 if (m->check_init() == false) { 00098 result = false; 00099 } 00100 delete m; 00101 break; 00102 } 00103 00104 GREENTEA_TESTSUITE_RESULT(result); 00105 }
Generated on Tue Aug 9 2022 00:37:14 by
1.7.2