From: Michal Privoznik <[email protected]> The signature and implementation of virSkipSpacesBackwards() is soon about to change. Introduce a test case to make sure its behaviour stays the same.
Signed-off-by: Michal Privoznik <[email protected]> --- tests/virstringtest.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index f4976890db..a9c8e621ce 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -111,6 +111,51 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED) } +#define TEST_STR "This is a static string with spaces" +#define TEST_SPACES " " + +static int +testSkipSpacesBackwards(const void *opaque G_GNUC_UNUSED) +{ + const char *str = TEST_STR TEST_SPACES; + char *eol = NULL; + + virSkipSpacesBackwards(str, &eol); + + if (STRNEQ(str, TEST_STR TEST_SPACES)) { + fprintf(stderr, "expected '" TEST_STR TEST_SPACES "' got '%s'\n", str); + return -1; + } + + while (g_ascii_isspace(*eol)) + eol++; + + if (*eol != '\0') { + fprintf(stderr, "expected empty string, got '%s'\n", eol); + return -1; + } + + eol = (char *)str + strlen(TEST_STR); + + virSkipSpacesBackwards(str, &eol); + + if (STRNEQ(str, TEST_STR TEST_SPACES)) { + fprintf(stderr, "expected '" TEST_STR TEST_SPACES "' got '%s'\n", str); + return -1; + } + + if (STRNEQ(eol, TEST_SPACES)) { + fprintf(stderr, "expected empty string, got '%s'\n", eol); + return -1; + } + + return 0; +} + +#undef TEST_SPACES +#undef TEST_STR + + struct stringSearchData { const char *str; const char *regexp; @@ -463,6 +508,9 @@ mymain(void) if (virTestRun("virStringSortCompare", testStringSortCompare, NULL) < 0) ret = -1; + if (virTestRun("virSkipSpacesBackwards", testSkipSpacesBackwards, NULL) < 0) + ret = -1; + #define TEST_SEARCH(s, r, x, n, m, e) \ do { \ struct stringSearchData data = { \ -- 2.51.2
