Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Expand tests for tag_long_array
Browse files Browse the repository at this point in the history
Format long arrays with "l" suffixes
Version bump
  • Loading branch information
ljfa-ag committed May 21, 2018
1 parent 82366cb commit c7cb857
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0)
project(libnbt++
VERSION 2.4.1)
VERSION 2.5)

# supported configure options
option(NBT_BUILD_SHARED "Build shared libraries" OFF)
Expand Down
2 changes: 1 addition & 1 deletion src/text/json_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace //anonymous
os << "[";
for(unsigned int i = 0; i < la.size(); ++i)
{
os << la[i];
os << la[i] << "l";
if(i != la.size()-1)
os << ", ";
}
Expand Down
10 changes: 7 additions & 3 deletions test/read_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class read_test : public CxxTest::TestSuite
std::string input{
1, //tag_type::Byte
0, //tag_type::End
11, //tag_type::Int_Array
12, //tag_type::Long_Array

0x0a, 0x0b, 0x0c, 0x0d, //0x0a0b0c0d in Big Endian

Expand All @@ -54,7 +54,7 @@ class read_test : public CxxTest::TestSuite

TS_ASSERT_EQUALS(reader.read_type(), tag_type::Byte);
TS_ASSERT_EQUALS(reader.read_type(true), tag_type::End);
TS_ASSERT_EQUALS(reader.read_type(false), tag_type::Int_Array);
TS_ASSERT_EQUALS(reader.read_type(false), tag_type::Long_Array);

int32_t i;
reader.read_num(i);
Expand Down Expand Up @@ -107,7 +107,7 @@ class read_test : public CxxTest::TestSuite
//Tests if comp equals an extended variant of Notch's bigtest NBT
void verify_bigtest_structure(const tag_compound& comp)
{
TS_ASSERT_EQUALS(comp.size(), 13u);
TS_ASSERT_EQUALS(comp.size(), 14u);

TS_ASSERT(comp.at("byteTest") == tag_byte(127));
TS_ASSERT(comp.at("shortTest") == tag_short(32767));
Expand Down Expand Up @@ -138,6 +138,9 @@ class read_test : public CxxTest::TestSuite

TS_ASSERT(comp.at("intArrayTest") == tag_int_array(
{0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f}));

TS_ASSERT(comp.at("longArrayTest") == tag_long_array(
{0x0decafc0ffeebabe, static_cast<int64_t>(0xdeadbeefbaadf00d)}));
}

void test_read_bigtest()
Expand Down Expand Up @@ -216,6 +219,7 @@ class read_test : public CxxTest::TestSuite
"Even though unprovided for by NBT, the library should also handle "
"the case where the file consists of something else than tag_compound"));
}

void test_read_gzip()
{
#ifdef NBT_HAVE_ZLIB
Expand Down
Binary file modified test/testfiles/bigtest.nbt
Binary file not shown.
Binary file modified test/testfiles/bigtest.zlib
Binary file not shown.
Binary file modified test/testfiles/bigtest_uncompr
Binary file not shown.
Binary file modified test/testfiles/littletest_uncompr
Binary file not shown.
13 changes: 11 additions & 2 deletions test/write_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class read_test : public CxxTest::TestSuite

writer.write_type(tag_type::End);
writer.write_type(tag_type::Long);
writer.write_type(tag_type::Int_Array);
writer.write_type(tag_type::Long_Array);

writer.write_num(int64_t(0x0102030405060708));

Expand All @@ -54,7 +54,7 @@ class read_test : public CxxTest::TestSuite
std::string expected{
0, //tag_type::End
4, //tag_type::Long
11, //tag_type::Int_Array
12, //tag_type::Long_Array

0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, //0x0102030405060708 in Big Endian

Expand Down Expand Up @@ -147,6 +147,15 @@ class read_test : public CxxTest::TestSuite
}));
os.str("");

//tag_long_array
writer.write_payload(tag_long_array{0x0102030405060708, 0x090a0b0c0d0e0f10});
TS_ASSERT_EQUALS(os.str(), (std::string{
0x00, 0x00, 0x00, 0x02, //length in Big Endian
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10
}));
os.str("");

//tag_list
writer.write_payload(tag_list()); //empty list with undetermined type, should be written as list of tag_end
writer.write_payload(tag_list(tag_type::Int)); //empty list of tag_int
Expand Down

0 comments on commit c7cb857

Please sign in to comment.