// helper functions to test the parsing of config files and/or metaknobs // void testparse(int lineno, MACRO_SET & set, MACRO_EVAL_CONTEXT &ctx, MACRO_SOURCE & source, bool verbose, const char * tag, const char * params, const char * expected) { int ret = Parse_config_string(source, 0, params, set, ctx); const char * hashout = NULL; if (ret < 0) { fprintf(stderr, "Failed %5d: test '%s' local=%s subsys=%s parse error %d\n", lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : "", ret); gmstr.clear(); hashout = NULL; } else { dump_macro_set(set, gmstr, "\t"); hashout = gmstr.c_str(); if (gmstr != expected) { fprintf(stderr, "Failed %5d: test '%s' local=%s subsys=%s resulting hashtable does not match expected\n", lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : ""); ret = -1; } else if (verbose) { fprintf(stdout, " OK %5d: test '%s' local=%s subsys=%s\n", lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : ""); ret = 0; } } if (verbose || ret) { fprintf(ret ? stderr : stdout, "\t---- parse input %d ----\n%s", lineno, params); if (hashout) fprintf(ret ? stderr : stdout, "\t---- resulting hash %d ----\n%s", lineno, hashout); if (ret) fprintf(stderr, "\t---- expected hash %d ----\n%s", lineno, expected); fprintf(ret ? stderr : stdout, "\t---- end %d ----\n\n", lineno); } clear_macro_set(set); }
static void dump_macro_set(MACRO_SET & set, MyString & str, const char * prefix) { str.clear(); HASHITER it = hash_iter_begin(set, HASHITER_NO_DEFAULTS | HASHITER_SHOW_DUPS); while( ! hash_iter_done(it)) { const char *name = hash_iter_key(it); const char *val = hash_iter_value(it); //const MACRO_META *met = hash_iter_meta(it); if (prefix) str += prefix; str += name; str += "="; str += val ? val : ""; str += "\n"; hash_iter_next(it); } hash_iter_delete(&it); }
bool user_map_do_mapping(const char *, const char *, MyString & output) { output.clear(); return false; }