From c7cb857c2fe0a066011cf7d2a8f82eb025d86fec Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Mon, 21 May 2018 20:57:47 +0200 Subject: [PATCH] Expand tests for tag_long_array Format long arrays with "l" suffixes Version bump --- CMakeLists.txt | 2 +- src/text/json_formatter.cpp | 2 +- test/read_test.h | 10 +++++++--- test/testfiles/bigtest.nbt | Bin 561 -> 581 bytes test/testfiles/bigtest.zlib | Bin 528 -> 561 bytes test/testfiles/bigtest_uncompr | Bin 1601 -> 1637 bytes test/testfiles/littletest_uncompr | Bin 1601 -> 1637 bytes test/write_test.h | 13 +++++++++++-- 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b9a1e4..02077b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/text/json_formatter.cpp b/src/text/json_formatter.cpp index beb6c46..4bcb12d 100644 --- a/src/text/json_formatter.cpp +++ b/src/text/json_formatter.cpp @@ -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 << ", "; } diff --git a/test/read_test.h b/test/read_test.h index 4f71495..60516c9 100644 --- a/test/read_test.h +++ b/test/read_test.h @@ -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 @@ -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); @@ -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)); @@ -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(0xdeadbeefbaadf00d)})); } void test_read_bigtest() @@ -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 diff --git a/test/testfiles/bigtest.nbt b/test/testfiles/bigtest.nbt index de1a91268b9406085714e9c1634530e8bf30396c..7647bcc037f568e7876176c218b9fad8e48e468f 100644 GIT binary patch literal 581 zcmV-L0=oSliwFpk5CdBP17c}sbY*jN0PU3DZ_-c{#}B22QVJ}SEM!@h>zo9zl7ftp zWimF|WJ|*qXy&pkWMy0mTH2*8GkfwyAB}JR7mM#RSxopFeAQPUjQStorTmx=`s@oQ zP0s1L-`mf*x5<|SM#2|Zqk+{7U6rwAzv>Tz0-x0~Onca4fwOG0J(NJav@J>d=-GZn zDk8bGTSesAMDli3Mpe18TYidqZ+fqL@9#3;Yifq#d?nwHq}||c>-Lz#L0BgxZlE)x zb8d9?2C~UJ2kw^AVS(0_4hBz2>6~{h2AB&)>*9?901yRM)v?06t*Uiw+7k&3!UrL( zZ8`A?JB$ z=m4&0W%cu0_=h_6ceM|Kw^&Sw&NMDy>z6im?#&B$P;Z*1aygXQEsUCNlawh@6p?cW z7BZ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!JL5*)&Z|~6d?7I)+*(AX_jzp^0G@b#_vcsmhdT3jH4ot@ETKfV8V_)- zM~ArY763Ai4=qc5oXDIm!A{SjVMdZ9bl<>6vx5mEWu&q@JFkq?Zt^8v6w!86%c1{> zAA3$0jW-e|Xf~e}aXTksCNE+^#B@5Hq+s7~C~huu!m22*93yj4JHHO6FB9I=f|M;P z%X>mqTw94^{$l++6~4K=^2Q3SY)CoU+pjj)%F%j$YkebCx`|)qV*VC{HjlXd)uvoN zt}|P;jq6f6p2(g0r3GWbSTO!C!w*8+9JF+|!yNqj_Tk6qt{H?7?bY)>L)#Do9 DeufjR delta 9 QcmaFLbC73)0~;d)01}A;wg3PC diff --git a/test/write_test.h b/test/write_test.h index a302891..b9be132 100644 --- a/test/write_test.h +++ b/test/write_test.h @@ -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)); @@ -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 @@ -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