void assert_ini_value( INI_Context *ini, const char *section, const char *key, const char *expected_value) { const char *value = ini_get_value(ini, section, key); if (value == 0 || expected_value == 0) { // Assert that both values are NULL assert(value == expected_value); } else { // Assert that both values contain the same string int value_equals_expected_value = !strcmp(value, expected_value); assert(value_equals_expected_value); } }
void load_config() { char *value; char msg[100]; msg[0] = 0; /* ini_r is a structure that holds state to make this reader * reentrant */ struct read_ini *ini_r = NULL; /* "test.ini" will be parsed into "ini" */ char* root = (*SYS_RootDir)(); char filename[100]; filename[0] = 0; strcat(filename, root); strcat(filename, "\\PlugIns\\"); strcat(filename, "saveall.ini"); struct ini *ini = read_ini(&ini_r, filename); /* pretty printing of ini structure */ ini_pp(ini); /* retrieve a value */ value = ini_get_value(ini, "section", "basedir"); if(value != NULL) { strcat(msg, "value is\n"); strcat(msg, value); strcpy(basedir, value); // ShowMessage(msg); } else { // ShowMessage("cannot get key"); } /* free memory */ destroy_ini(ini); cleanup_readini(ini_r); }