[MediaWiki-commits] [Gerrit] openzim[master]: Adapt tests to new internal cluster API.

2017-03-25 Thread Kelson (Code Review)
Kelson has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/320243 )

Change subject: Adapt tests to new internal cluster API.
..


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
---
M zimlib/test/cluster.cpp
1 file changed, 48 insertions(+), 20 deletions(-)

Approvals:
  Kelson: Verified; Looks good to me, approved



diff --git a/zimlib/test/cluster.cpp b/zimlib/test/cluster.cpp
index c4c25e6..687c1e1 100644
--- a/zimlib/test/cluster.cpp
+++ b/zimlib/test/cluster.cpp
@@ -18,9 +18,12 @@
  */
 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #include 
 #include 
@@ -69,7 +72,9 @@
 
 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 @@
   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 @@
   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 @@
   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 @@
   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 @@
 #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 @@
   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 @@
   CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(0), 
cluster2.getBlobPtr(0) + cluster2.getBlobSize(0), blob0.data()));
   

[MediaWiki-commits] [Gerrit] openzim[master]: Adapt tests to new internal cluster API.

2016-11-07 Thread Kelson (Code Review)
Kelson has submitted this change and it was merged.

Change subject: Adapt tests to new internal cluster API.
..


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
---
M zimlib/test/cluster.cpp
1 file changed, 48 insertions(+), 20 deletions(-)

Approvals:
  Kelson: Verified; Looks good to me, approved



diff --git a/zimlib/test/cluster.cpp b/zimlib/test/cluster.cpp
index c4c25e6..687c1e1 100644
--- a/zimlib/test/cluster.cpp
+++ b/zimlib/test/cluster.cpp
@@ -18,9 +18,12 @@
  */
 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #include 
 #include 
@@ -69,7 +72,9 @@
 
 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 @@
   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 @@
   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 @@
   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 @@
   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 @@
 #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 @@
   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 @@
   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) + 

[MediaWiki-commits] [Gerrit] openzim[master]: Adapt tests to new internal cluster API.

2016-11-07 Thread Mgautierfr (Code Review)
Mgautierfr has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/320243

Change subject: Adapt tests to new internal cluster API.
..

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
---
M zimlib/test/cluster.cpp
1 file changed, 48 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/openzim refs/changes/43/320243/1

diff --git a/zimlib/test/cluster.cpp b/zimlib/test/cluster.cpp
index c4c25e6..687c1e1 100644
--- a/zimlib/test/cluster.cpp
+++ b/zimlib/test/cluster.cpp
@@ -18,9 +18,12 @@
  */
 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 #include 
 #include 
@@ -69,7 +72,9 @@
 
 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 @@
   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 @@
   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 @@
   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 @@
   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 @@
 #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 @@
   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 @@
   CXXTOOLS_UNIT_ASSERT(std::equal(cluster2.getBlobPtr(0), 
cluster2.getBlobPtr(0) + cluster2.getBlobSize(0), blob0.data()));