diff options
Diffstat (limited to 'tests/dumptest.cc')
-rw-r--r-- | tests/dumptest.cc | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 7344f95..d2fd9b1 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -24,15 +24,14 @@ * */ +#include "tests-common.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" #include "value.h" #include "export.h" #include "builtin.h" -#include "nodedumper.h" #include "Tree.h" #include <QApplication> @@ -54,28 +53,14 @@ QString currentdir; QString examplesdir; QString librarydir; -static AbstractModule *parsefile(const char *filename) +string dumptree(const Tree &tree, const AbstractNode &node) { - 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); + std::stringstream str; + const std::vector<AbstractNode*> &children = node.getChildren(); + for (std::vector<AbstractNode*>::const_iterator iter = children.begin(); iter != children.end(); iter++) { + str << tree.getString(**iter) << "\n"; } - return root_module; + return str.str(); } int main(int argc, char **argv) @@ -135,14 +120,15 @@ int main(int argc, char **argv) AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); - // Cache test - QString teststr("test"); Tree tree; tree.setRoot(root_node); - string dumpstdstr = tree.getString(*root_node); - string dumpstdstr_cached = tree.getString(*root_node); - assert(dumpstdstr == dumpstdstr_cached); + string dumpstdstr = dumptree(tree, *root_node); + string dumpstdstr_cached = dumptree(tree, *root_node); + if (dumpstdstr != dumpstdstr_cached) { + fprintf(stderr, "Error: Dump cached failed\n"); + exit(1); + } QDir::setCurrent(original_path.absolutePath()); std::ofstream outfile; @@ -150,10 +136,29 @@ int main(int argc, char **argv) outfile << dumpstdstr << "\n"; outfile.close(); - if (!parsefile(outfilename)) { + root_module = parsefile(outfilename); + if (!root_module) { fprintf(stderr, "Error: Unable to read back dumped file\n"); exit(1); } + fileInfo = QFileInfo(outfilename); + QDir::setCurrent(fileInfo.absolutePath()); + + AbstractNode::resetIndexCounter(); + root_node = root_module->evaluate(&root_ctx, &root_inst); + + tree.setRoot(root_node); + + string readbackstr = dumptree(tree, *root_node); + if (dumpstdstr != readbackstr) { + fprintf(stderr, "Error: Readback is different from original dump:\n"); + fprintf(stderr, "Original:\n"); + fprintf(stderr, dumpstdstr.c_str()); + fprintf(stderr, "Readback:\n"); + fprintf(stderr, readbackstr.c_str()); + exit(1); + } + destroy_builtin_functions(); destroy_builtin_modules(); |