diff options
author | Marius Kintel <marius@kintel.net> | 2011-11-05 18:38:03 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-11-05 18:38:03 (GMT) |
commit | efcbf8e1a20b46081b9348aa9b6536a23b519073 (patch) | |
tree | a6cf25a29c211d0abe574c8c8057e48a90e656a6 /tests/tests-common.cc | |
parent | d14a24a2b63d7d3815e02a79ef9dacd76cd01f4d (diff) |
Minor refactoring of test code
Diffstat (limited to 'tests/tests-common.cc')
-rw-r--r-- | tests/tests-common.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/tests-common.cc b/tests/tests-common.cc new file mode 100644 index 0000000..1f19c59 --- /dev/null +++ b/tests/tests-common.cc @@ -0,0 +1,32 @@ +#include "tests-common.h" +#include "openscad.h" +#include "module.h" +#include "handle_dep.h" + +#include <QFile> +#include <QFileInfo> +#include <sstream> + +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; +} |