Mercurial > fife-parpg
comparison tests/core_tests/test_dat2.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 #include <iostream> | |
24 #include <iomanip> | |
25 | |
26 // Platform specific includes | |
27 | |
28 // 3rd party library includes | |
29 | |
30 // FIFE includes | |
31 // These includes are split up in two parts, separated by one empty line | |
32 // First block: files included from the FIFE root src directory | |
33 // Second block: files included from the same folder | |
34 #include "vfs/vfs.h" | |
35 #include "util/time/timemanager.h" | |
36 #include "vfs/vfs.h" | |
37 #include "vfs/vfsdirectory.h" | |
38 #include "vfs/dat/dat2.h" | |
39 #include "vfs/raw/rawdata.h" | |
40 #include "util/base/exception.h" | |
41 | |
42 #include "fife_unit_test.h" | |
43 | |
44 using boost::unit_test::test_suite; | |
45 using namespace FIFE; | |
46 | |
47 // Environment | |
48 struct environment { | |
49 boost::shared_ptr<TimeManager> timemanager; | |
50 | |
51 environment() | |
52 : timemanager(new TimeManager()) {} | |
53 }; | |
54 | |
55 using boost::unit_test::test_suite; | |
56 using namespace FIFE; | |
57 | |
58 static const std::string COMPRESSED_FILE = "../data/dat2vfstest.dat"; | |
59 static const std::string RAW_FILE = "../data/test.map"; | |
60 | |
61 #ifdef FIFE_BOOST_VERSION_103300 | |
62 void test_decoder() { | |
63 #else | |
64 BOOST_AUTO_TEST_CASE( OGL_animtest ) { | |
65 #endif | |
66 environment env; | |
67 | |
68 boost::shared_ptr<VFS> vfs(new VFS()); | |
69 vfs->addSource(new VFSDirectory(vfs.get())); | |
70 | |
71 if ((!vfs->exists(COMPRESSED_FILE))) { | |
72 BOOST_ERROR("Test source " << COMPRESSED_FILE << " not found"); | |
73 return; | |
74 } | |
75 | |
76 vfs->addSource(new DAT2(vfs.get(), COMPRESSED_FILE)); | |
77 | |
78 if ((!vfs->exists(RAW_FILE)) || (!vfs->exists("dat2vfstest.map"))) { | |
79 BOOST_ERROR("Test files not found"); | |
80 } | |
81 | |
82 RawData* fraw = vfs->open(RAW_FILE); | |
83 RawData* fcomp = vfs->open("dat2vfstest.map"); | |
84 | |
85 if (fraw->getDataLength() != fcomp->getDataLength()) { | |
86 std::cout << "raw length = " << fraw->getDataLength() \ | |
87 << ", compressed length = " << fcomp->getDataLength() << std::endl; | |
88 BOOST_ERROR("Data length mismatch"); | |
89 } else { | |
90 std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; | |
91 } | |
92 | |
93 unsigned int smaller_len = fraw->getDataLength(); | |
94 if (fcomp->getDataLength() < smaller_len) { | |
95 smaller_len = fcomp->getDataLength(); | |
96 } | |
97 | |
98 uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; | |
99 uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; | |
100 fraw->readInto(d_raw,fraw->getDataLength()); | |
101 fcomp->readInto(d_comp,fcomp->getDataLength()); | |
102 | |
103 std::cout << "scanning data..." << std::endl; | |
104 for (unsigned int i = 0; i < smaller_len; i++) { | |
105 uint8_t rawc = d_raw[i]; | |
106 uint8_t compc = d_comp[i]; | |
107 if (rawc != compc) { | |
108 BOOST_ERROR("Data mismatch"); | |
109 std::cout | |
110 << "raw: " << std::setbase(16) << rawc | |
111 << " comp: " << std::setbase(16) << compc << std::endl; | |
112 break; | |
113 } | |
114 } | |
115 std::cout << "scanning finished" << std::endl; | |
116 delete[] d_raw; | |
117 delete[] d_comp; | |
118 delete fraw; | |
119 delete fcomp; | |
120 } | |
121 | |
122 #ifdef FIFE_BOOST_VERSION_103300 | |
123 test_suite* init_unit_test_suite(int argc, char** const argv) { | |
124 test_suite* test = BOOST_TEST_SUITE("DAT2 tests"); | |
125 test->add(BOOST_TEST_CASE(&test_decoder), 0); | |
126 return test; | |
127 } | |
128 #endif |