test_all.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdlib.h"
00026 #include "stdio.h"
00027 #include "CUnit/Basic.h"
00028 #include "CUnit/Automated.h"
00029 #include "CUnit/Console.h"
00030 #include "CUnit/TestDB.h"
00031
00032 typedef int (*testSuite_t) (void);
00033
00034
00035 #include "test_generic.h"
00036 #include "test_ui.h"
00037 #include "test_routing.h"
00038 #include "test_inventory.h"
00039 #include "test_campaign.h"
00040 #include "test_rma.h"
00041 #include "test_parser.h"
00042
00043 static const testSuite_t testSuites[] = {
00044 UFO_AddGenericTests,
00045 UFO_AddParserTests,
00046 UFO_AddUITests,
00047 UFO_AddCampaignTests,
00048 UFO_AddRoutingTests,
00049 UFO_AddInventoryTests,
00050 UFO_AddRandomMapAssemblyTests,
00051 NULL
00052 };
00053 #define NUMBER_OF_TESTS (sizeof(testSuites) / sizeof(*(testSuites)))
00054
00055 static inline int fatalError (void)
00056 {
00057 CU_cleanup_registry();
00058 return CU_get_error();
00059 }
00060
00061 void Sys_Init(void);
00062 void Sys_Init (void)
00063 {
00064 }
00065
00066 typedef struct config_s {
00067 int console;
00068 int automated;
00069 int disableRMA;
00070 } config_t;
00071
00072 static config_t config;
00073
00074 static void Test_List (void)
00075 {
00076 CU_pTestRegistry registry;
00077 CU_pSuite suite;
00078
00079 printf("Suites:\n");
00080 registry = CU_get_registry();
00081 suite = registry->pSuite;
00082 while (suite) {
00083 printf("* %s\n", suite->pName);
00084 suite = suite->pNext;
00085 }
00086 }
00087
00088 static void Test_RemovePSuite (CU_pSuite suite)
00089 {
00090 if (suite->pNext)
00091 suite->pNext->pPrev = suite->pPrev;
00092 if (suite->pPrev)
00093 suite->pPrev->pNext = suite->pNext;
00094 else
00095 CU_get_registry()->pSuite = suite->pNext;
00096 }
00097
00098 static int Test_RemoveSuite (const char *name)
00099 {
00100 CU_pTestRegistry registry;
00101 CU_pSuite suite;
00102
00103 registry = CU_get_registry();
00104 suite = registry->pSuite;
00105 while (suite) {
00106 if (!strcmp(suite->pName, name)) {
00107 Test_RemovePSuite(suite);
00108 return 0;
00109 }
00110 suite = suite->pNext;
00111 }
00112 return 1;
00113 }
00114
00115 static int Test_RemoveAllSuitesElse (const char *name)
00116 {
00117 int found = 0;
00118 CU_pTestRegistry registry;
00119 CU_pSuite suite;
00120
00121 registry = CU_get_registry();
00122 suite = registry->pSuite;
00123 while (suite) {
00124 if (!strcmp(suite->pName, name)) {
00125 suite = suite->pNext;
00126 found = 1;
00127 } else {
00128 CU_pSuite remove = suite;
00129 suite = suite->pNext;
00130 Test_RemovePSuite(remove);
00131 }
00132 }
00133 if (found)
00134 return 0;
00135 return 1;
00136 }
00137
00138 static void Test_Parameters (const int argc, const char **argv)
00139 {
00140 int i;
00141
00142 for (i = 1; i < argc; i++) {
00143 if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--console")) {
00144 config.console = 1;
00145 } else if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--automated")) {
00146 config.automated = 1;
00147 } else if (!strncmp(argv[i], "--disable-", 10)) {
00148 const char *name = argv[i] + 10;
00149 if (Test_RemoveSuite(name) != 0) {
00150 printf("Suite \"%s\" unknown\n", name);
00151 printf("Use \"%s -l\" to show the list of suites\n", argv[0]);
00152 exit(2);
00153 }
00154 } else if (!strncmp(argv[i], "--only-", 7)) {
00155 const char *name = argv[i] + 7;
00156 if (Test_RemoveAllSuitesElse(name) != 0) {
00157 printf("Suite \"%s\" unknown\n", name);
00158 printf("Use \"%s -l\" to show the list of suites\n", argv[0]);
00159 exit(2);
00160 }
00161 } else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--list")) {
00162 Test_List();
00163 exit(0);
00164 } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
00165 printf("Usage:\n");
00166 printf("-h --help | show this help screen\n");
00167 printf("-c --console | run tests in console mode\n");
00168 printf("-a --automated | run tests in automated mode (create xml file)\n");
00169 printf("-l --list | list suite name available\n");
00170 printf(" --disable-SUITE | Disable a suite by name\n");
00171 printf(" SUITE=suite name\n");
00172 printf(" --only-SUITE | Enable an only one suite by name\n");
00173 printf(" SUITE=suite name\n");
00174 exit(0);
00175 } else {
00176 printf("Param \"%s\" unknown\n", argv[i]);
00177 printf("Use \"%s -h\" to show the help screen\n", argv[0]);
00178 exit(2);
00179 }
00180 }
00181 }
00182
00188 int main (int argc, const char **argv)
00189 {
00190 int i;
00191 int failures;
00192
00193
00194 if (CU_initialize_registry() != CUE_SUCCESS)
00195 return CU_get_error();
00196
00197 for (i = 0; i < NUMBER_OF_TESTS - 1; i++) {
00198 if (testSuites[i]() != CUE_SUCCESS)
00199 return fatalError();
00200 }
00201
00202 Test_Parameters(argc, argv);
00203
00204 if (config.console)
00205
00206 CU_console_run_tests();
00207 else if (config.automated) {
00208 CU_basic_set_mode(CU_BRM_VERBOSE);
00209 CU_set_output_filename("ufoai");
00210 CU_automated_run_tests();
00211 } else {
00212
00213 CU_basic_set_mode(CU_BRM_VERBOSE);
00214 CU_basic_run_tests();
00215 }
00216
00217 failures = CU_get_number_of_failures();
00218 CU_cleanup_registry();
00219
00220 return failures != 0;
00221 }