diff options
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; +} |