summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt7
-rw-r--r--tests/cgalpngtest.cc7
-rw-r--r--tests/csgtestcore.cc7
-rw-r--r--tests/dumptest.cc13
-rw-r--r--tests/regression/cgalpngtest/linear_extrude-tests-expected.pngbin12351 -> 10926 bytes
-rw-r--r--tests/regression/cgalpngtest/localfiles-compatibility-test-expected.pngbin0 -> 11732 bytes
-rw-r--r--tests/regression/dumptest/linear_extrude-tests-expected.txt5
-rw-r--r--tests/regression/dumptest/localfiles-compatibility-test-expected.txt20
-rw-r--r--tests/regression/opencsgtest/linear_extrude-tests-expected.pngbin12785 -> 11429 bytes
-rw-r--r--tests/regression/opencsgtest/localfiles-compatibility-test-expected.pngbin0 -> 12657 bytes
-rw-r--r--tests/regression/throwntogethertest/linear_extrude-tests-expected.pngbin12023 -> 11439 bytes
-rw-r--r--tests/regression/throwntogethertest/localfiles-compatibility-test-expected.pngbin0 -> 12657 bytes
-rw-r--r--tests/tests-common.cc11
-rw-r--r--tests/tests-common.h4
14 files changed, 56 insertions, 18 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 51abd06..964adc2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -429,6 +429,7 @@ set(CORE_SOURCES
../src/linearextrude.cc
../src/rotateextrude.cc
../src/printutils.cc
+ ../src/fileutils.cc
../src/progress.cc
../src/boost-utils.cc
${FLEX_OpenSCADlexer_OUTPUTS}
@@ -762,13 +763,15 @@ list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES})
list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad
- ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad)
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles_dir/localfiles-compatibility-test.scad)
list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILES})
list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad
- ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad)
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles_dir/localfiles-compatibility-test.scad)
list(APPEND OPENCSGTEST_FILES ${CGALPNGTEST_FILES})
list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/bbox-transform-bug.scad)
diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc
index 81fc6b4..7b958de 100644
--- a/tests/cgalpngtest.cc
+++ b/tests/cgalpngtest.cc
@@ -113,9 +113,10 @@ int main(int argc, char **argv)
exit(1);
}
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
AbstractNode::resetIndexCounter();
AbstractNode *absolute_root_node = root_module->instantiate(&top_ctx, &root_inst);
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 320b533..7b9dbab 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -148,9 +148,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
}
if (!sysinfo_dump) {
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
}
AbstractNode::resetIndexCounter();
diff --git a/tests/dumptest.cc b/tests/dumptest.cc
index e4876fa..4477703 100644
--- a/tests/dumptest.cc
+++ b/tests/dumptest.cc
@@ -97,9 +97,10 @@ int main(int argc, char **argv)
exit(1);
}
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
AbstractNode::resetIndexCounter();
root_node = root_module->instantiate(&top_ctx, &root_inst);
@@ -130,7 +131,7 @@ int main(int argc, char **argv)
delete root_module;
fs::current_path(original_path);
- root_module = parsefile(outfilename);
+ root_module = parsefile(outfilename, fparent.string().c_str());
if (!root_module) {
fprintf(stderr, "Error: Unable to read back dumped file\n");
exit(1);
@@ -141,9 +142,7 @@ int main(int argc, char **argv)
tree.setRoot(root_node);
- if (fs::path(outfilename).has_parent_path()) {
- fs::current_path(fs::path(outfilename).parent_path());
- }
+ fs::current_path(fparent);
string readbackstr = dumptree(tree, *root_node);
if (dumpstdstr != readbackstr) {
diff --git a/tests/regression/cgalpngtest/linear_extrude-tests-expected.png b/tests/regression/cgalpngtest/linear_extrude-tests-expected.png
index 1486743..7d3ea2c 100644
--- a/tests/regression/cgalpngtest/linear_extrude-tests-expected.png
+++ b/tests/regression/cgalpngtest/linear_extrude-tests-expected.png
Binary files differ
diff --git a/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png b/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..d0cfd50
--- /dev/null
+++ b/tests/regression/cgalpngtest/localfiles-compatibility-test-expected.png
Binary files differ
diff --git a/tests/regression/dumptest/linear_extrude-tests-expected.txt b/tests/regression/dumptest/linear_extrude-tests-expected.txt
index cba1189..298b7e7 100644
--- a/tests/regression/dumptest/linear_extrude-tests-expected.txt
+++ b/tests/regression/dumptest/linear_extrude-tests-expected.txt
@@ -29,4 +29,9 @@
square(size = [10, 10], center = false);
}
}
+ multmatrix([[1, 0, 0, -15], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ linear_extrude(height = 5, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
+ square(size = [10, 10], center = false);
+ }
+ }
diff --git a/tests/regression/dumptest/localfiles-compatibility-test-expected.txt b/tests/regression/dumptest/localfiles-compatibility-test-expected.txt
new file mode 100644
index 0000000..8725061
--- /dev/null
+++ b/tests/regression/dumptest/localfiles-compatibility-test-expected.txt
@@ -0,0 +1,20 @@
+ group() {
+ linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
+ import(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, -250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ linear_extrude(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, 350], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ rotate_extrude(file = "localfile.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2);
+ }
+ multmatrix([[1, 0, 0, 250], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ multmatrix([[200, 0, 0, 0], [0, 200, 0, 0], [0, 0, 50, 0], [0, 0, 0, 1]]) {
+ surface(file = "localfile.dat", center = false);
+ }
+ }
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, -200], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ sphere($fn = 0, $fa = 12, $fs = 2, r = 100);
+ }
+ }
+
diff --git a/tests/regression/opencsgtest/linear_extrude-tests-expected.png b/tests/regression/opencsgtest/linear_extrude-tests-expected.png
index f31b22a..b929d09 100644
--- a/tests/regression/opencsgtest/linear_extrude-tests-expected.png
+++ b/tests/regression/opencsgtest/linear_extrude-tests-expected.png
Binary files differ
diff --git a/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png b/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..f280efd
--- /dev/null
+++ b/tests/regression/opencsgtest/localfiles-compatibility-test-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/linear_extrude-tests-expected.png b/tests/regression/throwntogethertest/linear_extrude-tests-expected.png
index b672783..fddeeb8 100644
--- a/tests/regression/throwntogethertest/linear_extrude-tests-expected.png
+++ b/tests/regression/throwntogethertest/linear_extrude-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png b/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png
new file mode 100644
index 0000000..f280efd
--- /dev/null
+++ b/tests/regression/throwntogethertest/localfiles-compatibility-test-expected.png
Binary files differ
diff --git a/tests/tests-common.cc b/tests/tests-common.cc
index ac85e37..3c66e1b 100644
--- a/tests/tests-common.cc
+++ b/tests/tests-common.cc
@@ -7,7 +7,12 @@
#include <sstream>
#include <fstream>
-FileModule *parsefile(const char *filename)
+/*!
+ fakepath is used to force the parser to believe that the file is
+ read from this location, in order to ensure that filepaths are
+ eavluated relative to this path (for testing purposes).
+*/
+FileModule *parsefile(const char *filename, const char *fakepath)
{
FileModule *root_module = NULL;
@@ -19,7 +24,9 @@ FileModule *parsefile(const char *filename)
else {
std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
text += "\n" + commandline_commands;
- std::string pathname = boosty::stringy(fs::path(filename).parent_path());
+ std::string pathname;
+ if (fakepath) pathname = fakepath;
+ else pathname = boosty::stringy(fs::path(filename).parent_path());
root_module = parse(text.c_str(), pathname.c_str(), false);
if (root_module) {
root_module->handleDependencies();
diff --git a/tests/tests-common.h b/tests/tests-common.h
index 3393884..e16bcda 100644
--- a/tests/tests-common.h
+++ b/tests/tests-common.h
@@ -1,6 +1,8 @@
#ifndef TESTS_COMMON_H_
#define TESTS_COMMON_H_
-class FileModule *parsefile(const char *filename);
+#include <stdlib.h>
+
+class FileModule *parsefile(const char *filename, const char *fakepath = NULL);
#endif
contact: Jan Huwald // Impressum