Add test_internal__ascii_parse()
This commit is contained in:
parent
6951b4bd40
commit
4bc3af5a1c
@ -156,3 +156,18 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|||||||
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=.debug
|
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=.debug
|
||||||
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=.release
|
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=.release
|
||||||
# make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE
|
# make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE
|
||||||
|
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
set(CMAKE_CTEST_COMMAND ctest -V)
|
||||||
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
||||||
|
|
||||||
|
add_executable(test_internal EXCLUDE_FROM_ALL tests/test_internal.c
|
||||||
|
tests/stream_buffer.c
|
||||||
|
src/stream.c
|
||||||
|
src/internal/ascii_parse.c)
|
||||||
|
add_test(test_internal test_internal)
|
||||||
|
add_dependencies(check test_internal)
|
||||||
|
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
#include "utest_lib.h"
|
#include "utest_lib.h"
|
||||||
|
|
||||||
|
#include "../src/internal/ascii_parse.h"
|
||||||
#include "../src/internal/byte_swap.h"
|
#include "../src/internal/byte_swap.h"
|
||||||
#include "../src/internal/byte_codec.h"
|
#include "../src/internal/byte_codec.h"
|
||||||
|
|
||||||
|
#include "stream_buffer.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
const char* test_internal__byte_swap()
|
const char* test_internal__byte_swap()
|
||||||
{
|
{
|
||||||
UTEST_ASSERT(foug_uint16_bswap(0x1122) == 0x2211);
|
UTEST_ASSERT(foug_uint16_bswap(0x1122) == 0x2211);
|
||||||
@ -35,6 +41,69 @@ const char* test_internal__byte_codec()
|
|||||||
|
|
||||||
const char* test_internal__ascii_parse()
|
const char* test_internal__ascii_parse()
|
||||||
{
|
{
|
||||||
|
char text[] =
|
||||||
|
"Une citation,\to je crois qu'elle est de moi :"
|
||||||
|
"Parfois le chemin est rude.\n"
|
||||||
|
"pi : 3.1415926535897932384626433832795";
|
||||||
|
|
||||||
|
{
|
||||||
|
foug_buffer_t buff;
|
||||||
|
foug_stream_t stream;
|
||||||
|
|
||||||
|
char small_fwd_it_str[4];
|
||||||
|
char fwd_it_str[32];
|
||||||
|
foug_ascii_stream_fwd_iterator_t fwd_it;
|
||||||
|
|
||||||
|
char copy_str[128];
|
||||||
|
foug_ascii_string_buffer_t copy_strbuff;
|
||||||
|
|
||||||
|
buff.ptr = text;
|
||||||
|
buff.len = strlen(text);
|
||||||
|
buff.pos = 0;
|
||||||
|
foug_stream_set_buffer(&stream, &buff);
|
||||||
|
|
||||||
|
memset(&fwd_it, 0, sizeof(foug_ascii_stream_fwd_iterator_t));
|
||||||
|
fwd_it.stream = &stream;
|
||||||
|
fwd_it.buffer.ptr = fwd_it_str;
|
||||||
|
fwd_it.buffer.max_len = sizeof(fwd_it_str);
|
||||||
|
foug_ascii_stream_fwd_iterator_init(&fwd_it);
|
||||||
|
|
||||||
|
copy_strbuff.ptr = copy_str;
|
||||||
|
copy_strbuff.max_len = sizeof(copy_str);
|
||||||
|
|
||||||
|
UTEST_ASSERT(foug_current_char(&fwd_it) != NULL);
|
||||||
|
UTEST_ASSERT(*foug_current_char(&fwd_it) == 'U');
|
||||||
|
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
/* printf("\ncopy_strbuff.ptr = \"%s\"\n", copy_strbuff.ptr); */
|
||||||
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Une") == 0);
|
||||||
|
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
||||||
|
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "o") == 0);
|
||||||
|
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "je") == 0);
|
||||||
|
|
||||||
|
foug_skip_spaces(&fwd_it);
|
||||||
|
UTEST_ASSERT(foug_next_char(&fwd_it) != NULL);
|
||||||
|
UTEST_ASSERT(*foug_current_char(&fwd_it) == 'r');
|
||||||
|
|
||||||
|
/* Test with very small string buffer */
|
||||||
|
buff.pos = 0;
|
||||||
|
fwd_it.buffer.ptr = small_fwd_it_str;
|
||||||
|
fwd_it.buffer.max_len = sizeof(small_fwd_it_str);
|
||||||
|
foug_ascii_stream_fwd_iterator_init(&fwd_it);
|
||||||
|
|
||||||
|
UTEST_ASSERT(*foug_current_char(&fwd_it) == 'U');
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
UTEST_ASSERT(foug_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* all_tests()
|
const char* all_tests()
|
||||||
@ -42,6 +111,7 @@ const char* all_tests()
|
|||||||
UTEST_SUITE_START();
|
UTEST_SUITE_START();
|
||||||
UTEST_RUN(test_internal__byte_swap);
|
UTEST_RUN(test_internal__byte_swap);
|
||||||
UTEST_RUN(test_internal__byte_codec);
|
UTEST_RUN(test_internal__byte_codec);
|
||||||
|
UTEST_RUN(test_internal__ascii_parse);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,18 +23,20 @@
|
|||||||
tests_run++;\
|
tests_run++;\
|
||||||
if (message) return message;
|
if (message) return message;
|
||||||
|
|
||||||
#define UTEST_MAIN(name) int main(int argc, char *argv[]) {\
|
#define UTEST_MAIN(name) \
|
||||||
argc = 1;\
|
int main(int argc, char *argv[]) {\
|
||||||
|
const char *result = NULL; \
|
||||||
|
\
|
||||||
printf("----\nRUNNING: %s\n", argv[0]);\
|
printf("----\nRUNNING: %s\n", argv[0]);\
|
||||||
const char *result = name();\
|
result = name();\
|
||||||
if (result != 0) {\
|
if (result != NULL) {\
|
||||||
printf("\n\nFAILED: %s\n", result);\
|
printf("\n\nFAILED: %s\n", result);\
|
||||||
}\
|
}\
|
||||||
else {\
|
else {\
|
||||||
printf("\n\nALL TESTS PASSED\n");\
|
printf("\n\nALL TESTS PASSED\n");\
|
||||||
}\
|
}\
|
||||||
printf("Tests run: %d\n", tests_run);\
|
printf("Tests run: %d\n", tests_run);\
|
||||||
exit(result != 0);\
|
exit(result != NULL);\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user