Add some Unit Tests for UDPC

This commit is contained in:
Stephen Seo 2019-08-27 18:03:30 +09:00
parent 8883d84b9b
commit 35bc629b1b
2 changed files with 26 additions and 0 deletions

View file

@ -40,6 +40,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(UDPC_UnitTest_SOURCES
src/test/UDPC_UnitTest.cpp
src/test/TestTSQueue.cpp
src/test/TestUDPC.cpp
)
add_executable(UnitTest ${UDPC_UnitTest_SOURCES})
target_compile_features(UnitTest PUBLIC cxx_std_17)

View file

@ -0,0 +1,25 @@
#include <gtest/gtest.h>
#include <UDPConnection.h>
#include <UDPC_Defines.hpp>
#include <cstring>
TEST(UDPC, atostr) {
UDPC::Context context(false);
UDPC_atostr(&context, 0x0100007F);
EXPECT_EQ(std::strcmp(context.atostrBuf, "127.0.0.1"), 0);
UDPC_atostr(&context, 0xFF08000A);
EXPECT_EQ(std::strcmp(context.atostrBuf, "10.0.8.255"), 0);
UDPC_atostr(&context, 0x0201A8C0);
EXPECT_EQ(std::strcmp(context.atostrBuf, "192.168.1.2"), 0);
}
TEST(UDPC, strtoa) {
EXPECT_EQ(UDPC_strtoa("127.0.0.1"), 0x0100007F);
EXPECT_EQ(UDPC_strtoa("10.0.8.255"), 0xFF08000A);
EXPECT_EQ(UDPC_strtoa("192.168.1.2"), 0x0201A8C0);
}