Compare commits
9 Commits
f97f364681
...
47095a868e
Author | SHA1 | Date | |
---|---|---|---|
47095a868e | |||
9d1dcc5714 | |||
0354afb2b7 | |||
a8480a2fcf | |||
b2f9953f31 | |||
4c65f21664 | |||
5a2b67b933 | |||
d4e8cc96b2 | |||
6199dc4a12 |
3
bootstrap
Executable file
3
bootstrap
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec autoreconf --verbose --install --force
|
@ -201,7 +201,7 @@ easycsv_init_errormsg(const char *fp,
|
||||
csv->start = clock();
|
||||
#endif
|
||||
|
||||
easycsv *csv = malloc(sizeof *csv);
|
||||
easycsv *csv = malloc(sizeof(easycsv));
|
||||
csv->mode = mode;
|
||||
csv->_priv = _easycsv_priv_init(fp, mode, error);
|
||||
|
||||
@ -687,23 +687,36 @@ _easycsv_priv_init(const char *fp,
|
||||
const EASYCSV_MODE mode,
|
||||
const EASYCSV_ERRORMSG error)
|
||||
{
|
||||
_easycsv *_priv = malloc(sizeof *_priv);
|
||||
memset(_priv, 0, sizeof(*_priv)); // set all members to NULL or 0
|
||||
_easycsv *_priv = malloc(sizeof(_easycsv));
|
||||
|
||||
_priv->file = NULL;
|
||||
_priv->temp = NULL;
|
||||
_priv->fp = NULL;
|
||||
_priv->tmpfp = NULL;
|
||||
_priv->rows = 0;
|
||||
_priv->cols = 0;
|
||||
#ifdef EASYCSV_DEBUG
|
||||
_priv->start = 0;
|
||||
#endif
|
||||
|
||||
_priv->error = error;
|
||||
|
||||
/* Open file according to mode */
|
||||
switch (mode) {
|
||||
case EASYCSV_R:
|
||||
case EASYCSV_W: {
|
||||
case EASYCSV_R: {
|
||||
_priv->file = fopen(fp, "r");
|
||||
break;
|
||||
}
|
||||
case EASYCSV_W: {
|
||||
_priv->file = fopen(fp, "w");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
_easycsv_printerror(_priv, EASYCSV_UNKNOWNIOMODE);
|
||||
_easycsv_priv_free(_priv);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (_priv->file == NULL)
|
||||
{
|
||||
@ -717,22 +730,19 @@ _easycsv_priv_init(const char *fp,
|
||||
/* Allocate memory for char* */
|
||||
_priv->fp = malloc(stfp + 1); // + 1 for null
|
||||
|
||||
strncpy(_priv->fp, fp, stfp);
|
||||
strcpy(_priv->fp, fp);
|
||||
|
||||
/* Calculate rows and cols if file exists */
|
||||
if (access(_priv->fp, F_OK) == 0) {
|
||||
_priv->rows = _easycsv_rows(_priv, mode);
|
||||
_priv->cols = _easycsv_columns(_priv, mode);
|
||||
}
|
||||
else {
|
||||
_priv->rows = 0;
|
||||
_priv->cols = 0;
|
||||
}
|
||||
|
||||
if (mode == EASYCSV_W) {
|
||||
|
||||
/* csv->tmpfp = malloc(16 + stfp + 1); */
|
||||
/* strncpy(csv->tmpfp, prefix, 16); */
|
||||
|
||||
/* strncat(csv->tmpfp, fp, stfp); */
|
||||
|
||||
do {
|
||||
@ -785,7 +795,6 @@ _easycsv_priv_init(const char *fp,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return _priv;
|
||||
}
|
||||
|
||||
@ -892,7 +901,7 @@ _easycsv_columns(_easycsv *_priv,
|
||||
3. if >1 column, n commas = n+1 columns
|
||||
*/
|
||||
|
||||
unsigned int col = 1;
|
||||
int col = 1;
|
||||
char c;
|
||||
|
||||
while ((c = fgetc(_priv->file)) != '\n') {
|
||||
|
@ -4,28 +4,59 @@
|
||||
static const char SAMPLE1_PATH[] = "samples/1.csv";
|
||||
static const char SAMPLE2_PATH[] = "samples/2.csv";
|
||||
|
||||
START_TEST(test_easycsv_init_read)
|
||||
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_nonnull(csv);
|
||||
ck_assert_ptr_null(csv);
|
||||
easycsv_free(csv);
|
||||
}
|
||||
|
||||
START_TEST(test_easycsv_init_write)
|
||||
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_printcolumns)
|
||||
{
|
||||
easycsv *csv = easycsv_init(SAMPLE1_PATH, EASYCSV_R);
|
||||
@ -50,47 +81,25 @@ START_TEST(test_easycsv_readcolumnvalue)
|
||||
easycsv_free(csv);
|
||||
}
|
||||
|
||||
Suite*
|
||||
easycsv_constructor_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_init;
|
||||
|
||||
s = suite_create ("constructor");
|
||||
tc_init = tcase_create ("basic constructor");
|
||||
|
||||
tcase_add_test(tc_init, test_easycsv_init_read);
|
||||
tcase_add_test(tc_init, test_easycsv_init_write);
|
||||
suite_add_tcase(s, tc_init);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Suite*
|
||||
easycsv_print_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_col, *tc_row;
|
||||
s = suite_create ("print");
|
||||
tc_col = tcase_create ("columns");
|
||||
tc_row = tcase_create ("rows");
|
||||
tcase_add_test(tc_col, test_easycsv_printcolumns);
|
||||
tcase_add_test(tc_row, test_easycsv_printrows);
|
||||
suite_add_tcase(s, tc_col);
|
||||
suite_add_tcase(s, tc_row);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Suite*
|
||||
easycsv_read_suite(void)
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc_readcolumnvalue;
|
||||
TCase *tc_readcolumnvalue, *tc_col, *tc_row;
|
||||
s = suite_create ("read");
|
||||
tc_readcolumnvalue = tcase_create ("readcolumnvalue");
|
||||
tcase_add_test(tc_readcolumnvalue, test_easycsv_readcolumnvalue);
|
||||
|
||||
tc_col = tcase_create ("columns");
|
||||
tcase_add_test(tc_col, test_easycsv_printcolumns);
|
||||
|
||||
tc_row = tcase_create ("rows");
|
||||
tcase_add_test(tc_row, test_easycsv_printrows);
|
||||
|
||||
suite_add_tcase(s, tc_readcolumnvalue);
|
||||
suite_add_tcase(s, tc_col);
|
||||
suite_add_tcase(s, tc_row);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -101,7 +110,6 @@ main(void)
|
||||
SRunner *sr;
|
||||
|
||||
sr = srunner_create(easycsv_constructor_suite());
|
||||
srunner_add_suite(sr, easycsv_print_suite());
|
||||
srunner_add_suite(sr, easycsv_read_suite());
|
||||
|
||||
srunner_run_all(sr, CK_VERBOSE);
|
||||
|
Loading…
Reference in New Issue
Block a user