| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#include <assert.h> |
| 39 |
#include <errno.h> |
| 40 |
#include <stdio.h> |
| 41 |
#include <stdlib.h> |
| 42 |
#include <string.h> |
| 43 |
|
| 44 |
#include "scare.h" |
| 45 |
#include "sxprotos.h" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
int |
| 55 |
main (int argc, const char *argv[]) |
| 56 |
{ |
| 57 |
const sc_char *const program = argv[0]; |
| 58 |
sc_bool is_verbose = FALSE, is_tracing = FALSE; |
| 59 |
const sc_char *trace_flags; |
| 60 |
sx_test_descriptor_t *tests; |
| 61 |
sc_int count, index_, errors; |
| 62 |
assert (argc > 0 && argv); |
| 63 |
|
| 64 |
|
| 65 |
if (argc > 1 |
| 66 |
&& (strcmp (argv[1], "-v") == 0 || strcmp (argv[1], "-vv") == 0)) |
| 67 |
{ |
| 68 |
is_verbose = TRUE; |
| 69 |
is_tracing = (strcmp (argv[1], "-vv") == 0); |
| 70 |
argc--; |
| 71 |
argv++; |
| 72 |
} |
| 73 |
|
| 74 |
if (is_verbose) |
| 75 |
{ |
| 76 |
sx_trace ("--- %s Test Suite [Adrift %ld compatible]\n", |
| 77 |
sc_scare_version (), sc_scare_emulation ()); |
| 78 |
if (argc < 2) |
| 79 |
return EXIT_SUCCESS; |
| 80 |
} |
| 81 |
else if (argc < 2) |
| 82 |
{ |
| 83 |
fprintf (stderr, "Usage: %s [-v | -vv] test [test...]\n", program); |
| 84 |
return EXIT_FAILURE; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
if (!sc_set_locale ("Latin1")) |
| 89 |
{ |
| 90 |
fprintf (stderr, "%s: failed to set locale\n", program); |
| 91 |
return EXIT_FAILURE; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
sc_set_portable_random (TRUE); |
| 100 |
|
| 101 |
|
| 102 |
scr_set_verbose (is_verbose); |
| 103 |
stub_debug_trace (is_tracing); |
| 104 |
trace_flags = getenv ("SC_TRACE_FLAGS"); |
| 105 |
if (trace_flags) |
| 106 |
sc_set_trace_flags (strtoul (trace_flags, NULL, 0)); |
| 107 |
|
| 108 |
|
| 109 |
tests = sx_malloc ((argc - 1) * sizeof (*tests)); |
| 110 |
|
| 111 |
|
| 112 |
count = 0; |
| 113 |
for (index_ = 1; index_ < argc; index_++) |
| 114 |
{ |
| 115 |
const sc_char *name; |
| 116 |
FILE *stream; |
| 117 |
sx_script script; |
| 118 |
sc_game game; |
| 119 |
|
| 120 |
name = argv[index_]; |
| 121 |
|
| 122 |
script = sx_fopen (name, "scr", "r"); |
| 123 |
if (!script) |
| 124 |
{ |
| 125 |
fprintf (stderr, "%s: %s.scr: %s\n", program, name, strerror (errno)); |
| 126 |
continue; |
| 127 |
} |
| 128 |
|
| 129 |
stream = sx_fopen (name, "taf", "rb"); |
| 130 |
if (!stream) |
| 131 |
{ |
| 132 |
fprintf (stderr, "%s: %s.taf: %s\n", program, name, strerror (errno)); |
| 133 |
fclose (script); |
| 134 |
continue; |
| 135 |
} |
| 136 |
|
| 137 |
sc_reseed_random_sequence (1); |
| 138 |
game = sc_game_from_stream (stream); |
| 139 |
fclose (stream); |
| 140 |
if (!game) |
| 141 |
{ |
| 142 |
fprintf (stderr, |
| 143 |
"%s: %s.taf: Unable to decode Adrift game\n", program, name); |
| 144 |
fclose (script); |
| 145 |
continue; |
| 146 |
} |
| 147 |
|
| 148 |
tests[count].name = name; |
| 149 |
tests[count].script = script; |
| 150 |
tests[count].game = game; |
| 151 |
count++; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
if (count > 0) |
| 156 |
errors = test_run_game_tests (tests, count, is_verbose); |
| 157 |
else |
| 158 |
errors = 1; |
| 159 |
|
| 160 |
|
| 161 |
for (index_ = 0; index_ < count; index_++) |
| 162 |
{ |
| 163 |
fclose (tests[index_].script); |
| 164 |
sc_free_game (tests[index_].game); |
| 165 |
} |
| 166 |
sx_free (tests); |
| 167 |
|
| 168 |
|
| 169 |
printf ("%s [%ld test%s, %ld error%s]\n", |
| 170 |
errors > 0 ? "FAIL" : "PASS", |
| 171 |
count, count == 1 ? "" : "s", errors, errors == 1 ? "" : "s"); |
| 172 |
|
| 173 |
return errors > 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
| 174 |
} |