From: Laurent Mazet Date: Sat, 29 Jun 2024 13:06:07 +0000 (+0200) Subject: add tests X-Git-Tag: v1.0~1 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=7713f44c3120631d525400716e89882ac6c2eb8c;p=solitaire.git add tests --- diff --git a/.gitignore b/.gitignore index 2cab4ec..913136d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ *.exe *.log *.o -*.sol *.diff diff --git a/bogus.sol b/bogus.sol new file mode 100644 index 0000000..388350f --- /dev/null +++ b/bogus.sol @@ -0,0 +1,4 @@ +width: 7 +height: 7 +bogus: 42 +tab: " OOO OOX OOOXOOXOOOXXXXOOOOOXX OOXXX XOX " diff --git a/constant.c b/constant.c index f5ababd..2ac694d 100644 --- a/constant.c +++ b/constant.c @@ -52,7 +52,7 @@ board_t _board_english = {7, 7, board_t _board_diamond = {9, 9, " X " " XXX " - " XXXXx " + " XXXXX " " XXXXXXX " "XXXXOXXXX" " XXXXXXX " diff --git a/display.c b/display.c index 34b1cc1..c32ffe4 100644 --- a/display.c +++ b/display.c @@ -431,8 +431,8 @@ char *savewindow (int length, int xoffset, int yoffset) if (name) { for (j = length - 1; j >= 0; j--) { - if (name[i] == ' ') { - name[i] = '\0'; + if (name[j] == ' ') { + name[j] = '\0'; } } if (*name == '\0') { diff --git a/solitaire.c b/solitaire.c index 0abeb74..f55e823 100644 --- a/solitaire.c +++ b/solitaire.c @@ -22,7 +22,7 @@ char *version = "0.1"; char *boardname = "french"; char *filename = NULL; -int scale = 0; +int scale = 2; int xoffset = 1; int yoffset = 1; @@ -114,26 +114,36 @@ int main (int argc, char *argv[]) } /* check */ - if ((scale < 0) || (scale > 4)) { + if ((scale < 0) || (scale > 3)) { VERBOSE (ERROR, fprintf (stderr, "incorrect scale (%d)\n", scale)); + return 1; } /* load playground */ board_t *board = NULL; if (filename) { char *buffer = readdata (filename); + if (buffer == NULL) { + VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", filename)); + return 1; + } board = loadboard (buffer); free (buffer); + if (board == NULL) { + VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", filename)); + return 1; + } } else if (boardname) { board_t *temp = getboard (boardname); if (temp == (board_t *)(-1)) { return 0; } + if (temp == NULL) { + VERBOSE (ERROR, fprintf (stderr, "unknown board (%s)\n", boardname)); + return 1; + } board = copyboard (temp); } - if (board == NULL) { - return 1; - } setscale (board, scale); /* init curses window */ @@ -271,16 +281,23 @@ int main (int argc, char *argv[]) } /* test: solitaire.exe -b 2>&1 | grep 'no board' */ -/* test: solitaire.exe -b bogus 2>&1 | grep 'unkonwn board' */ +/* test: solitaire.exe -b bogus 2>&1 | grep 'unknown board' */ /* test: solitaire.exe -b list | grep 'board:' */ /* test: solitaire.exe -f 2>&1 | grep 'no file' */ /* test: solitaire.exe -f nofile.sol 2>&1 | grep "can't read file" */ /* test: solitaire.exe -f bogus.sol 2>&1 | grep 'incorrect file' */ /* test: solitaire.exe -h | grep usage */ -/* test: solitaire.exe -s 2>&1 | grep missing */ +/* test: solitaire.exe -s 2>&1 | grep 'no scale' */ /* test: solitaire.exe -s 4 2>&1 | grep incorrect */ /* test: solitaire.exe -v 2>&1 | grep missing */ /* test: solitaire.exe _ 2>&1 | grep invalid */ -/* test: echo -n q | solitaire.exe */ +/* test: { echo lllcksa.sol; sleep 1; echo -n q; } | solitaire.exe -v 4 */ +/* test: { echo -en 'lkclsb.sol\e'; sleep 1; echo -e ' b\b\b '; echo -n q; } | solitaire.exe -v 3 -f a.sol */ +/* test: { echo -n llllkkckjjicljj; sleep 1; echo -n x; sleep 1; echo -n q; } | solitaire.exe -s 0 -b german */ +/* test: { echo -n kkkklcljj; sleep 1; echo -n q; } | solitaire.exe -s 1 -b assymetric */ +/* test: { echo -n lllkckii; sleep 1; echo -n q; } | solitaire.exe -s 2 -b english */ +/* test: { echo -n llllkkckii; sleep 1; echo -n q; } | solitaire.exe -s 3 -b diamond */ +/* test: { echo -n clckcjci; sleep 1; echo -n q; } | solitaire.exe -f test.sol */ +/* test: { echo -n clckcj; sleep 1; echo -n xxx; sleep 1; echo -n iickclci; sleep 1; echo -n xxx; sleep 1; echo -n q; } | solitaire.exe -f test.sol */ /* vim: set ts=4 sw=4 et: */ diff --git a/test.sol b/test.sol new file mode 100644 index 0000000..e92513c --- /dev/null +++ b/test.sol @@ -0,0 +1,3 @@ +width: 3 +height: 3 +tab: "XXOXXXOXO"