diff options
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/cgalpngtest.cc | 24 | ||||
-rw-r--r-- | tests/cgaltest.cc | 24 | ||||
-rw-r--r-- | tests/csgtermtest.cc | 24 | ||||
-rw-r--r-- | tests/csgtestcore.cc | 30 | ||||
-rw-r--r-- | tests/csgtexttest.cc | 24 | ||||
-rw-r--r-- | tests/dumptest.cc | 28 | ||||
-rw-r--r-- | tests/echotest.cc | 24 | ||||
-rw-r--r-- | tests/tests-common.cc | 32 | ||||
-rw-r--r-- | tests/tests-common.h | 6 |
10 files changed, 67 insertions, 150 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e2cbbe5..827eb5d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -158,6 +158,7 @@ include_directories(../src) add_definitions(-DOPENSCAD_VERSION=test -DOPENSCAD_YEAR=2011 -DOPENSCAD_MONTH=10) set(CORE_SOURCES + tests-common.cc ../src/mathc99.cc ../src/handle_dep.cc ../src/qhash.cc diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index bb65fa0..02ee35e 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -25,6 +25,7 @@ */ #include "myqhash.h" +#include "tests-common.h" #include "openscad.h" #include "node.h" #include "module.h" @@ -41,7 +42,6 @@ #include "CGAL_renderer.h" #include "cgal.h" #include "OffscreenView.h" -#include "handle_dep.h" #include <QApplication> #include <QFile> @@ -133,28 +133,12 @@ int main(int argc, char **argv) AbstractModule *root_module; ModuleInstantiation root_inst; - 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(); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 242b7b7..0cbd89a 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -25,8 +25,8 @@ */ #include "myqhash.h" +#include "tests-common.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" @@ -117,28 +117,12 @@ int main(int argc, char **argv) AbstractModule *root_module; ModuleInstantiation root_inst; - 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(); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 08002e2..5268b28 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -25,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" @@ -103,28 +103,12 @@ int main(int argc, char **argv) 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(); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 8460a59..57e397e 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,8 +74,8 @@ 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(); @@ -111,28 +111,12 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) 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(); @@ -231,7 +215,7 @@ 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(); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index afa5bbe..ca28e37 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -24,10 +24,10 @@ * */ +#include "tests-common.h" #include "CSGTextRenderer.h" #include "CSGTextCache.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" @@ -106,28 +106,12 @@ int main(int argc, char **argv) ModuleInstantiation root_inst; 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(); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 7344f95..f35ace3 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -24,8 +24,8 @@ * */ +#include "tests-common.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" @@ -54,30 +54,6 @@ QString currentdir; QString examplesdir; QString librarydir; -static 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; -} - int main(int argc, char **argv) { if (argc != 3) { @@ -135,8 +111,6 @@ 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); diff --git a/tests/echotest.cc b/tests/echotest.cc index 329aac2..d1d1f9b 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -24,8 +24,8 @@ * */ +#include "tests-common.h" #include "openscad.h" -#include "handle_dep.h" #include "node.h" #include "module.h" #include "context.h" @@ -110,28 +110,12 @@ int main(int argc, char **argv) ModuleInstantiation root_inst; 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(); 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; +} diff --git a/tests/tests-common.h b/tests/tests-common.h new file mode 100644 index 0000000..92ebc78 --- /dev/null +++ b/tests/tests-common.h @@ -0,0 +1,6 @@ +#ifndef TESTS_COMMON_H_ +#define TESTS_COMMON_H_ + +class AbstractModule *parsefile(const char *filename); + +#endif |