From 2f0bf929fcecc47c5a5d2b3f151d8f187fb5d7f9 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 12 Aug 2015 13:54:17 +0200 Subject: Use string constructor from initializer_list No need for null terminators --- test/endian_str_test.cpp | 18 +++++++++--------- test/read_test.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/endian_str_test.cpp b/test/endian_str_test.cpp index d519dee049..c8db4ea674 100644 --- a/test/endian_str_test.cpp +++ b/test/endian_str_test.cpp @@ -39,7 +39,7 @@ void test_uint() write_big (str, uint32_t(0x090A0B0C)); write (str, uint64_t(0x090A0B0C0D0E0F10), endian::big); - const char expected[] { + std::string expected{ 1, 2, 1, 4, 3, 2, 1, @@ -48,8 +48,8 @@ void test_uint() 9, 9, 10, 9, 10, 11, 12, - 9, 10, 11, 12, 13, 14, 15, 16, - 0}; //Null terminator + 9, 10, 11, 12, 13, 14, 15, 16 + }; ASSERT(str.str() == expected); uint8_t u8; @@ -93,7 +93,7 @@ void test_sint() write (str, int32_t(-0x090A0B0C), endian::big); write_big (str, int64_t(-0x090A0B0C0D0E0F10)); - const char expected[] { //meh, stupid narrowing conversions + std::string expected{ //meh, stupid narrowing conversions '\xFF', '\xFE', '\xFE', '\xFC', '\xFC', '\xFD', '\xFE', @@ -102,8 +102,8 @@ void test_sint() '\xF7', '\xF6', '\xF6', '\xF6', '\xF5', '\xF4', '\xF4', - '\xF6', '\xF5', '\xF4', '\xF3', '\xF2', '\xF1', '\xF0', '\xF0', - 0}; //Null terminator + '\xF6', '\xF5', '\xF4', '\xF3', '\xF2', '\xF1', '\xF0', '\xF0' + }; ASSERT(str.str() == expected); int8_t i8; @@ -147,13 +147,13 @@ void test_float() write_big (str, fconst); write_big (str, dconst); - const char expected[] { + std::string expected{ '\x01', '\xEF', '\xCD', '\xAB', '\x05', '\x04', '\x03', '\x02', '\x01', '\xEF', '\xCD', '\xAB', '\xAB', '\xCD', '\xEF', '\x01', - '\xAB', '\xCD', '\xEF', '\x01', '\x02', '\x03', '\x04', '\x05', - 0}; //Null terminator + '\xAB', '\xCD', '\xEF', '\x01', '\x02', '\x03', '\x04', '\x05' + }; ASSERT(str.str() == expected); float f; diff --git a/test/read_test.cpp b/test/read_test.cpp index 0fa6259a15..b9d8c59f6c 100644 --- a/test/read_test.cpp +++ b/test/read_test.cpp @@ -28,7 +28,7 @@ using namespace nbt; void test_stream_reader_big() { - const char input[] { + std::string input{ 1, //tag_type::Byte 0, //tag_type::End 11, //tag_type::Int_Array @@ -40,7 +40,7 @@ void test_stream_reader_big() 0 //tag_type::End (invalid with allow_end = false) }; - std::istringstream is(std::string(input, sizeof input)); + std::istringstream is(input); nbt::io::stream_reader reader(is); ASSERT(&reader.get_istr() == &is); @@ -75,7 +75,7 @@ void test_stream_reader_big() void test_stream_reader_little() { - const char input[] { + std::string input{ 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, //0x0d0c0b0a09080706 in Little Endian 0x06, 0x00, //String length in Little Endian @@ -84,7 +84,7 @@ void test_stream_reader_little() 0x10, 0x00, //String length (intentionally too large) 'a', 'b', 'c', 'd' //unexpected EOF }; - std::istringstream is(std::string(input, sizeof input)); + std::istringstream is(input); nbt::io::stream_reader reader(is, endian::little); ASSERT(reader.get_endian() == endian::little); -- cgit 0.0.5-2-1-g0f52