| 38 |
38 |
| 39 static CX_TEST(test_real_pgn) { |
39 static CX_TEST(test_real_pgn) { |
| 40 static unsigned index = 0; |
40 static unsigned index = 0; |
| 41 ++index; |
41 ++index; |
| 42 GameState gamestate; |
42 GameState gamestate; |
| |
43 // TODO: fix that we need an initialized game state for parsing PGNs |
| 43 gamestate_init(&gamestate); |
44 gamestate_init(&gamestate); |
| 44 CX_TEST_DO { |
45 CX_TEST_DO { |
| 45 int result = parse_pgn(pgn_data[index-1], &gamestate); |
46 int result = parse_pgn(pgn_data[index-1], &gamestate); |
| 46 char msg[64]; |
47 char msg[64]; |
| 47 sprintf(msg, "failed to parse game%03u.pgn: code %d, pos: %zu", |
48 sprintf(msg, "failed to parse game%03u.pgn: code %d, pos: %zu", |
| 49 CX_TEST_ASSERTM(result == pgn_no_error, msg); |
50 CX_TEST_ASSERTM(result == pgn_no_error, msg); |
| 50 } |
51 } |
| 51 gamestate_cleanup(&gamestate); |
52 gamestate_cleanup(&gamestate); |
| 52 } |
53 } |
| 53 |
54 |
| |
55 static CX_TEST_SUBROUTINE(test_real_pgn_stalemate_sub, |
| |
56 GameState *gamestate, int game) { |
| |
57 // TODO: fix that we need an initialized game state for parsing PGNs |
| |
58 gamestate_init(gamestate); |
| |
59 CX_TEST_ASSERT(0 == parse_pgn(pgn_data[game], gamestate)); |
| |
60 CX_TEST_ASSERT(gamestate->stalemate); |
| |
61 CX_TEST_ASSERT(!gamestate->wresign); |
| |
62 CX_TEST_ASSERT(!gamestate->bresign); |
| |
63 CX_TEST_ASSERT(!gamestate->checkmate); |
| |
64 CX_TEST_ASSERT(!gamestate->remis); |
| |
65 CX_TEST_ASSERT(!gamestate->threefold); |
| |
66 gamestate_cleanup(gamestate); |
| |
67 } |
| |
68 |
| |
69 static CX_TEST(test_real_pgn_stalemate) { |
| |
70 GameState gamestate; |
| |
71 CX_TEST_DO { |
| |
72 /* the below mentioned games end in stalemate position */ |
| |
73 CX_TEST_CALL_SUBROUTINE(test_real_pgn_stalemate_sub, &gamestate, 128); |
| |
74 CX_TEST_CALL_SUBROUTINE(test_real_pgn_stalemate_sub, &gamestate, 146); |
| |
75 } |
| |
76 gamestate_cleanup(&gamestate); |
| |
77 } |
| |
78 |
| 54 CxTestSuite* test_real_pgn_suite(void) { |
79 CxTestSuite* test_real_pgn_suite(void) { |
| 55 CxTestSuite* suite = cx_test_suite_new("Real PGN Files"); |
80 CxTestSuite* suite = cx_test_suite_new("Real PGN Files"); |
| 56 for (unsigned i = 0 ; i < 150 ; i++) { |
81 for (unsigned i = 0 ; i < 150 ; i++) { |
| 57 cx_test_register(suite, test_real_pgn); |
82 cx_test_register(suite, test_real_pgn); |
| 58 } |
83 } |
| |
84 cx_test_register(suite, test_real_pgn_stalemate); |
| 59 return suite; |
85 return suite; |
| 60 } |
86 } |
| 61 |
87 |
| 62 const char pgn_data[150][1500] = { |
88 const char pgn_data[150][1500] = { |
| 63 { |
89 { |