Skip to content

Commit

Permalink
Merge pull request #585 from openzim/small_fixes
Browse files Browse the repository at this point in the history
A series of small fixes.
  • Loading branch information
kelson42 authored Jul 7, 2021
2 parents 2990f07 + 9fb4cd3 commit 20c0e30
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

#define ANCHOR_TERM "0posanchor "

#define DEFAULT_CLUSTER_SIZE 1024*1024
#define DEFAULT_CLUSTER_SIZE 2*1024*1024
2 changes: 1 addition & 1 deletion src/writer/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void Cluster::write(int out_fd) const
}
clusterInfo += getCompression();
if (_write(out_fd, &clusterInfo, 1) == -1) {
throw std::runtime_error("Error writng");
throw std::runtime_error("Error writing");
}

// Open a comprestion stream if needed
Expand Down
13 changes: 13 additions & 0 deletions test/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ TEST(ClusterTest, read_write_cluster)
ASSERT_EQ(cluster2.getBlobSize(zim::blob_index_t(2)).v, blob2.size());
}

TEST(ClusterTest, read_write_no_content)
{
zim::writer::Cluster cluster(zim::zimcompNone);

cluster.close();
auto buffer = write_to_buffer(cluster, "\3garbage");
const auto cluster2shptr = zim::Cluster::read(zim::BufferReader(buffer), zim::offset_t(0));
zim::Cluster& cluster2 = *cluster2shptr;
ASSERT_EQ(cluster2.getCompression(), zim::zimcompNone);
ASSERT_EQ(cluster2.isExtended, false);
ASSERT_EQ(cluster2.count().v, 0U);
}

TEST(ClusterTest, read_write_empty)
{
zim::writer::Cluster cluster(zim::zimcompNone);
Expand Down
3 changes: 2 additions & 1 deletion test/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ makeTempFile(const char* name, const std::string& content);


template<typename T>
zim::Buffer write_to_buffer(const T& object)
zim::Buffer write_to_buffer(const T& object, const std::string& tail="")
{
TempFile tmpFile("test_temp_file");
const auto tmp_fd = tmpFile.fd();
object.write(tmp_fd);
write(tmp_fd, tail.data(), tail.size());
auto size = LSEEK(tmp_fd, 0, SEEK_END);

auto buf = zim::Buffer::makeBuffer(zim::zsize_t(size));
Expand Down

0 comments on commit 20c0e30

Please sign in to comment.