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 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/dat2.h"
38 #include "vfs/raw/rawdata.h"
39 #include "util/base/exception.h"
40 #include "util/time/timemanager.h"
41
42 using namespace FIFE;
43
44 static const std::string COMPRESSED_FILE = "../data/dat2vfstest.dat";
45 static const std::string RAW_FILE = "../data/test.map";
46 TEST(DAT2_test){
47
48 boost::shared_ptr<TimeManager> timemanager(new TimeManager());
49
50 boost::shared_ptr<VFS> vfs(new VFS());
51 vfs->addSource(new VFSDirectory(vfs.get()));
52 CHECK(vfs->exists(COMPRESSED_FILE));
53
54 try {
55 std::cout << "adding Source" << std::endl;
56 vfs->addSource(new DAT2(vfs.get(), COMPRESSED_FILE));
57 std::cout << "added Source" << std::endl;
58 }
59 catch (Exception& e)
60 {
61 std::cout << e.getMessage() << std::endl;
62 }
63
64 CHECK(vfs->exists(RAW_FILE));
65 CHECK(vfs->exists("dat2vfstest.map"));
66
67 FIFE::RawData* fraw = vfs->open(RAW_FILE);
68 FIFE::RawData* fcomp = vfs->open("dat2vfstest.map");
69
70 CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength());
71 //std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl;
72
73 unsigned int smaller_len = fraw->getDataLength();
74 if (fcomp->getDataLength() < smaller_len) {
75 smaller_len = fcomp->getDataLength();
76 }
77
78 uint8_t* d_raw = new uint8_t[fraw->getDataLength()];
79 uint8_t* d_comp = new uint8_t[fcomp->getDataLength()];
80 fraw->readInto(d_raw,fraw->getDataLength());
81 fcomp->readInto(d_comp,fcomp->getDataLength());
82 //std::cout << "scanning data..." << std::endl;
83 for (unsigned int i = 0; i < smaller_len; i++) {
84 uint8_t rawc = d_raw[i];
85 uint8_t compc = d_comp[i];
86 CHECK_EQUAL(compc, rawc);
87 //std::cout
88 // << "raw: " << std::setbase(16) << rawc
89 // << " comp: " << std::setbase(16) << compc << std::endl;
90 break;
91
92
93 }
94 //std::cout << "scanning finished" << std::endl;
95
96 delete[] d_raw;
97 delete[] d_comp;
98 delete fraw;
99 delete fcomp;
100
101 }