Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "config.h"
00040
00041 #include <assert.h>
00042 #include <string.h>
00043 #include <strings.h>
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <unistd.h>
00047
00048 #include "ksm/memory.h"
00049 #include "test_routines.h"
00050
00051 static int m_automatic = 0;
00052 static int m_basic = 0;
00053 static int m_console = 0;
00054 static int m_list = 0;
00055 static int m_curses= 0;
00056 static char* m_filename = NULL;
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static void TestHelp(void)
00072 {
00073 static const char* lines[] = {
00074 "The following switches are available:",
00075 "",
00076 " -a Automatic - run tests in automatic mode. If the -f switch is also",
00077 " given, the output is set to a file whose root name is given here.",
00078 " Two files are produced, <root>-Listing.xml, listing the tests,",
00079 " and <root>-Results.xml listing the contents of the tests. If not",
00080 " specified, a default name (CUnitAutomated) is used instead.",
00081 " -b Basic - run tests in basic mode. (This is the default.)",
00082 " -c Console - run tests using console mode.",
00083 " -f file Name of the file for automatic or list mode.",
00084 " -h Print this message and exit.",
00085 " -l List tests to file.",
00086 " -u Curses - run tests using curses interface.",
00087 "",
00088 " (The options 'a', 'b', 'c', 'l' and 'u' are mutually exclusive.)",
00089 NULL
00090 };
00091 int i;
00092
00093 for (i = 0; lines[i]; ++i) {
00094 printf("%s\n", lines[i]);
00095 }
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static void TestCommandLine(int argc, char** argv)
00114 {
00115 int c = 0;
00116
00117
00118
00119
00120 while ((c = getopt(argc, argv, "abcf:hlu")) != -1) {
00121 switch (c) {
00122 case 'a':
00123 m_automatic = 1;
00124 break;
00125
00126 case 'b':
00127 m_basic = 1;
00128 break;
00129
00130 case 'c':
00131 m_console = 1;
00132 break;
00133
00134 case 'f':
00135 m_filename = optarg;
00136 break;
00137
00138 case 'h':
00139 TestHelp();
00140 exit(0);
00141
00142 case 'l':
00143 m_list = 1;
00144 break;
00145
00146 case 'u':
00147 m_curses = 1;
00148 break;
00149
00150 default:
00151 fprintf(stderr, "Unrecognised switch: -%c\n", optopt);
00152 exit(1);
00153 }
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void TestInitialize(int argc, char** argv)
00171 {
00172 int sum;
00173
00174
00175
00176 TestCommandLine(argc, argv);
00177
00178
00179
00180 sum = TestGetAutomatic() + TestGetBasic() + TestGetConsole() +
00181 TestGetCurses() + TestGetList();
00182 if (sum == 0) {
00183 m_basic = 1;
00184 }
00185 else if (sum > 1) {
00186 printf("Conflicting options given\n\n");
00187 TestHelp();
00188 exit(1);
00189 }
00190
00191 return;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 int TestGetAutomatic(void)
00209 {
00210
00211
00212 return m_automatic;
00213 }
00214
00215 int TestGetBasic(void)
00216 {
00217 return m_basic;
00218 }
00219
00220 int TestGetConsole(void)
00221 {
00222 return m_console;
00223 }
00224
00225 int TestGetList(void)
00226 {
00227 return m_list;
00228 }
00229
00230 int TestGetCurses(void)
00231 {
00232 return m_curses;
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 const char* TestGetFilename(void)
00254 {
00255 return m_filename;
00256 }