diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 28 | ||||
| -rw-r--r-- | tests/test_dns.c | 8 | ||||
| -rw-r--r-- | tests/test_dns.h | 6 | ||||
| -rw-r--r-- | tests/tests.c | 26 |
4 files changed, 68 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..7f52921 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +project(dnsl-tests LANGUAGES C VERSION ${CMAKE_PROJECT_VERSION}) + +set(dnsl-tests_headers + test_dns.h +) + +set(dnsl-tests_c_sources + tests.c + test_dns.c +) + +add_executable(${PROJECT_NAME}) +add_executable(${PROJECT_NAMESPACE}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +target_sources(${PROJECT_NAME} + PRIVATE + ${dnsl-tests_c_sources} + ${dnsl-tests_headers} +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED ON + C_EXTENSIONS OFF + COMPILE_WARNING_AS_ERROR ON + + VERSION ${PROJECT_VERSION} +) +target_link_libraries(${PROJECT_NAME} PRIVATE dnslite::dnslite unity) diff --git a/tests/test_dns.c b/tests/test_dns.c new file mode 100644 index 0000000..1b15e1c --- /dev/null +++ b/tests/test_dns.c @@ -0,0 +1,8 @@ +#include "dnslite.h" +#include "unity.h" + +void test_dnsl_encode_hostname (void) +{ + struct dnsl_error error; + TEST_ASSERT_EQUAL_STRING_LEN("\x03\x64\x6e\x73\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00", dnsl_encode_hostname("dns.google.com", &error), 16); +} diff --git a/tests/test_dns.h b/tests/test_dns.h new file mode 100644 index 0000000..d481edf --- /dev/null +++ b/tests/test_dns.h @@ -0,0 +1,6 @@ +#ifndef DNSL_TESTS_DNS_H +#define DNSL_TESTS_DNS_H + +void test_dnsl_encode_hostname (void); + +#endif diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..9ec1a84 --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,26 @@ +#include "dnslite.h" +#include "unity.h" + +#include "test_dns.h" + +void setUp (void) +{ + struct dnsl_error error; + + if(dnsl_socket_init(&error) != 0) + { + printf("Could not initialize sockets: [%d] %s\n", error.code, error.msg); + } +} + +void tearDown (void) +{ + dnsl_socket_fini(); +} + +int main (void) +{ + UNITY_BEGIN(); + RUN_TEST(test_dnsl_encode_hostname); + return UNITY_END(); +} |
