diff --git a/cpp_impl/CMakeLists.txt b/cpp_impl/CMakeLists.txt index 377f556..034205a 100644 --- a/cpp_impl/CMakeLists.txt +++ b/cpp_impl/CMakeLists.txt @@ -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) diff --git a/cpp_impl/src/test/TestUDPC.cpp b/cpp_impl/src/test/TestUDPC.cpp new file mode 100644 index 0000000..5f17733 --- /dev/null +++ b/cpp_impl/src/test/TestUDPC.cpp @@ -0,0 +1,25 @@ +#include + +#include +#include + +#include + +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); +}