mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
csv-imp - add basic test for gnc_csv_parse
This commit is contained in:
parent
afff8102f4
commit
598531f7e6
@ -46,6 +46,28 @@ teardown( Fixture *fixture, gconstpointer pData )
|
||||
static const gchar *suitename = "/import-export/csv-imp/gnc-csv-model";
|
||||
void test_suite_gnc_csv_model ( void );
|
||||
|
||||
static char* get_filepath(const char* filename, gboolean test_existence)
|
||||
{
|
||||
char *result;
|
||||
|
||||
const char *srcdir = g_getenv("SRCDIR");
|
||||
if (!srcdir)
|
||||
{
|
||||
g_test_message("No env variable SRCDIR exists, assuming \".\"\n");
|
||||
srcdir = ".";
|
||||
}
|
||||
|
||||
result = g_strdup_printf("%s/%s", srcdir, filename);
|
||||
|
||||
g_test_message("Using file path %s\n", result);
|
||||
|
||||
// Test whether the file really exists
|
||||
if (test_existence)
|
||||
g_assert(g_file_test(result, G_FILE_TEST_EXISTS));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* parse_date_with_year
|
||||
time64 parse_date_with_year (const char* date_str, int format)// Local: 1:0:0
|
||||
*/
|
||||
@ -91,10 +113,44 @@ test_gnc_csv_load_file (Fixture *fixture, gconstpointer pData)
|
||||
/* gnc_csv_parse
|
||||
int gnc_csv_parse (GncCsvParseData* parse_data, gboolean guessColTypes, GError** error)// C: 13 in 1 Local: 0:0:0
|
||||
*/
|
||||
/* static void
|
||||
static void
|
||||
test_gnc_csv_parse (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
}*/
|
||||
|
||||
char *file1 = get_filepath ("notexist.csv", FALSE);
|
||||
char *file2 = get_filepath ("sample1.csv", TRUE);
|
||||
GError *the_error = NULL;
|
||||
int resultcode = 0;
|
||||
|
||||
GncCsvParseData* parse_data = gnc_csv_new_parse_data ();
|
||||
|
||||
/* Test if object creation worked */
|
||||
g_assert (parse_data != NULL);
|
||||
|
||||
/* Test loading of a non-existing file */
|
||||
resultcode = gnc_csv_load_file (parse_data, file1,
|
||||
&the_error);
|
||||
g_assert ((the_error->domain == GNC_CSV_IMP_ERROR) &&
|
||||
(the_error->code == GNC_CSV_IMP_ERROR_OPEN));
|
||||
|
||||
/* Test loading of a valid csv file */
|
||||
resultcode = gnc_csv_load_file (parse_data, file2,
|
||||
&the_error);
|
||||
g_assert (resultcode == 0);
|
||||
|
||||
/* Test basic parsing of the loaded file
|
||||
* A few fields are sampled in the parsed data. */
|
||||
resultcode = gnc_csv_parse (parse_data, TRUE, &the_error);
|
||||
g_assert (g_strcmp0 ((char*)((GPtrArray*)(parse_data->orig_lines->pdata[0]))->pdata[0],
|
||||
"Date") == 0);
|
||||
g_assert (g_strcmp0 ((char*)((GPtrArray*)(parse_data->orig_lines->pdata[1]))->pdata[6],
|
||||
"1,100.00") == 0);
|
||||
|
||||
/* Clean up */
|
||||
g_free(file1);
|
||||
g_free(file2);
|
||||
gnc_csv_parse_data_free (parse_data);
|
||||
}
|
||||
/* trans_property_free
|
||||
static void trans_property_free (TransProperty* prop)// Local: 2:0:0
|
||||
*/
|
||||
@ -156,7 +212,7 @@ test_suite_gnc_csv_model (void)
|
||||
// GNC_TEST_ADD (suitename, "gnc csv parse data free", Fixture, NULL, setup, test_gnc_csv_parse_data_free, teardown);
|
||||
// GNC_TEST_ADD (suitename, "gnc csv convert encoding", Fixture, NULL, setup, test_gnc_csv_convert_encoding, teardown);
|
||||
// GNC_TEST_ADD (suitename, "gnc csv load file", Fixture, NULL, setup, test_gnc_csv_load_file, teardown);
|
||||
// GNC_TEST_ADD (suitename, "gnc csv parse", Fixture, NULL, setup, test_gnc_csv_parse, teardown);
|
||||
GNC_TEST_ADD (suitename, "gnc csv parse", Fixture, NULL, setup, test_gnc_csv_parse, teardown);
|
||||
// GNC_TEST_ADD (suitename, "trans property free", Fixture, NULL, setup, test_trans_property_free, teardown);
|
||||
// GNC_TEST_ADD (suitename, "trans property set", Fixture, NULL, setup, test_trans_property_set, teardown);
|
||||
// GNC_TEST_ADD (suitename, "trans property list free", Fixture, NULL, setup, test_trans_property_list_free, teardown);
|
||||
|
Loading…
Reference in New Issue
Block a user