Skip to content

Actions rebased #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
623cb71
print commmands with -hb/-hc
stm2 Aug 13, 2020
bb8d3a1
fixed help (-R)
stm2 Aug 14, 2020
b5adbc8
added missing items and fixed English item names
stm2 Aug 13, 2020
9f80d4d
BREED is actually called GROW
stm2 Aug 13, 2020
6fd1a6d
message spelling fixed
stm2 Aug 17, 2020
e77728b
fixed English herb names
stm2 Aug 13, 2020
5981477
removed BELAGERE
stm2 Aug 14, 2020
a471368
removed deprecated commands
stm2 Aug 14, 2020
98f8237
fixed options
stm2 Aug 14, 2020
fb5129a
check ZERSTOERE
stm2 Aug 13, 2020
a21fcd8
HELP FIGHT, FACTIONSTEALTH not for e3
stm2 Aug 14, 2020
3223ea2
E3 races
stm2 Aug 14, 2020
f6e9095
fixed e3 files
stm2 Aug 14, 2020
eb99560
small adjustments
stm2 Aug 17, 2020
495013a
refactored testing, check CLAIM order parameters
stm2 Aug 15, 2020
65c3710
tests for e3, ALLIANZ
stm2 Aug 16, 2020
58be0a1
warn of too many parameters
stm2 Aug 16, 2020
9a2a62d
check PFLANZE
stm2 Aug 17, 2020
3be73b5
handle single quotes and quotes within quotes (partially)
stm2 Aug 17, 2020
d452782
check SPRACHE
stm2 Aug 17, 2020
1181b98
tweaks
stm2 Aug 20, 2020
2b1d245
fixed https://bugs.eressea.de/view.php?id=2555
stm2 Aug 20, 2020
9244f51
fixed https://bugs.eressea.de/view.php?id=2641
stm2 Aug 21, 2020
ef38813
added Steinkreis
stm2 Aug 21, 2020
a210756
fixed https://bugs.eressea.de/view.php?id=2547
stm2 Aug 21, 2020
b7441d2
fixed https://bugs.eressea.de/view.php?id=2522
stm2 Aug 21, 2020
9977e26
check for missing order start / accidental NEXT
stm2 Aug 21, 2020
1caca0c
fixed missing message, (wrong) caravanserei spelling, -P option
stm2 Aug 21, 2020
0cbe483
okay, server accepts PARTEI x "pw" as order start
stm2 Aug 22, 2020
2a10ce2
fixed whitespace errors
stm2 Aug 22, 2020
e917ef1
check LOCALE mismatch
stm2 Aug 23, 2020
2c3eb45
test actions
stm2 Aug 25, 2020
a37f5e2
fixed a few memory leaks
stm2 Aug 29, 2020
2574c6f
tests for breed
stm2 Aug 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions echeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,17 +1042,21 @@ char *eatwhite(char *ptr)
return ptr;
}

static char nulls[] = "\0\0\0\0\0\0\0\0";

