diff options
Diffstat (limited to 'tests/csgtestcore.cc')
-rw-r--r-- | tests/csgtestcore.cc | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 2390f06..034084c 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -1,9 +1,9 @@ // csg test core, used by throwntegether test and opencsg test #include "csgtestcore.h" +#include "tests-common.h" #include "system-gl.h" #include "openscad.h" -#include "handle_dep.h" #include "builtin.h" #include "context.h" #include "node.h" @@ -74,11 +74,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) exit(1); } - std::string filename(argv[1]); - std::string outfile(argv[2]); + const char *filename = argv[1]; + const char *outfilename = argv[2]; - initialize_builtin_functions(); - initialize_builtin_modules(); + Builtins::instance()->initialize(); QApplication app(argc, argv, false); @@ -106,47 +105,17 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } Context root_ctx; - root_ctx.functions_p = &builtin_functions; - root_ctx.modules_p = &builtin_modules; - root_ctx.set_variable("$fn", Value(0.0)); - root_ctx.set_variable("$fs", Value(1.0)); - root_ctx.set_variable("$fa", Value(12.0)); - root_ctx.set_variable("$t", Value(0.0)); - - Value zero3; - zero3.type = Value::VECTOR; - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - zero3.append(new Value(0.0)); - root_ctx.set_variable("$vpt", zero3); - root_ctx.set_variable("$vpr", zero3); - + register_builtin(root_ctx); AbstractModule *root_module; ModuleInstantiation root_inst; - QFileInfo fileInfo(filename.c_str()); - handle_dep(filename); - FILE *fp = fopen(filename.c_str(), "rt"); - if (!fp) { - fprintf(stderr, "Can't open input file `%s'!\n", filename.c_str()); + 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(); @@ -245,10 +214,9 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.glview->paintGL(); - csgInfo.glview->save(outfile.c_str()); + csgInfo.glview->save(outfilename); - destroy_builtin_functions(); - destroy_builtin_modules(); + Builtins::instance(true); return 0; } |