/** * \file * * * \brief Test function for ini_reader module. * * $test$: cp bertos/cfg/cfg_kfile.h $cfgdir/ * $test$: echo "#undef CONFIG_KFILE_GETS" >> $cfgdir/cfg_kfile.h * $test$: echo "#define CONFIG_KFILE_GETS 1" >> $cfgdir/cfg_kfile.h * * \author Luca Ottaviano */ #include #include #include // strcmp #include "ini_reader.h" const char ini_file[] = "./test/ini_reader_file.ini"; static KFilePosix kf; int ini_reader_testSetup(void) { kdbg_init(); if (!kfile_posix_init(&kf, ini_file, "r")) { kprintf("No test file found\n"); return -1; } return 0; } int ini_reader_testRun(void) { char buf[30]; memset(buf, 0, 30); ASSERT(ini_getString(&kf.fd, "First", "String", "default", buf, 30) != EOF); ASSERT(strcmp(buf, "noot") == 0); ASSERT(ini_getString(&kf.fd, "Second", "Val", "default", buf, 30) != EOF); ASSERT(strcmp(buf, "2") == 0); ASSERT(ini_getString(&kf.fd, "First", "Empty", "default", buf, 30) != EOF); ASSERT(strcmp(buf, "") == 0); ASSERT(ini_getString(&kf.fd, "Second", "Bar", "default", buf, 30) == EOF); ASSERT(strcmp(buf, "default") == 0); ASSERT(ini_getString(&kf.fd, "Foo", "Bar", "default", buf, 30) == EOF); ASSERT(strcmp(buf, "default") == 0); ASSERT(ini_getString(&kf.fd, "Second", "Long key", "", buf, 30) == EOF); ASSERT(ini_getString(&kf.fd, "Second", "comment", "", buf, 30) != EOF); ASSERT(strcmp(buf, "line with #comment") == 0); ASSERT(ini_getString(&kf.fd, "Long section with spaces", "value", "", buf, 30) != EOF); ASSERT(strcmp(buf, "long value") == 0); ASSERT(ini_getString(&kf.fd, "Long section with spaces", "no_new_line", "", buf, 30) != EOF); ASSERT(strcmp(buf, "value") == 0); return 0; } int ini_reader_testTearDown(void) { return kfile_close(&kf.fd); } TEST_MAIN(ini_reader);