diff options
author | Marius Kintel <marius@kintel.net> | 2011-11-03 18:50:10 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-11-03 18:50:10 (GMT) |
commit | 7845bd05980dc29d3edce2861f3a9f46351e43b8 (patch) | |
tree | a72a43c916a80244875d2299071478051e56076a | |
parent | c3f44b495323297d3b82af54788ea9bf568947c8 (diff) |
Also test roundtripping the dumped file
-rw-r--r-- | tests/dumptest.cc | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 3782446..8e48d24 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -54,6 +54,30 @@ QString currentdir; QString examplesdir; QString librarydir; +static AbstractModule *parsefile(const char *filename) +{ + AbstractModule *root_module = NULL; + + QFileInfo fileInfo(filename); + handle_dep(filename); + FILE *fp = fopen(filename, "rt"); + if (!fp) { + fprintf(stderr, "Can't open input file `%s'!\n", filename); + } else { + std::stringstream text; + char buffer[513]; + int ret; + while ((ret = fread(buffer, 1, 512, fp)) > 0) { + buffer[ret] = 0; + text << buffer; + } + fclose(fp); + text << commandline_commands; + root_module = parse(text.str().c_str(), fileInfo.absolutePath().toLocal8Bit(), false); + } + return root_module; +} + int main(int argc, char **argv) { if (argc != 3) { @@ -114,28 +138,12 @@ int main(int argc, char **argv) ModuleInstantiation root_inst; AbstractNode *root_node; - QFileInfo fileInfo(filename); - handle_dep(filename); - FILE *fp = fopen(filename, "rt"); - if (!fp) { - fprintf(stderr, "Can't open input file `%s'!\n", filename); + root_module = parsefile(filename); + if (!root_module) { exit(1); - } else { - std::stringstream text; - char buffer[513]; - int ret; - while ((ret = fread(buffer, 1, 512, fp)) > 0) { - buffer[ret] = 0; - text << buffer; - } - fclose(fp); - text << commandline_commands; - root_module = parse(text.str().c_str(), fileInfo.absolutePath().toLocal8Bit(), false); - if (!root_module) { - exit(1); - } } + QFileInfo fileInfo(filename); QDir::setCurrent(fileInfo.absolutePath()); AbstractNode::resetIndexCounter(); @@ -150,11 +158,17 @@ int main(int argc, char **argv) string dumpstdstr_cached = tree.getString(*root_node); assert(dumpstdstr == dumpstdstr_cached); + QDir::setCurrent(original_path.absolutePath()); std::ofstream outfile; outfile.open(outfilename); outfile << dumpstdstr << "\n"; outfile.close(); + if (!parsefile(outfilename)) { + fprintf(stderr, "Error: Unable to read back dumped file\n"); + exit(1); + } + destroy_builtin_functions(); destroy_builtin_modules(); |