Mercurial > fife-parpg
comparison tests/core_tests/test_dat1.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 "vfs/vfsdirectory.h" | |
36 #include "vfs/dat/dat1.h" | |
37 #include "vfs/raw/rawdata.h" | |
38 #include "util/base/exception.h" | |
39 | |
40 #include "fife_unit_test.h" | |
41 | |
42 using boost::unit_test::test_suite; | |
43 using namespace FIFE; | |
44 | |
45 static const std::string COMPRESSED_FILE = "../data/dat1vfstest.dat"; | |
46 static const std::string RAW_FILE = "../data/test.map"; | |
47 | |
48 #ifdef FIFE_BOOST_VERSION_103300 | |
49 void test_decoder() { | |
50 #else | |
51 BOOST_AUTO_TEST_CASE( DAT1_test ) { | |
52 #endif | |
53 boost::shared_ptr<VFS> vfs(new VFS()); | |
54 vfs->addSource(new VFSDirectory(vfs.get())); | |
55 | |
56 if ((!vfs->exists(COMPRESSED_FILE))) { | |
57 BOOST_ERROR("Test source " << COMPRESSED_FILE << " not found"); | |
58 return; | |
59 } | |
60 | |
61 vfs->addSource(new DAT1(vfs.get(), COMPRESSED_FILE)); | |
62 | |
63 if ((!vfs->exists(RAW_FILE)) || (!vfs->exists("dat1vfstest.map"))) { | |
64 BOOST_ERROR("Test files not found"); | |
65 } | |
66 | |
67 RawData* fraw = vfs->open(RAW_FILE); | |
68 RawData* fcomp = vfs->open("dat1vfstest.map"); | |
69 | |
70 if (fraw->getDataLength() != fcomp->getDataLength()) { | |
71 std::cout << "raw length = " << fraw->getDataLength() \ | |
72 << ", compressed length = " << fcomp->getDataLength() << std::endl; | |
73 BOOST_ERROR("Data length mismatch"); | |
74 } else { | |
75 std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; | |
76 } | |
77 | |
78 unsigned int smaller_len = fraw->getDataLength(); | |
79 if (fcomp->getDataLength() < smaller_len) { | |
80 smaller_len = fcomp->getDataLength(); | |
81 } | |
82 | |
83 uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; | |
84 uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; | |
85 fraw->readInto(d_raw,fraw->getDataLength()); | |
86 fcomp->readInto(d_comp,fcomp->getDataLength()); | |
87 | |
88 std::cout << "scanning data..." << std::endl; | |
89 for (unsigned int i = 0; i < smaller_len; i++) { | |
90 uint8_t rawc = d_raw[i]; | |
91 uint8_t compc = d_comp[i]; | |
92 if (rawc != compc) { | |
93 BOOST_ERROR("Data mismatch"); | |
94 std::cout | |
95 << "raw: " << std::setbase(16) << rawc | |
96 << " comp: " << std::setbase(16) << compc << std::endl; | |
97 break; | |
98 } | |
99 } | |
100 std::cout << "scanning finished" << std::endl; | |
101 delete[] d_raw; | |
102 delete[] d_comp; | |
103 delete fraw; | |
104 delete fcomp; | |
105 } | |
106 | |
107 #ifdef FIFE_BOOST_VERSION_103300 | |
108 test_suite* init_unit_test_suite(int argc, char** const argv) { | |
109 test_suite* test = BOOST_TEST_SUITE("DAT1 tests"); | |
110 test->add(BOOST_TEST_CASE(&test_decoder), 0); | |
111 return test; | |
112 } | |
113 #endif |