2009-08-20 21:59:32 +00:00
|
|
|
/* inih -- unit tests
|
|
|
|
|
|
|
|
This works simply by dumping a bunch of info to standard output, which is
|
|
|
|
redirected to an output file (baseline_*.txt) and checked into the Subversion
|
|
|
|
repository. This baseline file is the test output, so the idea is to check it
|
|
|
|
once, and if it changes -- look at the diff and see which tests failed.
|
|
|
|
|
2016-12-29 10:53:49 -05:00
|
|
|
See unittest.bat and unittest.sh for how to run this (with tcc and gcc,
|
|
|
|
respectively).
|
2009-08-20 21:59:32 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-06-24 18:48:58 +00:00
|
|
|
#include <string.h>
|
2009-08-20 21:59:32 +00:00
|
|
|
#include "../ini.h"
|
|
|
|
|
|
|
|
int User;
|
|
|
|
char Prev_section[50];
|
|
|
|
|
2016-12-29 10:53:49 -05:00
|
|
|
#if INI_HANDLER_LINENO
|
|
|
|
int dumper(void* user, const char* section, const char* name,
|
|
|
|
const char* value, int lineno)
|
|
|
|
#else
|
2009-08-20 21:59:32 +00:00
|
|
|
int dumper(void* user, const char* section, const char* name,
|
|
|
|
const char* value)
|
2016-12-29 10:53:49 -05:00
|
|
|
#endif
|
2009-08-20 21:59:32 +00:00
|
|
|
{
|
2016-10-11 09:31:22 -04:00
|
|
|
User = *((int*)user);
|
2019-04-08 20:44:21 +08:00
|
|
|
if (!name || strcmp(section, Prev_section)) {
|
2009-08-20 21:59:32 +00:00
|
|
|
printf("... [%s]\n", section);
|
|
|
|
strncpy(Prev_section, section, sizeof(Prev_section));
|
|
|
|
Prev_section[sizeof(Prev_section) - 1] = '\0';
|
|
|
|
}
|
2019-04-08 20:44:21 +08:00
|
|
|
if (!name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2016-12-29 10:53:49 -05:00
|
|
|
|
|
|
|
#if INI_HANDLER_LINENO
|
2019-04-08 20:42:16 -04:00
|
|
|
printf("... %s=%s; line %d\n", name, value, lineno);
|
2016-12-29 10:53:49 -05:00
|
|
|
#else
|
2019-04-08 20:42:16 -04:00
|
|
|
printf("... %s=%s;\n", name, value);
|
2016-12-29 10:53:49 -05:00
|
|
|
#endif
|
2009-08-20 21:59:32 +00:00
|
|
|
|
|
|
|
return strcmp(name, "user")==0 && strcmp(value, "parse_error")==0 ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void parse(const char* fname) {
|
|
|
|
static int u = 100;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
*Prev_section = '\0';
|
2016-10-11 09:31:22 -04:00
|
|
|
e = ini_parse(fname, dumper, &u);
|
2009-08-20 21:59:32 +00:00
|
|
|
printf("%s: e=%d user=%d\n", fname, e, User);
|
|
|
|
u++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
parse("no_file.ini");
|
|
|
|
parse("normal.ini");
|
|
|
|
parse("bad_section.ini");
|
|
|
|
parse("bad_comment.ini");
|
|
|
|
parse("user_error.ini");
|
|
|
|
parse("multi_line.ini");
|
|
|
|
parse("bad_multi.ini");
|
2012-06-19 13:48:44 +00:00
|
|
|
parse("bom.ini");
|
2019-04-08 20:44:21 +08:00
|
|
|
parse("duplicate_sections.ini");
|
2009-08-20 21:59:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|