#include <cstdio> #include <cstdlib>
using namespace std;
int test_val;
bool test1(void) { printf("test1()\n"); return test_val > 1; } bool test2(void) { printf("test2()\n"); return test_val > 2; } bool test3(void) { printf("test3()\n"); return test_val > 3; } bool test4(void) { printf("test4()\n"); return test_val > 4; } bool test5(void) { printf("test5()\n"); return test_val > 5; } void test_ok(void) { printf("Test OK\n"); }
bool do_test1(void) { bool result = false; printf("Test pattern 1\n");
do { if(!test1()) break; if(!test2()) break; if(!test3()) break; if(!test4()) break; if(!test5()) break; test_ok(); result = true; } while(0);
return result; }
bool do_test2(void) { bool (*tests[])(void) = { test1, test2, test3, test4, test5, NULL, }; int i; bool result = true;
printf("Test pattern 2\n");
for(i = 0; tests[i] != NULL && result; i++) result = tests[i](); if(result) test_ok();
return result; }
bool do_test3(void) { printf("Test pattern 3\n");
return test1() && test2() && test3() && test4() && test5() && (test_ok(), true); }
int main(int argc, const char* argv[]) { bool result = false; if(argc < 3) return 0;
test_val = atoi(argv[2]); switch(atoi(argv[1])) { case 1: result = do_test1(); break; case 2: result = do_test2(); break; case 3: result = do_test3(); break; }
if(result) printf("全テスト正常終了");
return 0; } |