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 | 4c8334b0ab30 |
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 #include "fife_unittest++.h" | |
28 | |
29 // 3rd party library includes | |
30 | |
31 // FIFE includes | |
32 // These includes are split up in two parts, separated by one empty line | |
33 // First block: files included from the FIFE root src directory | |
34 // Second block: files included from the same folder | |
35 #include "vfs/vfs.h" | |
36 #include "vfs/vfsdirectory.h" | |
37 #include "vfs/dat/dat1.h" | |
38 #include "vfs/dat/dat2.h" | |
39 #include "vfs/raw/rawdata.h" | |
40 #include "util/base/exception.h" | |
41 | |
42 using namespace FIFE; | |
43 | |
44 static const std::string COMPRESSED_FILE = "../../tests/data/dat1vfstest.dat"; | |
45 static const std::string RAW_FILE = "../../tests/data/test.map"; | |
46 | |
47 TEST(DAT1_test){ | |
48 | |
49 boost::shared_ptr<FIFE::VFS> vfs(new FIFE::VFS()); | |
50 vfs->addSource(new FIFE::VFSDirectory(vfs.get())); | |
51 CHECK(vfs->exists(COMPRESSED_FILE)); | |
52 | |
53 | |
54 vfs->addSource(new FIFE::DAT1(vfs.get(), COMPRESSED_FILE)); | |
55 | |
56 CHECK(vfs->exists(RAW_FILE)); | |
57 CHECK(vfs->exists("dat1vfstest.map")); | |
58 | |
59 FIFE::RawData* fraw = vfs->open(RAW_FILE); | |
60 FIFE::RawData* fcomp = vfs->open("dat1vfstest.map"); | |
61 | |
62 CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength()); | |
63 //std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; | |
64 | |
65 unsigned int smaller_len = fraw->getDataLength(); | |
66 if (fcomp->getDataLength() < smaller_len) { | |
67 smaller_len = fcomp->getDataLength(); | |
68 } | |
69 | |
70 uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; | |
71 uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; | |
72 fraw->readInto(d_raw,fraw->getDataLength()); | |
73 fcomp->readInto(d_comp,fcomp->getDataLength()); | |
74 //std::cout << "scanning data..." << std::endl; | |
75 for (unsigned int i = 0; i < smaller_len; i++) { | |
76 uint8_t rawc = d_raw[i]; | |
77 uint8_t compc = d_comp[i]; | |
78 CHECK_EQUAL(compc, rawc); | |
79 //std::cout | |
80 // << "raw: " << std::setbase(16) << rawc | |
81 // << " comp: " << std::setbase(16) << compc << std::endl; | |
82 break; | |
83 | |
84 | |
85 } | |
86 //std::cout << "scanning finished" << std::endl; | |
87 | |
88 delete[] d_raw; | |
89 delete[] d_comp; | |
90 delete fraw; | |
91 delete fcomp; | |
92 | |
93 } |