示例#1
0
void StringTestCase::Trim()
{
    #define TEST_TRIM( str , dir , result )  \
        CPPUNIT_ASSERT( wxString(str).Trim(dir) == result )

    TEST_TRIM( wxT("  Test  "),  true, wxT("  Test") );
    TEST_TRIM( wxT("    "),      true, wxT("")       );
    TEST_TRIM( wxT(" "),         true, wxT("")       );
    TEST_TRIM( wxT(""),          true, wxT("")       );

    TEST_TRIM( wxT("  Test  "),  false, wxT("Test  ") );
    TEST_TRIM( wxT("    "),      false, wxT("")       );
    TEST_TRIM( wxT(" "),         false, wxT("")       );
    TEST_TRIM( wxT(""),          false, wxT("")       );

    #undef TEST_TRIM
}
示例#2
0
static void
test_evutil_rtrim(void *ptr)
{
#define TEST_TRIM(s, result) \
	do {						\
	    if (cp) mm_free(cp);			\
	    cp = mm_strdup(s);				\
	    tt_assert(cp);				\
	    evutil_rtrim_lws_(cp);			\
	    tt_str_op(cp, ==, result);			\
	} while(0)

	char *cp = NULL;
	(void) ptr;

	TEST_TRIM("", "");
	TEST_TRIM("a", "a");
	TEST_TRIM("abcdef ghi", "abcdef ghi");

	TEST_TRIM(" ", "");
	TEST_TRIM("  ", "");
	TEST_TRIM("a ", "a");
	TEST_TRIM("abcdef  gH       ", "abcdef  gH");

	TEST_TRIM("\t\t", "");
	TEST_TRIM(" \t", "");
	TEST_TRIM("\t", "");
	TEST_TRIM("a \t", "a");
	TEST_TRIM("a\t ", "a");
	TEST_TRIM("a\t", "a");
	TEST_TRIM("abcdef  gH    \t  ", "abcdef  gH");

end:
	if (cp)
		mm_free(cp);
}