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

📄 tests-stringbuffer.c

📁 this is sample about DHCP-agent
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/tests-stringbuffer.c,v 1.2 2002/12/30 06:29:20 actmodern Exp $ *  * Copyright 2002 Thamer Alharbash <tmh@whitefang.com> *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *  * stringbuffer test code. we need more tests too :) * */#include "dhcp-local.h"#include "dhcp-libutil.h"#include "tests.h"#define TEST_NAME "stringbuffer"/* test strings. *//* two basic strings for appending. */#define BAR_STRING "This is my source code, there are many others like it, but this one is mine."#define FOO_STRING "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890"/* the same strings appended 5 times and appended 10 times */#define FOO_STRING_X10 "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890"#define FOO_STRING_X5 "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890"#define BAR_STRING_X5 "This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine."#define BAR_STRING_X10 "This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine."/* the same strings appended 5 and 10 times only with a " : " in between to test aprintf capability */#define BAR_STRING_X5_PRINTF "This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : "#define BAR_STRING_X10_PRINTF "This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : "#define FOO_STRING_X5_PRINTF "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : "#define FOO_STRING_X10_PRINTF "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : "/* two strings to replace. */#define REPLACE_FOO_1 "foo bar foo bar foo bar foo bar foo bar"#define REPLACE_FOO_2 "foo foo foo foo foo foo foo foo foo foo"#define REPLACE_BAR_1 "bar foo bar foo bar foo bar foo bar foo"#define REPLACE_BAR_2 "bar bar bar bar bar bar bar bar bar bar"#define REPLACE_FOO "foo"#define REPLACE_BAR "bar"/* utility routines. */static int test_util_string_is_set(stringbuffer_t *sb, const char *string, const char *name){    const char *ptr;    int len;    /* see if it returns properly. */    ptr = stringbuffer_getstring(sb);    if(strcmp(ptr, string)) {        TEST_ERROR(name, "string did not match properly : string comparison wrong");        return 1;    }    len = stringbuffer_getlen(sb);    if(len != strlen(ptr)) {        TEST_ERROR(name, "string did not match properly : string length wrong");        return 1;    }    return 0;}/* test routines. */static int test_create_destroy(const char *name){    stringbuffer_t *sb;    /* just create and destroy. we cannot catch an error here     * but we may crash if something is up. */    sb = stringbuffer_create();    stringbuffer_destroy(sb);    return 0;}static int test_append_clear(const char *name){    stringbuffer_t *sb;    int i;    sb = stringbuffer_create();    /* * * * * * * * * * * * * * * *     * Append BAR_STRING and test. *     * * * * * * * * * * * * * * * */    /* append bar string. */    stringbuffer_append(sb, BAR_STRING);    /* check. */    if(test_util_string_is_set(sb, BAR_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_append(sb, BAR_STRING);    if(test_util_string_is_set(sb, BAR_STRING_X5, 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_append(sb, BAR_STRING);    if(test_util_string_is_set(sb, BAR_STRING_X10, 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_append(sb, FOO_STRING);    if(test_util_string_is_set(sb, FOO_STRING_X5, 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_append(sb, FOO_STRING);    if(test_util_string_is_set(sb, FOO_STRING_X10, 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_aprintf_clear(const char *name){    stringbuffer_t *sb;    int i;    sb = stringbuffer_create();    /* * * * * * * * * * * * * * * *     * Append BAR_STRING and test. *     * * * * * * * * * * * * * * * */    /* append bar string. */    stringbuffer_aprintf(sb, "%s", BAR_STRING);    /* check. */    if(test_util_string_is_set(sb, BAR_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 : ", BAR_STRING);    if(test_util_string_is_set(sb, BAR_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;

⌨️ 快捷键说明

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