summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt4
-rw-r--r--test/write_test.cpp61
2 files changed, 65 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 89a445d402..539efc5c1f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -17,6 +17,10 @@ add_custom_command(TARGET read_test POST_BUILD
copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/testfiles ${CMAKE_CURRENT_BINARY_DIR})
add_test(read_test read_test)
+add_executable(write_test write_test.cpp)
+target_link_libraries(write_test nbt++)
+add_test(write_test write_test)
+
add_executable(format_test format_test.cpp)
target_link_libraries(format_test nbt++)
add_test(format_test format_test)
diff --git a/test/write_test.cpp b/test/write_test.cpp
new file mode 100644
index 0000000000..5c5cab055b
--- /dev/null
+++ b/test/write_test.cpp
@@ -0,0 +1,61 @@
+/*
+ * libnbt++ - A library for the Minecraft Named Binary Tag format.
+ * Copyright (C) 2013, 2015 ljfa-ag
+ *
+ * This file is part of libnbt++.
+ *
+ * libnbt++ is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libnbt++ is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "microtest.h"
+#include "io/stream_writer.h"
+#include <iostream>
+#include <sstream>
+
+using namespace nbt;
+
+void test_stream_writer_big()
+{
+ std::ostringstream os;
+ nbt::io::stream_writer writer(os);
+
+ ASSERT(&writer.get_ostr() == &os);
+ ASSERT(writer.get_endian() == endian::big);
+
+ writer.write_type(tag_type::End);
+ writer.write_type(tag_type::Long);
+ writer.write_type(tag_type::Int_Array);
+
+ writer.write_num(int64_t(0x0102030405060708));
+
+ writer.write_string("foobar");
+
+ ASSERT(os);
+ std::string expected{
+ 0, //tag_type::End
+ 4, //tag_type::Long
+ 11, //tag_type::Int_Array
+
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, //0x0102030405060708 in Big Endian
+
+ 0x00, 0x06, //string length in Big Endian
+ 'f', 'o', 'o', 'b', 'a', 'r'
+ };
+ ASSERT(os.str() == expected);
+ std::clog << "test_stream_writer_big passed" << std::endl;
+}
+
+int main()
+{
+ test_stream_writer_big();
+}