142 lines
3.3 KiB
C
142 lines
3.3 KiB
C
#include <check.h>
|
|
#include "../include/easycsv.h"
|
|
|
|
static const char SAMPLE1_PATH[] = "samples/1.csv";
|
|
static const char SAMPLE2_PATH[] = "samples/2.csv";
|
|
|
|
START_TEST(test_easycsv_init_read_1)
|
|
{
|
|
easycsv *csv = NULL;
|
|
csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R);
|
|
ck_assert_ptr_nonnull(csv);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
START_TEST(test_easycsv_init_read_2)
|
|
{
|
|
easycsv *csv = NULL;
|
|
csv = easycsv_init(SAMPLE2_PATH, EASYCSV_R);
|
|
ck_assert_ptr_null(csv);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
START_TEST(test_easycsv_init_write_1)
|
|
{
|
|
easycsv *csv = NULL;
|
|
csv = easycsv_init(SAMPLE1_PATH, EASYCSV_W);
|
|
ck_assert_ptr_nonnull(csv);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
START_TEST(test_easycsv_init_write_2)
|
|
{
|
|
easycsv *csv = NULL;
|
|
csv = easycsv_init(SAMPLE2_PATH, EASYCSV_W);
|
|
ck_assert_ptr_nonnull(csv);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
Suite*
|
|
easycsv_constructor_suite(void)
|
|
{
|
|
Suite *s;
|
|
TCase *tc_read, *tc_write;
|
|
|
|
s = suite_create ("constructor");
|
|
tc_read = tcase_create ("read mode");
|
|
tc_write = tcase_create ("write mode");
|
|
|
|
tcase_add_test(tc_read, test_easycsv_init_read_1);
|
|
tcase_add_test(tc_read, test_easycsv_init_read_2);
|
|
tcase_add_test(tc_write, test_easycsv_init_write_1);
|
|
tcase_add_test(tc_write, test_easycsv_init_write_2);
|
|
|
|
suite_add_tcase(s, tc_read);
|
|
//suite_add_tcase(s, tc_write);
|
|
|
|
return s;
|
|
}
|
|
|
|
START_TEST(test_easycsv_print_columns)
|
|
{
|
|
easycsv *csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R);
|
|
ck_assert_int_eq(easycsv_print_columns(csv), 3);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
START_TEST(test_easycsv_print_rows)
|
|
{
|
|
easycsv *csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R);
|
|
ck_assert_int_eq(easycsv_print_rows(csv), 4);
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
START_TEST(test_easycsv_read_value)
|
|
{
|
|
easycsv *csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R);
|
|
char* str;
|
|
|
|
str = easycsv_read_value(csv, 1, 1);
|
|
ck_assert_str_eq(str, "FILEPATHA1");
|
|
free(str);
|
|
|
|
str = easycsv_read_value(csv, 2, 1);
|
|
ck_assert_str_eq(str, "FILEPATHB1");
|
|
free(str);
|
|
|
|
str = easycsv_read_value(csv, 1, 2);
|
|
ck_assert_str_eq(str, "FILEPATHA2");
|
|
free(str);
|
|
|
|
str = easycsv_read_value(csv, 1, 3);
|
|
ck_assert_str_eq(str, "");
|
|
free(str);
|
|
|
|
easycsv_free(csv);
|
|
}
|
|
|
|
/* START_TEST(test_easycsv_readcolumnvalue) */
|
|
/* { */
|
|
/* easycsv *csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R); */
|
|
/* ck_assert_str_eq(easycsv_readcolumnvalue(csv, "TEST1", 1), "FILEPATHA1"); */
|
|
/* ck_assert_str_eq(easycsv_readcolumnvalue(csv, "TEST1", 2), "FILEPATHB1"); */
|
|
/* ck_assert_str_eq(easycsv_readcolumnvalue(csv, "TEST1", 3), NULL); */
|
|
/* ck_assert_str_eq(easycsv_readcolumnvalue(csv, "TEST2", 1), "FILEPATHA2"); */
|
|
/* easycsv_free(csv); */
|
|
/* } */
|
|
|
|
Suite*
|
|
easycsv_access_suite(void)
|
|
{
|
|
Suite *s;
|
|
TCase *tc_find, *tc_read, *tc_print;
|
|
s = suite_create ("access");
|
|
tc_read = tcase_create ("read");
|
|
tcase_add_test(tc_read, test_easycsv_read_value);
|
|
/* tcase_add_test(tc_read, test_easycsv_readcolumnvalue); */
|
|
|
|
tc_print = tcase_create ("print");
|
|
tcase_add_test(tc_print, test_easycsv_print_columns);
|
|
tcase_add_test(tc_print, test_easycsv_print_rows);
|
|
|
|
suite_add_tcase(s, tc_read);
|
|
suite_add_tcase(s, tc_print);
|
|
|
|
return s;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
int number_failed;
|
|
SRunner *sr;
|
|
|
|
sr = srunner_create(easycsv_constructor_suite());
|
|
srunner_add_suite(sr, easycsv_access_suite());
|
|
|
|
srunner_run_all(sr, CK_VERBOSE);
|
|
number_failed = srunner_ntests_failed(sr);
|
|
srunner_free(sr);
|
|
return number_failed;
|
|
}
|