⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tests-stringbuffer.c

📁 this is sample about DHCP-agent
💻 C
📖 第 1 页 / 共 2 页
字号:
    for(i = 0;i < 10;i ++) /* do 10 X. */        stringbuffer_aprintf(sb, "%s : ", BAR_STRING);    if(test_util_string_is_set(sb, BAR_STRING_X10_PRINTF, name))        return 1;    stringbuffer_clear(sb);    /* check to see if it matches the empty string. */    if(test_util_string_is_set(sb, "", name))        return 1;    /* * * * * * * * * * * * * * * *     * Append FOO_STRING and test. *     * * * * * * * * * * * * * * * */    /* append bar string. */    stringbuffer_append(sb, FOO_STRING);    /* check. */    if(test_util_string_is_set(sb, FOO_STRING, name))        return 1;    stringbuffer_clear(sb);    /* check to see if it matches the empty string. */    if(test_util_string_is_set(sb, "", name))        return 1;    stringbuffer_clear(sb);    for(i = 0;i < 5;i ++) /* do 5 X. */        stringbuffer_aprintf(sb, "%s : ", FOO_STRING);    if(test_util_string_is_set(sb, FOO_STRING_X5_PRINTF, name))        return 1;    stringbuffer_clear(sb);    /* check to see if it matches the empty string. */    if(test_util_string_is_set(sb, "", name))        return 1;    for(i = 0;i < 10;i ++) /* do 10 X. */        stringbuffer_aprintf(sb, "%s : ", FOO_STRING);    if(test_util_string_is_set(sb, FOO_STRING_X10_PRINTF, name))        return 1;    stringbuffer_clear(sb);    /* check to see if it matches the empty string. */    if(test_util_string_is_set(sb, "", name))        return 1;    /* done. */    stringbuffer_destroy(sb);    return 0;}static int test_replace_c(const char *name){    stringbuffer_t *sb;    sb = stringbuffer_create();    /* * * * * * * * * * * * * * * * *     * using replace_c only change   *     * foo to brr                    *     * * * * * * * * * * * * * * * * */    stringbuffer_append(sb, REPLACE_FOO);    stringbuffer_replace_c(sb, 'f', 'b');    stringbuffer_replace_c(sb, 'o', 'r');    if(test_util_string_is_set(sb, "brr", name))        return 1;    stringbuffer_destroy(sb);    return 0;}static int test_replace(const char *name){    stringbuffer_t *sb;    sb = stringbuffer_create();    /* * * * * * * * * * * * * * * * *     * replace two simple sequences. *     * * * * * * * * * * * * * * * * */    stringbuffer_append(sb, REPLACE_FOO_1);    stringbuffer_replace(sb, "bar", "foo");    if(test_util_string_is_set(sb, REPLACE_FOO_2, name))        return 1;    stringbuffer_clear(sb);    stringbuffer_append(sb, REPLACE_BAR_1);    stringbuffer_replace(sb, "foo", "bar");    if(test_util_string_is_set(sb, REPLACE_BAR_2, name))        return 1;    stringbuffer_clear(sb);    /* * * * * * * * * * * * * * * * * * * *     * replace one string with one string  *     * * * * * * * * * * * * * * * * * * * */    stringbuffer_append(sb, REPLACE_FOO);    stringbuffer_replace(sb, REPLACE_FOO, REPLACE_BAR);    if(test_util_string_is_set(sb, REPLACE_BAR, name))        return 1;    stringbuffer_clear(sb);    /* * * * * * * * * * * * * * * * * * *     * replace one string with itself.   *     * * * * * * * * * * * * * * * * * * */    stringbuffer_append(sb, REPLACE_FOO);    stringbuffer_replace(sb, REPLACE_FOO, REPLACE_FOO);    if(test_util_string_is_set(sb, REPLACE_FOO, name))        return 1;    stringbuffer_clear(sb);    /* * * * * * * * * * * * * * * * * * * * *     * replace two charactes in "foo" to be  *     * "brr" with replace                    *     * * * * * * * * * * * * * * * * * * * * */    stringbuffer_append(sb, REPLACE_FOO);    stringbuffer_replace(sb, "f", "b");    stringbuffer_replace(sb, "o", "r");    if(test_util_string_is_set(sb, "brr", name))        return 1;    stringbuffer_clear(sb);    /* done. */    stringbuffer_destroy(sb);    return 0;}static int test_trim_whitespace(const char *name){    stringbuffer_t *sb;    sb = stringbuffer_create();    /* test with leading and trailing white space. */    stringbuffer_aprintf(sb, "  \t%s\t  ", BAR_STRING);    stringbuffer_trim_whitespace(sb);    if(test_util_string_is_set(sb, BAR_STRING, name))        return 1;    stringbuffer_clear(sb);    /* test with just leading whitespace. */    stringbuffer_aprintf(sb, "  \t%s", BAR_STRING);    stringbuffer_trim_whitespace(sb);    if(test_util_string_is_set(sb, BAR_STRING, name))        return 1;    stringbuffer_clear(sb);    /* test with just trailing whitespace. */    stringbuffer_aprintf(sb, "%s\t  ", BAR_STRING);    stringbuffer_trim_whitespace(sb);    if(test_util_string_is_set(sb, BAR_STRING, name))        return 1;    stringbuffer_clear(sb);    /* test with only whitespace. */    stringbuffer_aprintf(sb, "     \t    ");    stringbuffer_trim_whitespace(sb);    if(test_util_string_is_set(sb, "", name))        return 1;    stringbuffer_clear(sb);    /* test with nothing :-). */    stringbuffer_aprintf(sb, "");    stringbuffer_trim_whitespace(sb);    if(test_util_string_is_set(sb, "", name))        return 1;    stringbuffer_clear(sb);    stringbuffer_destroy(sb);    return 0;}/* array of test routines. */static test_table tests[] = {    { "create/destroy",  test_create_destroy  },    { "append/clear",    test_append_clear    },    { "aprintf/clear",   test_aprintf_clear   },    { "replace_c",       test_replace_c   },    { "replace",         test_replace   },    { "trim_whitespace", test_trim_whitespace },};/* main: loops. */int main(int argc, char *argv[]){    DO_TESTS(tests);    exit(TESTS_EXIT_SUCCESS);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -