1 /*
2  *  CUnit - A Unit testing framework library for C.
3  *  Copyright (C) 2004  Anil Kumar, Jerry St.Clair
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Library General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "Basic.h"
25 #include "ExampleTests.h"
26 
main(int argc,char * argv[])27 int main(int argc, char* argv[])
28 {
29   CU_BasicRunMode mode = CU_BRM_VERBOSE;
30   CU_ErrorAction error_action = CUEA_IGNORE;
31   int i;
32 
33   setvbuf(stdout, NULL, _IONBF, 0);
34 
35   for (i=1 ; i<argc ; i++) {
36     if (!strcmp("-i", argv[i])) {
37       error_action = CUEA_IGNORE;
38     }
39     else if (!strcmp("-f", argv[i])) {
40       error_action = CUEA_FAIL;
41     }
42     else if (!strcmp("-A", argv[i])) {
43       error_action = CUEA_ABORT;
44     }
45     else if (!strcmp("-s", argv[i])) {
46       mode = CU_BRM_SILENT;
47     }
48     else if (!strcmp("-n", argv[i])) {
49       mode = CU_BRM_NORMAL;
50     }
51     else if (!strcmp("-v", argv[i])) {
52       mode = CU_BRM_VERBOSE;
53     }
54     else if (!strcmp("-e", argv[i])) {
55       print_example_results();
56       return 0;
57     }
58     else {
59       printf("\nUsage:  BasicTest [options]\n\n"
60                "Options:   -i   ignore framework errors [default].\n"
61                "           -f   fail on framework error.\n"
62                "           -A   abort on framework error.\n\n"
63                "           -s   silent mode - no output to screen.\n"
64                "           -n   normal mode - standard output to screen.\n"
65                "           -v   verbose mode - max output to screen [default].\n\n"
66                "           -e   print expected test results and exit.\n"
67                "           -h   print this message and exit.\n\n");
68       return 0;
69     }
70   }
71 
72   if (CU_initialize_registry()) {
73     printf("\nInitialization of Test Registry failed.");
74   }
75   else {
76     AddTests();
77     CU_basic_set_mode(mode);
78     CU_set_error_action(error_action);
79     printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
80     CU_cleanup_registry();
81   }
82 
83   return 0;
84 }
85