KUDr@3900: /* $Id$ */ KUDr@3900: KUDr@3900: #define UNITTEST KUDr@3900: KUDr@3900: #include "../../stdafx.h" KUDr@3900: KUDr@3900: EXTERN_C_BEGIN KUDr@3900: #include "../../macros.h" KUDr@3900: #include "../../tile.h" KUDr@3900: #include "../../openttd.h" KUDr@3900: #include "../../map.h" KUDr@3900: #include "../../rail.h" KUDr@3900: EXTERN_C_END KUDr@3900: KUDr@3900: //#include "../track_dir.hpp" KUDr@3900: KUDr@3900: #include "../yapf.hpp" KUDr@3900: KUDr@3900: #include "../autocopyptr.hpp" KUDr@3900: KUDr@3900: #include "unittest.h" KUDr@3900: KUDr@3900: #include "test_autocopyptr.h" KUDr@3900: #include "test_binaryheap.h" KUDr@3900: #include "test_fixedsizearray.h" KUDr@3900: #include "test_blob.h" KUDr@3900: #include "test_hashtable.h" KUDr@3900: #include "test_yapf.h" KUDr@3900: KUDr@3900: int _total_pf_time_us = 0; KUDr@3900: KUDr@3900: int num_tests_failed = 0; KUDr@3900: int num_tests_total = 0; KUDr@3900: bool _dbg = false; KUDr@3900: KUDr@3900: int do_test(const char* name, TESTPROC test_proc, bool silent) KUDr@3900: { KUDr@3900: printf("%s ", name); KUDr@3900: if (!silent) {printf("[enter]:"); getc(stdin);} KUDr@3900: _dbg = !silent; KUDr@3900: fflush(stdout); KUDr@3900: int res = test_proc(silent); KUDr@3900: if (res == 0) KUDr@3900: { KUDr@3900: printf("%s OK\n", silent ? "..." : "\n"); KUDr@3900: } KUDr@3900: else { KUDr@3900: printf("\n ERROR! (0x%X)\n", res); KUDr@3900: printf("\nFailed cases:"); KUDr@3900: int num_failed = 0; KUDr@3900: for(int i = 0; i < 32; i++) { KUDr@3900: if (((1 << i) & res) != 0) { KUDr@3900: printf(" %d", i); KUDr@3900: num_failed++; KUDr@3900: } KUDr@3900: } KUDr@3900: printf("\n\nTotal: %d cases failed\n\n", num_failed); KUDr@3900: } KUDr@3900: KUDr@3900: num_tests_total++; KUDr@3900: if (res != 0) num_tests_failed++; KUDr@3900: KUDr@3900: return (res == 0) ? 0 : 1; KUDr@3900: } KUDr@3900: KUDr@3900: struct TEST_RECORD { KUDr@3900: const char* name; KUDr@3900: TESTPROC testproc; KUDr@3900: }; KUDr@3900: KUDr@3900: TEST_RECORD tests[] = { KUDr@3900: {"AutoCopyPtr test" , &TestAutoCopyPtr }, KUDr@3900: {"BinaryHeap test 1" , &TestBinaryHeap1 }, KUDr@3900: {"BinaryHeap test 2" , &TestBinaryHeap2 }, KUDr@3900: {"FixedSizeArray test", &TestFixedSizeArray }, KUDr@3900: {"Array test" , &TestArray }, KUDr@3900: {"Blob test 1" , &TestBlob1 }, KUDr@3900: {"Blob test 2" , &TestBlob2 }, KUDr@3900: {"HashTable test 1" , &TestHashTable1 }, KUDr@3900: {"Yapf test 1" , &CTestYapf1::stTestAstar }, KUDr@3900: {"Yapf test 2" , &CTestYapf2::stTestAstar }, KUDr@3900: KUDr@3900: {NULL , NULL }, KUDr@3900: }; KUDr@3900: KUDr@3900: int main(int argc, char** argv) KUDr@3900: { KUDr@3900: bool silent = (argc == 1); KUDr@3900: KUDr@3900: for (TEST_RECORD* tr = tests; tr->name != NULL; tr++) KUDr@3900: do_test(tr->name, tr->testproc, silent); KUDr@3900: KUDr@3900: if (num_tests_failed == 0) KUDr@3900: printf("\nALL %d TESTS PASSED OK!\n\n", num_tests_total); KUDr@3900: else KUDr@3900: printf("\n****** %d (from %d of total) TEST(S) FAILED! ******\n", num_tests_failed, num_tests_total); KUDr@3900: return 0; KUDr@3900: } KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: extern "C" KUDr@3900: const TileIndexDiffC _tileoffs_by_dir[] = { KUDr@3900: {-1, 0}, KUDr@3900: { 0, 1}, KUDr@3900: { 1, 0}, KUDr@3900: { 0, -1} KUDr@3900: }; KUDr@3900: KUDr@3900: extern "C" KUDr@3900: const byte _ffb_64[128] = { KUDr@3900: 0,0,1,0,2,0,1,0, KUDr@3900: 3,0,1,0,2,0,1,0, KUDr@3900: 4,0,1,0,2,0,1,0, KUDr@3900: 3,0,1,0,2,0,1,0, KUDr@3900: 5,0,1,0,2,0,1,0, KUDr@3900: 3,0,1,0,2,0,1,0, KUDr@3900: 4,0,1,0,2,0,1,0, KUDr@3900: 3,0,1,0,2,0,1,0, KUDr@3900: KUDr@3900: 0,0,0,2,0,4,4,6, KUDr@3900: 0,8,8,10,8,12,12,14, KUDr@3900: 0,16,16,18,16,20,20,22, KUDr@3900: 16,24,24,26,24,28,28,30, KUDr@3900: 0,32,32,34,32,36,36,38, KUDr@3900: 32,40,40,42,40,44,44,46, KUDr@3900: 32,48,48,50,48,52,52,54, KUDr@3900: 48,56,56,58,56,60,60,62, KUDr@3900: }; KUDr@3900: KUDr@3900: /* Maps a trackdir to the (4-way) direction the tile is exited when following KUDr@3900: * that trackdir */ KUDr@3900: extern "C" KUDr@3900: const DiagDirection _trackdir_to_exitdir[] = { KUDr@3900: DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE, KUDr@3900: DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE, KUDr@3900: }; KUDr@3900: KUDr@3900: /* Maps a diagonal direction to the all trackdirs that are connected to any KUDr@3900: * track entering in this direction (including those making 90 degree turns) KUDr@3900: */ KUDr@3900: extern "C" KUDr@3900: const TrackdirBits _exitdir_reaches_trackdirs[] = { KUDr@3900: TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */ KUDr@3900: TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ KUDr@3900: TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ KUDr@3900: TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ KUDr@3900: }; KUDr@3900: KUDr@3900: /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ KUDr@3900: extern "C" KUDr@3900: const TrackdirBits _track_crosses_trackdirs[] = { KUDr@3900: TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ KUDr@3900: TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ KUDr@3900: TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ KUDr@3900: TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ KUDr@3900: TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ KUDr@3900: TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E /* TRACK_RIGHT */ KUDr@3900: }; KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: