| 63 static CX_TEST(test_real_pgn) { |
63 static CX_TEST(test_real_pgn) { |
| 64 static unsigned index = 0; |
64 static unsigned index = 0; |
| 65 ++index; |
65 ++index; |
| 66 GameState gamestate; |
66 GameState gamestate; |
| 67 gamestate_init(&gamestate); |
67 gamestate_init(&gamestate); |
| |
68 char *chkpgn = NULL; |
| 68 CX_TEST_DO { |
69 CX_TEST_DO { |
| 69 const enum expected_result rs = pgn_data[index-1][0]; |
70 const enum expected_result rs = pgn_data[index-1][0]; |
| 70 const char *pgn = pgn_data[index-1]+1; |
71 const char *pgn = pgn_data[index-1]+1; |
| 71 int result = parse_pgn(pgn, &gamestate); |
72 int result = parse_pgn(pgn, &gamestate); |
| 72 char msg[64]; |
73 char msg[64]; |
| 73 sprintf(msg, "failed to parse game%03u.pgn: code %d, pos: %zu", |
74 sprintf(msg, "failed to parse game%03u.pgn: code %d, pos: %zu", |
| 74 index, result, pgn_error_position()); |
75 index, result, pgn_error_position()); |
| 75 CX_TEST_ASSERTM(result == pgn_no_error, msg); |
76 CX_TEST_ASSERTM(result == pgn_no_error, msg); |
| 76 CX_TEST_CALL_SUBROUTINE(verify_expected_result, &gamestate, rs); |
77 CX_TEST_CALL_SUBROUTINE(verify_expected_result, &gamestate, rs); |
| |
78 |
| |
79 /* check if we get the PGN text back */ |
| |
80 chkpgn = create_pgn(&gamestate, false); |
| |
81 /* find move blocks (ignore the STR) */ |
| |
82 char *chkpgn_moves = strstr(chkpgn, "1. "); |
| |
83 const char *pgn_moves = strstr(pgn, "1. "); |
| |
84 /* revert the formatting (test data is also unformatted) */ |
| |
85 for (size_t i = 0; ; i++) { |
| |
86 if (chkpgn_moves[i] == '\n') chkpgn_moves[i] = ' '; |
| |
87 if (chkpgn_moves[i] == '\0') { |
| |
88 /* do not replace last line break */ |
| |
89 chkpgn_moves[i-1] = '\n'; |
| |
90 break; |
| |
91 } |
| |
92 } |
| |
93 |
| |
94 /* compare */ |
| |
95 CX_TEST_ASSERTM(strcmp(chkpgn_moves, pgn_moves) == 0, "PGN move text mismatch"); |
| 77 } |
96 } |
| |
97 free(chkpgn); |
| 78 gamestate_cleanup(&gamestate); |
98 gamestate_cleanup(&gamestate); |
| 79 } |
99 } |
| 80 |
100 |
| 81 CxTestSuite* test_real_pgn_suite(void) { |
101 CxTestSuite* test_real_pgn_suite(void) { |
| 82 CxTestSuite* suite = cx_test_suite_new("Real PGN Files"); |
102 CxTestSuite* suite = cx_test_suite_new("Real PGN Files"); |