示例#1
0
文件: tests.c 项目: DownGoat/plstr
void test_split() {
    int size = 0;
    char the_string[] = "fooasdbar";
    char **ret_val;

    ret_val = pl_split(the_string, "asd", &size);

    assert_equal_str(
                "foo",
                ret_val[0],
                "test_split",
                "Test 1: The strings are not equal."
            );

    assert_equal_str(
                "bar",
                ret_val[1],
                "test_split",
                "Test 2: The strings are not equal."
            );

    assert_equal_int(
                2,
                size,
                "test_split",
                "Test 3: Size is not correct."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val);
}
示例#2
0
文件: tests.c 项目: DownGoat/plstr
void test_expandtabs() {
    char *ret_val;

    ret_val = pl_expandtabs("this is a\ttabbed\t\tstring", 4);
    assert_equal_str(
                "this is a   tabbed      string",
                ret_val,
                "test_expandtabs",
                "Test 1: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_expandtabs("'\t'", 10);
    assert_equal_str(
                "'         '",
                ret_val,
                "test_expandtabs",
                "Test 2: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_expandtabs("asd\tdsa", 0);
    assert_equal_str(
                "asddsa",
                ret_val,
                "test_expandtabs",
                "Test 3: Strings are not equal."
            );

    free(ret_val);
}
示例#3
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_both_negative() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, -13, -4);

    assert_equal_str(
                "eggs, and",
                ret_val,
                "test_slice_both_negative",
                "Test 1: The function did not return the correct substring."
            );

    free(ret_val);

    ret_val = pl_slice(the_string, -5, -5);

    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_both_negative",
                "Test 2: The function did not return the correct substring."
            );

    ret_val = pl_slice(the_string, -5, -10);

    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_both_negative",
                "Test 3: The function did not return the correct substring."
            );
}
示例#4
0
文件: tests.c 项目: DownGoat/plstr
void test_strcat_empty_params() {
    char *ret_val;

    ret_val = pl_cat(NULL, "asd");
    assert_equal_str(
                NULL,
                ret_val,
                "test_strcat_empty_params",
                "Test 1: NULL not returned."
            );

    ret_val = pl_cat("asd", NULL);
    assert_equal_str(
                NULL,
                ret_val,
                "test_strcat_empty_params",
                "Test 2: NULL not returned."
            );

    ret_val = pl_cat(NULL, NULL);
    assert_equal_str(
                NULL,
                ret_val,
                "test_strcat_empty_params",
                "Test 3: NULL not returned."
            );
}
示例#5
0
文件: tests.c 项目: DownGoat/plstr
void test_translate() {
    char *ret_val;

    ret_val = pl_translate("read this short text", NULL, "aeiou");
    assert_equal_str(
                "rd ths shrt txt",
                ret_val,
                "test_translate",
                "Test 1: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_translate("read this short text", (unsigned char *) "aeiou", "xxxxx");
    assert_equal_str(
                "rxxd thxs shxrt txxt",
                ret_val,
                "test_translate",
                "Test 2: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_translate("read this short text", (unsigned char *) "zzzzz", "aeiou");
    assert_equal_str(
                "read this short text",
                ret_val,
                "test_translate",
                "Test 3: Strings are not equal"
            );

    free(ret_val);
}
示例#6
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_negative_offset() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, -3, 9);

    assert_equal_str(
            NULL,
            ret_val,
            "test_slice_negative_offset",
            "Test 1: The ret_val is not empty."
            );


    ret_val = pl_slice(the_string, -1, 9);

    assert_equal_str(
            NULL,
            ret_val,
            "test_slice_negative_offset",
            "Test 2: The ret_val is not empty."
            );

    ret_val = pl_slice(the_string, -9, 9);

    assert_equal_str(
            NULL,
            ret_val,
            "test_slice_negative_offset",
            "Test 3: The ret_val is not empty."
            );

    ret_val = pl_slice(the_string, -1, 3);

    assert_equal_str(
            NULL,
            ret_val,
            "test_slice_negative_offset",
            "Test 4: The ret_val is not empty."
            );

    ret_val = pl_slice(the_string, -4, 1);

    assert_equal_str(
            NULL,
            ret_val,
            "test_slice_negative_offset",
            "Test 5: The ret_val is not empty."
            );
}
示例#7
0
文件: tests.c 项目: DownGoat/plstr
void test_strip_empty_params() {
    char *ret_val;

    ret_val = pl_strip("", "a");
    assert_equal_str(
                NULL,
                ret_val,
                "test_strip_empty_params",
                "Test 1: NULL not returned."
            );

    ret_val = pl_strip("   asd   ", "");
    assert_equal_str(
                "asd",
                ret_val,
                "test_strip_empty_params",
                "Test 2: Strings not equal."
            );

    free(ret_val);

    ret_val = pl_strip("   asd   ", NULL);
    assert_equal_str(
                "asd",
                ret_val,
                "test_strip_empty_params",
                "Test 3: Strings not equal."
            );

    free(ret_val);

    ret_val = pl_strip(NULL, NULL);
    assert_equal_str(
                NULL,
                ret_val,
                "test_strip_empty_params",
                "Test 4: NULL not returned"
            );

    ret_val = pl_strip(NULL, "asd");
    assert_equal_str(
                NULL,
                ret_val,
                "test_strip_empty_params",
                "Test 5: NULL not returned."
            );
}
示例#8
0
文件: tests.c 项目: DownGoat/plstr
void test_strip_with_chars() {
    char *ret_val;
    char str1[] = "aaabbbccc";
    char str2[] = "bbbcccaaa";
    char str3[] = "aaabbbcccaaa";
    char str4[] = "adadbbbcccadad";

    ret_val = pl_strip(str1, "a");
    assert_equal_str(
                "bbbccc",
                ret_val,
                "test_strip_with_chars",
                "Test 1: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str2, "a");
    assert_equal_str(
                "bbbccc",
                ret_val,
                "test_strip_with_chars",
                "Test 2: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str3, "a");
    assert_equal_str(
                "bbbccc",
                ret_val,
                "test_strip_with_chars",
                "Test 3: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str4, "ad");
    assert_equal_str(
                "bbbccc",
                ret_val,
                "test_strip_with_chars",
                "Test 4: Strings are not equal."
            );

    free(ret_val);
}
示例#9
0
文件: tests.c 项目: DownGoat/plstr
void test_strip_no_chars() {
    char the_string[] = "   aaabbbccc";
    char str2[] = "aaabbbccc   ";
    char str3[] = "   aaabbbccc   ";
    char str4[] = "\n\r\t\v\f aaabbbccc    \f\v\r\n\t";
    char *ret_val;

    ret_val = pl_strip(the_string, NULL);
    assert_equal_str(
                "aaabbbccc",
                ret_val,
                "test_strip_no_chars",
                "Test 1: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str2, NULL);
    assert_equal_str(
                "aaabbbccc",
                ret_val,
                "test_strip_no_chars",
                "Test 2: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str3, NULL);
    assert_equal_str(
                "aaabbbccc",
                ret_val,
                "test_strip_no_chars",
                "Test 3: Strings are not equal."
            );

    free(ret_val);

    ret_val = pl_strip(str4, NULL);
    assert_equal_str(
                "aaabbbccc",
                ret_val,
                "test_strip_no_chars",
                "Test 4: Strings are not equal."
            );

    free(ret_val);
}
示例#10
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_negative_limit() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, 1, -3);

    assert_equal_str(
                "pam, eggs, and ",
                ret_val,
                "test_slice_negative_limit",
                "Test 1: The strings are not equal"
            );

    free(ret_val);

    ret_val = pl_slice(the_string, 1, -10);

    assert_equal_str(
                "pam, egg",
                ret_val,
                "test_slice_negative_limit",
                "Test 2: The strings are not equal"
            );

    free(ret_val);

    ret_val = pl_slice(the_string, 9, -10);

    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_negative_limit",
                "Test 3: The strings are not equal"
            );

    ret_val = pl_slice(the_string, 0, -5);

    assert_equal_str(
                "spam, eggs, an",
                ret_val,
                "test_slice_negative_limit",
                "Test 4: The strings are not equal"
            );

    free(ret_val);
}
示例#11
0
文件: tests.c 项目: DownGoat/plstr
void test_splitlines_keepends() {
    char **ret_val = NULL;
    int size = 0;

    ret_val = pl_splitlines("asd\ndsa\n\rqwe", 1, &size);
    assert_equal_str(
                "asd\n",
                ret_val[0],
                "test_splitlines_keepends",
                "Test 1: Strings not equal."
            );

    assert_equal_str(
                "dsa\n",
                ret_val[1],
                "test_splitlines_keepends",
                "Test 2: Strings not equal."
            );

    assert_equal_str(
                "\r",
                ret_val[2],
                "test_splitlines_keepends",
                "Test 3: Strings not equal."
            );

    assert_equal_str(
                "qwe",
                ret_val[3],
                "test_splitlines_keepends",
                "Test 4: Strings not equal."
            );

    assert_equal_int(
                4,
                size,
                "test_splitlines_keepends",
                "Test 5: Size not right."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val[3]);
    free(ret_val);
}
示例#12
0
文件: tests.c 项目: DownGoat/plstr
void test_splitlines() {
    char **ret_val = NULL;
    int size = 0;

    ret_val = pl_splitlines("asd\ndsa\n\rqwe", 0, &size);
    assert_equal_str(
                "asd",
                ret_val[0],
                "test_splitlines",
                "Test 1: Strings are not equal"
            );

    assert_equal_str(
                "dsa",
                ret_val[1],
                "test_splitlines",
                "Test 2: Strings are not equal."
            );

    assert_equal_str(
                "",
                ret_val[2],
                "test_splitlines",
                "Test 3: String is not empty."
            );

    assert_equal_str(
                "qwe",
                ret_val[3],
                "test_splitlines",
                "Test 4: Strings are not equal."
            );

    assert_equal_int(
                4,
                size,
                "test_splitlines",
                "Test 5: Size not right;"
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val[3]);
    free(ret_val);
}
示例#13
0
文件: tests.c 项目: DownGoat/plstr
void test_split_empty_paras() {
    char **ret_val;
    int size = 0;

    ret_val = pl_split("", " ", &size);
    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_paras",
                "Test 1: NULL not returned."
            );

    ret_val = pl_split(NULL, " ", &size);
    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_paras",
                "Test 2: NULL not returned"
            );

    ret_val = pl_split("asd asd", "", &size);
    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_paras",
                "Test 3: NULL not returned."
            );

    ret_val = pl_split("asd asd", NULL, &size);
    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_paras",
                "Test 4: NULL not returned."
            );

    ret_val = pl_split("asd asd", " ", NULL);
    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_paras",
                "Test 5: NULL not returned."
            );
}
示例#14
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_empty_string() {
    char *ret_val;

    ret_val = pl_slice("", 1, 3);
    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_empty_string",
                "Test 1: NULL not returned."
            );

    ret_val = pl_slice(NULL, 1, 3);
    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_empty_string",
                "Test 2: NULL not returned."
            );
}
示例#15
0
文件: db_test.c 项目: fadec/sqlpilot
void test_db_prepare(void)
{
	DB *db;
	DBStatement *stmt;
	const char *sql_tail;
	db = db_open("test.db");
	db_prepare(db, "select * from memos;", &stmt, &sql_tail);
	assert_equal_str(sql_tail, "");
	db_finalize(stmt);
	db_close(db);
}
示例#16
0
文件: tests.c 项目: DownGoat/plstr
void test_strcpy_empty_paras() {
    char *ret_val;

    ret_val = pl_cpy(NULL, NULL);
    assert_equal_str(
                NULL,
                ret_val,
                "test_strcpy_empty_paras",
                "Test 2: NULL not returned."
            );
}
示例#17
0
文件: tests.c 项目: DownGoat/plstr
void test_split_single_delim() {
    int size = 0;
    char the_string[] = "abc def ghi";
    char **ret_val;

    ret_val = pl_split(the_string, " ", &size);

    assert_equal_str(
                "abc",
                ret_val[0],
                "test_split_single_delim",
                "Test 1: Strings not equal."
            );

    assert_equal_str(
                "def",
                ret_val[1],
                "test_split_single_delim",
                "Test 2: Strings not equal."
            );

    assert_equal_str(
                "ghi",
                ret_val[2],
                "test_split_single_delim",
                "Test 3: Strings not equal."
            );

    assert_equal_int(
                3,
                size,
                "test_split_single_delim",
                "Test 4: Size of the returned array is not right."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val);
}
示例#18
0
文件: tests.c 项目: DownGoat/plstr
void test_split_multiple_delims() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "asd", &size);

    assert_equal_str(
                "foo",
                ret_val[0],
                "test_split_multiple_delims",
                "Test 1: Strings are not equal."
            );

    assert_equal_str(
                "bar",
                ret_val[1],
                "test_split_multiple_delims",
                "Test 2: Strings are not equal."
            );

    assert_equal_str(
                "magic",
                ret_val[2],
                "test_split_multiple_delims",
                "Test 3: Strings are not equal"
            );

    assert_equal_int(
                3,
                size,
                "test_split_multiple_delims",
                "Test 4: Size is not correct."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val);
}
示例#19
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_equal_offlim() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, 3, 3);

    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_equal_offlim",
                "The strings are not equal."
            );
}
示例#20
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_offset_oor() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, 99, 199);

    assert_equal_str(
                NULL,
                ret_val,
                "test_slice_offset_oor",
                "The ret_val was not NULL"
            );
}
示例#21
0
文件: tests.c 项目: DownGoat/plstr
void test_slice_positive_sub_str() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_slice(the_string, 3, 9);

    assert_equal_str(
            "m, egg",
            ret_val,
            "test_slice_positive_sub_str",
            "The substring is not equal to the sliced string."
            );

    free(ret_val);
}
示例#22
0
文件: tests.c 项目: DownGoat/plstr
void test_strcpy_no_alloc() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = pl_cpy(the_string, NULL);

    assert_equal_str(
                "spam, eggs, and ham",
                ret_val,
                "test_strcpy_no_alloc",
                "The strings are not equal."
            );

    free(ret_val);
}
示例#23
0
文件: tests.c 项目: DownGoat/plstr
void test_strcat_empty_source() {
    char empty[5] = {0};
    char bar[] = "bar";
    char *ret_val;

    ret_val = pl_cat(empty, bar);

    assert_equal_str(
                "bar",
                ret_val,
                "test_strcat_empty_source",
                "The strings are not equal."
            );

    free(ret_val);
}
示例#24
0
文件: tests.c 项目: DownGoat/plstr
void test_strcat_empty_destination() {
    char empty[5] = {0};
    char foo[] = "foo";
    char *ret_val;

    ret_val = pl_cat(foo, empty);

    assert_equal_str(
                "foo",
                ret_val,
                "test_strcat_empty_destination",
                "The strings are not equal."
            );

    free(ret_val);
}
示例#25
0
文件: tests.c 项目: DownGoat/plstr
void test_strcat() {
    char foo[] = "foo";
    char bar[] = "bar";
    char *ret_val;

    ret_val = pl_cat(foo, bar);

    assert_equal_str(
                "foobar",
                ret_val,
                "test_strcat",
                "The strings are not equal."
            );

    free(ret_val);
}
示例#26
0
文件: tests.c 项目: DownGoat/plstr
void test_strcpy_pre_alloc() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val;

    ret_val = (char *) calloc(strlen(the_string) + 1, sizeof(char));

    ret_val = pl_cpy(the_string, ret_val);

    assert_equal_str(
                "spam, eggs, and ham",
                ret_val,
                "test_strcpy_pre_alloc",
                "The strings are not equal."
            );

    free(ret_val);
}
示例#27
0
文件: tests.c 项目: DownGoat/plstr
void test_strcpy_not_empty() {
    char the_string[] = "spam, eggs, and ham";
    char *ret_val, tmp[100];

    strcpy(tmp, "foobar");

    ret_val = pl_cpy(the_string, NULL);

    assert_equal_str(
                "spam, eggs, and ham",
                ret_val,
                "test_strcpy_not_empty",
                "The strings are not equal"
            );

    free(ret_val);
}
示例#28
0
文件: tests.c 项目: DownGoat/plstr
void test_split_delim_not_found() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "x", &size);

    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_delim_not_found",
                "Test 1: NULL not returned."
            );

    assert_equal_int(
                0,
                size,
                "test_split_delim_not_found",
                "Test 2: Size is not correct."
            );
}
示例#29
0
文件: tests.c 项目: DownGoat/plstr
void test_split_empty_delim() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "", &size);

    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_delim",
                "Test 1: NULL not returned."
            );

    assert_equal_int(
                0,
                size,
                "test_split_empty_delim",
                "Test 2: Size is not right."
            );
}
示例#30
0
文件: db_test.c 项目: fadec/sqlpilot
void test_db(void)
{
	DB *mydb;
	DBResults *results;
	char *errormsg;

	mydb = db_open("test.db");
	results = db_get_table(mydb, "select * from memos;", &errormsg);

	assert_equal_str(db_results_table_lookup(results, 0, 0), "Hello");
	assert_equal_str(db_results_table_lookup(results, 0, 1), "World");
	assert_equal_str(db_results_table_lookup(results, 1, 0), "Yes");
	assert_equal_str(db_results_table_lookup(results, 1, 1), "No");

	assert_equal_str(db_results_column_name(results, 0), "subject");
	assert_equal_str(db_results_column_name(results, 1), "body");

	db_results_free(results);
	db_close(mydb);
}