summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYongDo-Hyun <froster12@naver.com>2025-12-27 13:05:30 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-03-27 19:57:09 +0300
commitb6d496b1e83853cd272a8ffdea273c59bbf4b87c (patch)
tree249509918badba23d7d45af345ef7c2a06212b44 /test
parent37a3f01be6fb37d6cb04ae12216b5d74cef2aca9 (diff)
downloadProject-Tick-b6d496b1e83853cd272a8ffdea273c59bbf4b87c.tar.gz
Project-Tick-b6d496b1e83853cd272a8ffdea273c59bbf4b87c.zip
feat: add numeric tag creation methods and corresponding tests for value assignments
Signed-off-by: YongDo-Hyun <froster12@naver.com>
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt3
-rw-r--r--test/test_value.cpp38
-rw-r--r--test/test_value.h36
3 files changed, 37 insertions, 40 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 500b939d51..fab1f58c00 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -112,8 +112,7 @@ stop_warnings(format_test)
# Optional local test executable to verify value assignments (developer helper)
option(NBT_BUILD_LOCAL_TEST "Build a small local test executable for value assignments" ON)
if(NBT_BUILD_LOCAL_TEST)
- add_executable(test_value test_value.cpp)
+ CXXTEST_ADD_TEST(test_value test_value.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_value.h)
target_link_libraries(test_value ${NBT_NAME})
- add_test(test_value test_value)
stop_warnings(test_value)
endif()
diff --git a/test/test_value.cpp b/test/test_value.cpp
deleted file mode 100644
index 6b4729ea59..0000000000
--- a/test/test_value.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <iostream>
-#include "nbt_tags.h"
-#include "value.h"
-
-using namespace nbt;
-
-int main()
-{
- try {
- value v;
-
- v = int8_t(-5);
- std::cout << "assigned int8_t(-5): as int32=" << int32_t(v) << ", as double=" << double(v) << "\n";
-
- v = value();
- v = int16_t(12345);
- std::cout << "assigned int16_t(12345): as int32=" << int32_t(v) << ", as double=" << double(v) << "\n";
-
- v = value();
- v = int32_t(100000);
- std::cout << "assigned int32_t(100000): as int64=" << int64_t(v) << ", as double=" << double(v) << "\n";
-
- v = value();
- v = float(3.14f);
- std::cout << "assigned float(3.14): as double=" << double(v) << "\n";
-
- v = value();
- v = double(2.718281828);
- std::cout << "assigned double(2.71828): as double=" << double(v) << "\n";
-
- std::cout << "Test finished OK\n";
- }
- catch(const std::exception& e) {
- std::cerr << "Exception: " << e.what() << "\n";
- return 1;
- }
- return 0;
-}
diff --git a/test/test_value.h b/test/test_value.h
new file mode 100644
index 0000000000..db93ffdf7a
--- /dev/null
+++ b/test/test_value.h
@@ -0,0 +1,36 @@
+#include <cxxtest/TestSuite.h>
+#include <cstdint>
+#include "value.h"
+
+using namespace nbt;
+
+class value_assignment_test : public CxxTest::TestSuite
+{
+public:
+ void test_numeric_assignments()
+ {
+ value v;
+
+ v = int8_t(-5);
+ TS_ASSERT_EQUALS(int32_t(v), int32_t(-5));
+ TS_ASSERT_EQUALS(double(v), static_cast<double>(int8_t(-5)));
+
+ v = value();
+ v = int16_t(12345);
+ TS_ASSERT_EQUALS(int32_t(v), int32_t(12345));
+ TS_ASSERT_EQUALS(double(v), static_cast<double>(int16_t(12345)));
+
+ v = value();
+ v = int32_t(100000);
+ TS_ASSERT_EQUALS(int64_t(v), int64_t(100000));
+ TS_ASSERT_EQUALS(double(v), static_cast<double>(int32_t(100000)));
+
+ v = value();
+ v = float(3.14f);
+ TS_ASSERT_EQUALS(double(v), static_cast<double>(3.14f));
+
+ v = value();
+ v = double(2.718281828);
+ TS_ASSERT_EQUALS(double(v), 2.718281828);
+ }
+};