diff options
Diffstat (limited to 'tests/csgtermtest.cc')
-rw-r--r-- | tests/csgtermtest.cc | 52 |
1 files changed, 11 insertions, 41 deletions
diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 643a64f..c8fcc6b 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -1,6 +1,7 @@ /* - * OpenSCAD (www.openscad.at) - * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at> + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and + * Marius Kintel <marius@kintel.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,10 +25,10 @@ */ #include "myqhash.h" +#include "tests-common.h" #include "PolySetEvaluator.h" #include "CSGTermEvaluator.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" @@ -68,8 +69,7 @@ int main(int argc, char **argv) int rc = 0; - initialize_builtin_functions(); - initialize_builtin_modules(); + Builtins::instance()->initialize(); QApplication app(argc, argv, false); QDir original_path = QDir::current(); @@ -96,48 +96,18 @@ int main(int argc, char **argv) } 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; const 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(); @@ -163,6 +133,7 @@ int main(int argc, char **argv) // if (evaluator.background) cout << "Background terms: " << evaluator.background->size() << "\n"; // if (evaluator.highlights) cout << "Highlights terms: " << evaluator.highlights->size() << "\n"; + QDir::setCurrent(original_path.absolutePath()); std::ofstream outfile; outfile.open(outfilename); if (root_term) { @@ -173,8 +144,7 @@ int main(int argc, char **argv) } outfile.close(); - destroy_builtin_functions(); - destroy_builtin_modules(); + Builtins::instance(true); return rc; } |