comparison tests/core_tests/test_zip.cpp @ 44:5a2db5e7ab54

renamed unittest++ based tests as they were with boost
author jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 13 Jul 2008 07:52:58 +0000
parents tests/core_tests/test_zip++.cpp@4c8334b0ab30
children 8c073dd2d3a3
comparison
equal deleted inserted replaced
43:6daa907234e1 44:5a2db5e7ab54
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 "util/time/timemanager.h"
37 #include "vfs/vfs.h"
38 #include "vfs/vfsdirectory.h"
39 #include "vfs/zip/zipsource.h"
40 #include "vfs/raw/rawdata.h"
41 #include "util/base/exception.h"
42
43 using namespace FIFE;
44
45 // Environment
46 struct environment {
47 boost::shared_ptr<TimeManager> timemanager;
48
49 environment()
50 : timemanager(new TimeManager()) {}
51 };
52
53 using namespace FIFE;
54
55 static const std::string COMPRESSED_FILE = "../../tests/data/testmap.zip";
56 static const std::string RAW_FILE = "../../tests/data/test.map";
57
58 TEST(test_decoder) {
59 environment env;
60 boost::shared_ptr<VFS> vfs(new VFS());
61 vfs->addSource(new VFSDirectory(vfs.get()));
62
63 CHECK(vfs->exists(COMPRESSED_FILE));
64 vfs->addSource(new ZipSource(vfs.get(), COMPRESSED_FILE));
65
66 CHECK_THROW(vfs->open("does-not-exist"), NotFound);
67 std::set<std::string> dirlist = vfs->listDirectories("ziptest_content");
68
69 CHECK(dirlist.size() == 4);
70 CHECK(std::find(dirlist.begin(), dirlist.end(), "maps") != dirlist.end());
71 CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir1") != dirlist.end());
72 CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir2") != dirlist.end());
73 CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir3") != dirlist.end());
74
75 std::set<std::string> filelist = vfs->listFiles("ziptest_content");
76 CHECK(filelist.size() == 0);
77 filelist = vfs->listFiles("ziptest_content/testdir1");
78
79 CHECK(filelist.size() == 4);
80 CHECK(std::find(filelist.begin(), filelist.end(), "file") != filelist.end());
81 CHECK(std::find(filelist.begin(), filelist.end(), "file-a") != filelist.end());
82 CHECK(std::find(filelist.begin(), filelist.end(), "file-b") != filelist.end());
83 CHECK(std::find(filelist.begin(), filelist.end(), "file-c") != filelist.end());
84
85 CHECK(vfs->listFiles("ziptest_content/testdir3").size() == 0);
86 CHECK(vfs->listDirectories("ziptest_content/testdir1").size() == 0);
87
88 CHECK(vfs->exists(RAW_FILE) && vfs->exists("ziptest_content/maps/test.map"));
89 RawData* fraw = vfs->open(RAW_FILE);
90 RawData* fcomp = vfs->open("ziptest_content/maps/test.map");
91
92 CHECK(fraw->getDataLength() == fcomp->getDataLength());
93 std::cout << "9" << std::endl;
94 unsigned int smaller_len = fraw->getDataLength();
95 if (fcomp->getDataLength() < smaller_len) {
96 smaller_len = fcomp->getDataLength();
97 }
98
99 uint8_t* d_raw = new uint8_t[fraw->getDataLength()];
100 uint8_t* d_comp = new uint8_t[fcomp->getDataLength()];
101 fraw->readInto(d_raw,fraw->getDataLength());
102 fcomp->readInto(d_comp,fcomp->getDataLength());
103
104 std::cout << "scanning data..." << std::endl;
105 for (unsigned int i = 0; i < smaller_len; i++) {
106 uint8_t rawc = d_raw[i];
107 uint8_t compc = d_comp[i];
108 CHECK(rawc == compc);
109
110 }
111 std::cout << "scanning finished" << std::endl;
112 delete[] d_raw;
113 delete[] d_comp;
114 delete fraw;
115 delete fcomp;
116 }
117
118 int main() {
119 return UnitTest::RunAllTests();
120 }