diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | CMakeLists.txt | 12 | ||||
| -rw-r--r-- | include/tag.h | 37 | ||||
| -rw-r--r-- | test/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | test/microtest.h | 14 | ||||
| -rw-r--r-- | test/nbttest.cpp | 9 |
6 files changed, 79 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 6c2e80ec8d..a7f172c739 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ /lib /obj /build -/doxygen/html +/doxygen diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..9f105284ea --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 2.6) +project(libnbt++) +set(libnbt++_VERSION_MAJOR 2) +set(libnbt++_VERSION_MINOR 0) + +add_definitions(-std=c++11) +include_directories(include) +add_library(nbt++ STATIC + ) + +enable_testing() +add_subdirectory(test) diff --git a/include/tag.h b/include/tag.h new file mode 100644 index 0000000000..a17406ff2b --- /dev/null +++ b/include/tag.h @@ -0,0 +1,37 @@ +#ifndef TAG_H_INCLUDED +#define TAG_H_INCLUDED + +#include <cstdint> + +namespace nbt +{ + +/** Tag type values used in the binary format */ +enum class tag_type : int8_t +{ + End = 0, + Byte = 1, + Short = 2, + Int = 3, + Long = 4, + Float = 5, + Double = 6, + Byte_Array = 7, + String = 8, + List = 9, + Compound = 10, + Int_Array = 11 +}; + +/** Base class for all tag classes */ +class tag +{ +public: + virtual ~tag() noexcept {} + + virtual tag_type get_type() const noexcept = 0; +}; + +} + +#endif // TAG_H_INCLUDED diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000..04672d2666 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,6 @@ +enable_testing() +include_directories(${libnbt++_SOURCE_DIR}/include) + +add_executable(nbttest nbttest.cpp) +target_link_libraries(nbttest nbt++) +add_test(nbttest nbttest) diff --git a/test/microtest.h b/test/microtest.h new file mode 100644 index 0000000000..8691ebb748 --- /dev/null +++ b/test/microtest.h @@ -0,0 +1,14 @@ +#ifndef MICROTEST_H +#define MICROTEST_H + +#include <type_traits> + +#define FAIL_TEST { std::cerr << "Assertion failed at " __FILE__ ":" << __LINE__ << std::endl; \ + exit(EXIT_FAILURE); } +#define ASSERT(expr) { if(!(expr)) FAIL_TEST } +#define EXPECT_EXCEPTION(expr, type) { \ + try { (expr); std::cerr << "Expected " #type " to be thrown" << std::endl; FAIL_TEST } \ + catch(type&) {} \ + catch(...) { std::cerr << "Expected " #type " to be thrown" << std::endl; FAIL_TEST } } + +#endif diff --git a/test/nbttest.cpp b/test/nbttest.cpp new file mode 100644 index 0000000000..eead43efd0 --- /dev/null +++ b/test/nbttest.cpp @@ -0,0 +1,9 @@ +#include "microtest.h" +#include "tag.h" +#include <cstdlib> +#include <iostream> + +int main() +{ + return EXIT_SUCCESS; +} |
