1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
From: Matthieu Gautier <matthieu.gautier@mgautier.fr>
Date: Mon, 7 Nov 2016 19:53:26 +0100
Subject: Adapt tests to new internal cluster API.
- There is no more operator>>() on cluster. We should use init_from_stream.
- The stream must be a zim::ifstream not a std::istream.
Change-Id: I58b8e1d43b0973129d02393b83c3f248b77768fd
---
test/cluster.cpp | 68 +++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 48 insertions(+), 20 deletions(-)
diff --git a/test/cluster.cpp b/test/cluster.cpp
index c4c25e6..687c1e1 100644
--- a/test/cluster.cpp
+++ b/test/cluster.cpp
@@ -18,9 +18,12 @@
*/
#include <zim/cluster.h>
+#include <zim/fstream.h>
#include <zim/zim.h>
#include <sstream>
+#include <fstream>
#include <algorithm>
+#include <cstdio>
#include <cxxtools/unit/testsuite.h>
#include <cxxtools/unit/registertest.h>
@@ -69,7 +72,9 @@ class ClusterTest : public cxxtools::unit::TestSuite
void ReadWriteCluster()
{
- std::stringstream s;
+ std::string name = std::tmpnam(NULL);
+ std::ofstream os;
+ os.open(name.c_str());
zim::Cluster cluster;
@@ -81,20 +86,25 @@ class ClusterTest : public cxxtools::unit::TestSuite
cluster.addBlob(blob1.data(), blob1.size());
cluster.addBlob(blob2.data(), blob2.size());
- s << cluster;
+ os << cluster;
+ os.close();
+ zim::ifstream is(name);
zim::Cluster cluster2;
- s >> cluster2;
- CXXTOOLS_UNIT_ASSERT(!s.fail());
+ cluster2.init_from_stream(is, 0);
+ CXXTOOLS_UNIT_ASSERT(!is.fail());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.count(), 3);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(0), blob0.size());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(1), blob1.size());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(2), blob2.size());
+ std::remove(name.c_str());
}
void ReadWriteEmpty()
{
- std::stringstream s;
+ std::string name = std::tmpnam(NULL);
+ std::ofstream os;
+ os.open(name.c_str());
zim::Cluster cluster;
@@ -102,21 +112,26 @@ class ClusterTest : public cxxtools::unit::TestSuite
cluster.addBlob(0, 0);
cluster.addBlob(0, 0);
- s << cluster;
+ os << cluster;
+ os.close();
+ zim::ifstream is(name);
zim::Cluster cluster2;
- s >> cluster2;
- CXXTOOLS_UNIT_ASSERT(!s.fail());
+ cluster2.init_from_stream(is, 0);
+ CXXTOOLS_UNIT_ASSERT(!is.fail());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.count(), 3);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(0), 0);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(1), 0);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(2), 0);
+ std::remove(name.c_str());
}
#ifdef ENABLE_ZLIB
void ReadWriteClusterZ()
{
- std::stringstream s;
+ std::string name = std::tmpnam(NULL);
+ std::ofstream os;
+ os.open(name.c_str());
zim::Cluster cluster;
@@ -129,11 +144,13 @@ class ClusterTest : public cxxtools::unit::TestSuite
cluster.addBlob(blob2.data(), blob2.size());
cluster.setCompression(zim::zimcompZip);
- s << cluster;
+ os << cluster;
+ os.close();
+ zim::ifstream is(name);
zim::Cluster cluster2;
- s >> cluster2;
- CXXTOOLS_UNIT_ASSERT(!s.fail());
+ cluster2.init_from_stream(is, 0);
+ CXXTOOLS_UNIT_ASSERT(!is.fail());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.count(), 3);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getCompression(), zim::zimcompZip);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(0), blob0.size());
@@ -142,6 +159,7 @@ class ClusterTest : public cxxtools::unit::TestSuite
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(0), cluster2.getBlobPtr(0) + cluster2.getBlobSize(0), blob0.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(1), cluster2.getBlobPtr(1) + cluster2.getBlobSize(1), blob1.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(2), cluster2.getBlobPtr(2) + cluster2.getBlobSize(2), blob2.data()));
+ std::remove(name.c_str());
}
#endif
@@ -149,7 +167,9 @@ class ClusterTest : public cxxtools::unit::TestSuite
#ifdef ENABLE_BZIP2
void ReadWriteClusterBz2()
{
- std::stringstream s;
+ std::string name = std::tmpnam(NULL);
+ std::ofstream os;
+ os.open(name.c_str());
zim::Cluster cluster;
@@ -162,11 +182,13 @@ class ClusterTest : public cxxtools::unit::TestSuite
cluster.addBlob(blob2.data(), blob2.size());
cluster.setCompression(zim::zimcompBzip2);
- s << cluster;
+ os << cluster;
+ os.close();
+ zim::ifstream is(name);
zim::Cluster cluster2;
- s >> cluster2;
- CXXTOOLS_UNIT_ASSERT(!s.fail());
+ cluster2.init_from_stream(is, 0);
+ CXXTOOLS_UNIT_ASSERT(!is.fail());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.count(), 3);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getCompression(), zim::zimcompBzip2);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(0), blob0.size());
@@ -175,6 +197,7 @@ class ClusterTest : public cxxtools::unit::TestSuite
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(0), cluster2.getBlobPtr(0) + cluster2.getBlobSize(0), blob0.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(1), cluster2.getBlobPtr(1) + cluster2.getBlobSize(1), blob1.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(2), cluster2.getBlobPtr(2) + cluster2.getBlobSize(2), blob2.data()));
+ std::remove(name.c_str());
}
#endif
@@ -182,7 +205,9 @@ class ClusterTest : public cxxtools::unit::TestSuite
#ifdef ENABLE_LZMA
void ReadWriteClusterLzma()
{
- std::stringstream s;
+ std::string name = std::tmpnam(NULL);
+ std::ofstream os;
+ os.open(name.c_str());
zim::Cluster cluster;
@@ -195,11 +220,13 @@ class ClusterTest : public cxxtools::unit::TestSuite
cluster.addBlob(blob2.data(), blob2.size());
cluster.setCompression(zim::zimcompLzma);
- s << cluster;
+ os << cluster;
+ os.close();
+ zim::ifstream is(name);
zim::Cluster cluster2;
- s >> cluster2;
- CXXTOOLS_UNIT_ASSERT(!s.fail());
+ cluster2.init_from_stream(is, 0);
+ CXXTOOLS_UNIT_ASSERT(!is.fail());
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.count(), 3);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getCompression(), zim::zimcompLzma);
CXXTOOLS_UNIT_ASSERT_EQUALS(cluster2.getBlobSize(0), blob0.size());
@@ -208,6 +235,7 @@ class ClusterTest : public cxxtools::unit::TestSuite
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(0), cluster2.getBlobPtr(0) + cluster2.getBlobSize(0), blob0.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(1), cluster2.getBlobPtr(1) + cluster2.getBlobSize(1), blob1.data()));
CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(2), cluster2.getBlobPtr(2) + cluster2.getBlobSize(2), blob2.data()));
+ std::remove(name.c_str());
}
#endif
|