const char *itob(int i)
{
static char buffer[40];
static int index = 0;
char *dst;
int b = i, x;

if (i == 0)
return "0";

dst = nulls + 6;
index = (index+1) % 4;
dst = buffer + index * 10 + 9;

*dst = 0;
do {
x = b % 36;
b /= 36;
Expand Down Expand Up @@ -1683,6 +1687,13 @@ void mock_input(const char *input)
mock_pos = mocked_input;
}

void set_output(FILE *out, FILE *err) {
if (out)
OUT = out;
if (err)
ERR = err;
}

int get_long_order_line() {
if (order_unit)
return order_unit->long_order_line;
Expand Down Expand Up @@ -1823,23 +1834,25 @@ void Error(char *text, int line, char *order)

int btoi(char *s)
{
char *x = s;
static char buf[5];
int n = 0;
int i = 0;

assert(s);
if (!(*s))
return 0;
while (isalnum(*s))
s++;
*s = 0;
s = x;
if (strlen(s) > 4) {

for(n = 0; n < 5 && isalnum(*s); ++n)
buf[n] = *(s++);
if (n > 4) {
sprintf(message_buf, "%s: `%s'. %s", errtxt[NTOOBIG], s, errtxt[USED1]);
anerror(message_buf);
return 1;
}
buf[n] = 0;
s = buf;
#ifdef HAVE_STRTOL
i = (int)(strtol(x, NULL, 36));
i = (int)(strtol(s, NULL, 36));
#else
while (isalnum(*s)) {
i *= 36;
Expand Down Expand Up @@ -3804,7 +3817,7 @@ void check_money(bool do_move)
if (t->ship == i) {
if (t->hasmoved > 1) { /* schon bewegt! */
sprintf(warn_buf, errtxt[UNITONSHIPHASMOVED], uid(t), itob(i));
Error(warn_buf, t->line_no, t->long_order);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das hier schient mir der eigentliche Bugfix zu sein, alles andere in diesem commit dient nur der Verwirrung des Reviewers (und macht mir einen Haufen Konflikte beim Cherry-Picking).

warning(warn_buf, t->line_no, t->long_order, 2);
}
t->hasmoved = 1;
t->newx = x;
Expand Down Expand Up @@ -4926,6 +4939,7 @@ int check_options(int argc, char *argv[], char dostop, char command_line)
{
int i;
char *x;
FILE *F;

for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
Expand Down Expand Up @@ -5017,16 +5031,14 @@ int check_options(int argc, char *argv[], char dostop, char command_line)
case 'E':
if (dostop) { /* bei Optionen via "; ECHECK" nicht mehr machen */
echo_it = 1;
OUT = stdout;
ERR = stdout;
set_output(stdout, stdout);
}
break;

case 'e':
if (dostop) { /* bei Optionen via "; ECHECK" nicht mehr machen */
echo_it = 1;
OUT = stdout;
ERR = stderr;
set_output(stdout, stderr);
}
break;

Expand All @@ -5041,17 +5053,19 @@ int check_options(int argc, char *argv[], char dostop, char command_line)
fputs
("Keine Datei für Fehler-Texte, stderr benutzt\n"
"Using stderr for error output\n", stderr);
ERR = stderr;
set_output(NULL, stderr);
break;
}
ERR = fopen(x, "w");
if (!ERR) {
F = fopen(x, "w");
if (!F) {
fprintf(stderr,
"Kann Datei `%s' nicht schreiben:\n"
"Can't write to file `%s':\n" " %s", x, x, strerror(errno));
exit(0);
}
set_output(NULL, F);
}

break;

case 'o':
Expand All @@ -5066,16 +5080,17 @@ int check_options(int argc, char *argv[], char dostop, char command_line)
fputs
("Leere Datei für 'geprüfte Datei', stdout benutzt\n"
"Empty file for checked file, using stdout\n", stderr);
OUT = stdout;
set_output(stdout, NULL);
break;
}
OUT = fopen(x, "w");
if (!OUT) {
F = fopen(x, "w");
if (!F) {
fprintf(stderr,
"Kann Datei `%s' nicht schreiben:\n"
"Can't write to file `%s':\n" " %s", x, x, strerror(errno));
exit(0);
}
set_output(F, NULL);
}
break;

Expand Down Expand Up @@ -5105,7 +5120,7 @@ int check_options(int argc, char *argv[], char dostop, char command_line)

case 's':
if (dostop) /* bei Optionen via "; ECHECK" nicht mehr machen */
ERR = stderr;
set_output(NULL, stderr);
break;

case 'n':
Expand Down Expand Up @@ -5268,7 +5283,8 @@ void process_order_file(int *faction_count, int *unit_count)
*/

while (!befehle_ende) {
switch (igetparam(order_buf)) {
int i = igetparam(order_buf);
switch (i) {
case P_LOCALE:
x = getstr();
get_order();
Expand Down Expand Up @@ -5546,7 +5562,7 @@ int main(int argc, char *argv[])
argc = ccommand(&argv); /* consolenabruf der parameter fuer macintosh added 15.6.00 chartus */
#endif

ERR = stderr;
set_output(stdout, stderr);
for (i = 0; i < MAX_ERRORS; i++)
errtxt[i] = Errors[i]; /* mit Defaults besetzten, weil NULL -> crash */

Expand All @@ -5557,7 +5573,7 @@ int main(int argc, char *argv[])
if (!path)
path = DEFAULT_PATH;
path = strdup(path);
ERR = stdout;
set_output(NULL, stdout);

filename = getenv("ECHECKOPTS");
if (filename)
Expand Down
140 changes: 136 additions & 4 deletions tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ extern int brief;
extern char show_warnings;
extern char *echeck_rules;
extern int line_no;
extern char no_comment;
extern int get_long_order_line();
extern void mock_input(const char * input);
extern void set_output(FILE *out, FILE *err);
extern char *getbuf(void);
extern char *igetstr(char *);
extern int btoi(char *s);
extern char *itob(int i);
extern void checkgiving(void);
extern void checkanorder(char *);
extern struct unit *newunit(int n, int t);
Expand All @@ -25,6 +29,15 @@ void process_order_file(int *faction_count, int *unit_count);

#define BUFSIZE 65000

#define DEFAULT_VERB 0
#define DEFAULT_BRIEF 2
#define DEFAULT_WARN 1

#define ERROR_FILE ".#echeck.test.error#"
#define OUTPUT_FILE ".#echeck.test.echo#"

static FILE *OUT = NULL, *ERR = NULL;

static int unit_no = 0;

static char input_buf[BUFSIZE];
Expand Down Expand Up @@ -57,6 +70,74 @@ static void assert_long_order(CuTest * tc, int expected_line) {
CuAssertIntEquals_Msg(tc, "long order line", expected_line, get_long_order_line());
}

void start_output() {
if (ERR)
fclose(ERR);
ERR = fopen(ERROR_FILE, "w");
if (OUT)
fclose(OUT);
OUT = fopen(OUTPUT_FILE, "w");
set_output(OUT, ERR);
}

void reset_output() {
if (ERR)
fclose(ERR);
if (OUT)
fclose(OUT);
remove(OUTPUT_FILE);
remove(ERROR_FILE);
set_output(stdout, stderr);
}

char * get_file_content(char *filename) {
FILE *IN;
long lSize;
char *buffer;

IN = fopen(filename, "rb");
if (IN) {
fseek(IN, 0L, SEEK_END);
lSize = ftell(IN);
rewind(IN);
buffer = malloc(sizeof(char) * (lSize + 1));
if (buffer) {
if (1 == fread(buffer, lSize, 1, IN)) {
buffer[lSize] = 0;
fclose(IN);
return buffer;
}
}
fclose(IN);
}
return "";
}

char * get_output() {
if (ERR)
fflush(ERR);
return get_file_content(ERROR_FILE);
}

char * get_echo() {
if (OUT)
fflush(OUT);
return get_file_content(OUTPUT_FILE);
}

void setup_test() {
no_comment = -128;
verbose = DEFAULT_VERB;
brief = DEFAULT_BRIEF;
show_warnings = DEFAULT_WARN;
reset_output();
}

static void test_tear_down(CuTest *tc)
{
reset_output();
}

static void test_process_nothing(CuTest * tc)
{
int faction_count = 0, unit_count = 0;
Expand Down Expand Up @@ -329,16 +410,57 @@ static void test_language(CuTest *tc)
test_orders(tc, "SPRACHE a b", 1, 0);
}

static void test_itob(CuTest *tc)
{
char buf[40];
sprintf(buf, "-%s-%s-%s-%s", itob(btoi("1111")), itob(btoi("2222")), itob(btoi("3333")), itob(btoi("4444")));
CuAssertStrEquals(tc, buf, "-1111-2222-3333-4444");
// sprintf(buf, "-%s-", itob(btoi("1111111")));
CuAssertIntEquals(tc, 1, btoi("22222"));
}

static void test_leave_ship_on(CuTest *tc)
{
char *output;

show_warnings = 5;
brief = 0;

start_output();
mock_input("ERESSEA 1 \"password\"\nREGION 3,3 ; null\nEINHEIT cap ; Captain [1,20$,Sshp1]\nNACH o\nEINHEIT 2 ; On Ship [1,20$,sshp1]\nNACH w\nEINHEIT 3; a [1,20$]\nNAECHSTER\n");
error_count = warning_count = 0;
process_order_file(0, 0);
CuAssertIntEquals(tc, 0, error_count);
CuAssertIntEquals(tc, 1, warning_count);

output = get_output();
CuAssertTrue(tc, 0 < strstr(output, "Warnung zur Zeile 5: Einheit 2 auf Schiff shp1 hat sich schon bewegt."));
free(output);
reset_output();

setup_test();
}

static void test_leave_ship_off(CuTest *tc)
{
show_warnings = 1;
mock_input("ERESSEA 1 \"password\"\nEINHEIT 1\nNAECHSTER\n");
mock_input("ERESSEA 1 \"password\"\nREGION 3,3 ; null\nEINHEIT cap ; Captain [1,20$,Sshp1]\nNACH o\nEINHEIT 2 ; On Ship [1,20$,sshp1]\nNACH w\nNAECHSTER\n");
error_count = warning_count = 0;
process_order_file(0, 0);
CuAssertIntEquals(tc, 0, error_count);
CuAssertIntEquals(tc, 0, warning_count);
show_warnings = DEFAULT_WARN;
}

int AddTestSuites(CuSuite * suite, const char * args)
{
char * names = (args && strcmp(args, "all")!=0) ? strdup(args) : strdup("echeck,process,common,give,destroy,entertain,claim,e3,alliance,plant");
char * names = (args && strcmp(args, "all")!=0) ? strdup(args) : strdup("echeck,process,common,give,destroy,entertain,claim,e3,alliance,plant,ship");
char * name = strtok(names, ",");
CuSuite * cs;

while (name) {
verbose = 0;
brief=2;
show_warnings = 1;
setup_test();

if (strcmp(name, "echeck")==0) {
cs = CuSuiteNew();
Expand Down Expand Up @@ -388,6 +510,13 @@ int AddTestSuites(CuSuite * suite, const char * args)
SUITE_ADD_TEST(cs, test_language);
CuSuiteAddSuite(suite, cs);
}
else if (strcmp(name, "ship")==0) {
cs = CuSuiteNew();
SUITE_ADD_TEST(cs, test_itob);
SUITE_ADD_TEST(cs, test_leave_ship_on);
SUITE_ADD_TEST(cs, test_leave_ship_off);
CuSuiteAddSuite(suite, cs);
}
/************* e2 only tests **************/
else if (strcmp(echeck_rules, "e2") == 0) {
if (strcmp(name, "entertain") == 0) {
Expand All @@ -412,5 +541,8 @@ int AddTestSuites(CuSuite * suite, const char * args)
}
name = strtok(0, ",");
}
cs = CuSuiteNew();
SUITE_ADD_TEST(cs, test_tear_down);
CuSuiteAddSuite(suite, cs);
return 0;
}