mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Basic tests infrastructure
This commit is contained in:
21
tests/CMakeLists.txt
Normal file
21
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
# create the testing file and list of tests
|
||||
create_test_sourcelist (Tests
|
||||
CommonCxxTests.cpp
|
||||
TestNiPoint3.cpp
|
||||
TestLDFFormat.cpp
|
||||
)
|
||||
|
||||
# add the executable
|
||||
add_executable (CommonCxxTests ${Tests})
|
||||
target_link_libraries(CommonCxxTests dCommon raknet)
|
||||
|
||||
# remove the test driver source file
|
||||
set (TestsToRun ${Tests})
|
||||
remove (TestsToRun CommonCxxTests.cpp)
|
||||
|
||||
# Add all the ADD_TEST for each test
|
||||
foreach (test ${TestsToRun})
|
||||
get_filename_component (TName ${test} NAME_WE)
|
||||
add_test (NAME ${TName} COMMAND CommonCxxTests ${TName})
|
||||
set_property(TEST ${TName} PROPERTY ENVIRONMENT CTEST_OUTPUT_ON_FAILURE=1)
|
||||
endforeach ()
|
0
tests/CommonCxxTests.cpp
Normal file
0
tests/CommonCxxTests.cpp
Normal file
4
tests/CommonCxxTests.h
Normal file
4
tests/CommonCxxTests.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <cstdio>
|
||||
|
||||
#define ASSERT_EQ(a,b) { if (!(a == b)) { printf("Failed assertion: " #a " == " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }}
|
||||
#define ASSERT_NE(a,b) { if (!(a != b)) { printf("Failed assertion: " #a " != " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }}
|
31
tests/TestLDFFormat.cpp
Normal file
31
tests/TestLDFFormat.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "LDFFormat.h"
|
||||
#include "CommonCxxTests.h"
|
||||
|
||||
/**
|
||||
* @brief Test parsing an LDF value
|
||||
*
|
||||
* @param argc Number of command line arguments for this test
|
||||
* @param argv Command line arguments
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int TestLDFFormat(int argc, char** argv) {
|
||||
// Create
|
||||
auto* data = LDFBaseData::DataFromString("KEY=0:VALUE");
|
||||
|
||||
// Check that the data type is correct
|
||||
ASSERT_EQ(data->GetValueType(), eLDFType::LDF_TYPE_UTF_16);
|
||||
|
||||
// Check that the key is correct
|
||||
ASSERT_EQ(data->GetKey(), u"KEY");
|
||||
|
||||
// Check that the value is correct
|
||||
ASSERT_EQ(((LDFData<std::u16string>* )data)->GetValue(), u"VALUE");
|
||||
|
||||
// Check that the serialization is correct
|
||||
ASSERT_EQ(data->GetString(), "KEY=0:VALUE");
|
||||
|
||||
// Cleanup the object
|
||||
delete data;
|
||||
|
||||
return 0;
|
||||
}
|
13
tests/TestNiPoint3.cpp
Normal file
13
tests/TestNiPoint3.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include "NiPoint3.h"
|
||||
#include "CommonCxxTests.h"
|
||||
|
||||
int TestNiPoint3(int argc, char** argv) {
|
||||
// Check that Unitize works
|
||||
ASSERT_EQ(NiPoint3(3,0,0).Unitize(), NiPoint3::UNIT_X);
|
||||
// Check what unitize does to a vector of length 0
|
||||
ASSERT_EQ(NiPoint3::ZERO.Unitize(), NiPoint3::ZERO);
|
||||
// If we get here, all was successful
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user