USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
mytest.h
00001 // mytest.h 2013/6/28 00002 #pragma once 00003 #include "mbed_debug.h" 00004 00005 class BaseTest { 00006 public: 00007 virtual void _run() = 0; 00008 char* m_a; 00009 char* m_b; 00010 int m_line; 00011 char* m_file; 00012 BaseTest* next; 00013 }; 00014 00015 class reg { 00016 BaseTest* head; 00017 BaseTest* tail; 00018 reg() { 00019 head = NULL; 00020 tail = NULL; 00021 } 00022 public: 00023 static reg* inst() { 00024 static reg regtest; 00025 return ®test; 00026 } 00027 void add(BaseTest* test) { 00028 test->next = NULL; 00029 if (head == NULL) { 00030 head = test; 00031 tail = test; 00032 } else { 00033 tail->next = test; 00034 tail = test; 00035 } 00036 } 00037 int run_all_tests(char* a = "") { 00038 BaseTest* test = head; 00039 int pass = 0; 00040 int count = 0; 00041 char* file = ""; 00042 while(test) { 00043 if (strcmp(a, "") == 0 || strcmp(a, test->m_a) == 0) { 00044 if (strcmp(file, test->m_file) != 0) { 00045 file = test->m_file; 00046 debug("%s\n", file); 00047 } 00048 debug("TEST(%s,%s)@%d ... ",test->m_a, test->m_b, test->m_line); 00049 Timer t; t.start(); 00050 test->_run(); 00051 debug("OK (%d ms)\n", t.read_ms()); 00052 pass++; 00053 } 00054 test = test->next; 00055 count++; 00056 } 00057 debug("%d/%d TESTS PASSED!!!\n", pass, count); 00058 return 0; 00059 } 00060 }; 00061 00062 #define TEST(A,B) \ 00063 class class_##A##_##B : public BaseTest { \ 00064 public: \ 00065 class_##A##_##B(char* a, char* b, char* file, int line) { \ 00066 m_a = a; m_b = b; \ 00067 m_file = file; m_line = line; \ 00068 reg::inst()->add(this); \ 00069 } \ 00070 virtual void _run(); \ 00071 }; \ 00072 class_##A##_##B instance_##A##_##B(#A,#B,__FILE__,__LINE__); \ 00073 void class_##A##_##B::_run() 00074 00075 #define RUN_TEST(A,B) instance_##A##_##B._run() 00076 #define RUN_ALL_TESTS(A) reg::inst()->run_all_tests(#A) 00077 #define ASSERT_TRUE(A) if(A){}else{debug("\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; 00078 00079 #ifndef DBG 00080 #define DBG(FMT, ...) do{debug("[%s:%d]"FMT"\r\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0); 00081 #endif 00082 #define TEST_PRINT(FMT, ...) do{debug("[TEST: %d]"FMT"\r\n", __LINE__, ##__VA_ARGS__);}while(0);
Generated on Wed Jul 13 2022 08:08:25 by 1.7.2