diff options
-rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/OffscreenContextWGL.cc | 130 | ||||
-rw-r--r-- | tests/cgalpngtest.cc | 7 | ||||
-rw-r--r-- | tests/csgtermtest.cc | 13 | ||||
-rw-r--r-- | tests/csgtestcore.cc | 7 | ||||
-rw-r--r-- | tests/csgtexttest.cc | 11 | ||||
-rw-r--r-- | tests/dumptest.cc | 11 | ||||
-rw-r--r-- | tests/imageutils-lodepng.cc | 3 | ||||
-rwxr-xr-x | tests/test_cmdline_tool.py | 15 |
9 files changed, 136 insertions, 64 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 84e0562..593fa1b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -273,12 +273,13 @@ target_link_libraries(throwntogethertest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRAR # This functions adds cmd-line tests given files. # Files are sent as the parameters following TESTSUFFIX # +find_package(PythonInterp) function(add_cmdline_test TESTCMD TESTSUFFIX) get_filename_component(TESTCMD_NAME ${TESTCMD} NAME_WE) foreach (SCADFILE ${ARGN}) get_filename_component(TESTNAME ${SCADFILE} NAME_WE) string(REPLACE " " "_" TESTNAME ${TESTNAME}) # Test names cannot include spaces - add_test("${TESTCMD_NAME}_${TESTNAME}" python ${tests_SOURCE_DIR}/test_cmdline_tool.py -s ${TESTSUFFIX} ${CMAKE_BINARY_DIR}/${TESTCMD} "${SCADFILE}") + add_test("${TESTCMD_NAME}_${TESTNAME}" ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py -s ${TESTSUFFIX} ${CMAKE_BINARY_DIR}/${TESTCMD} "${SCADFILE}") endforeach() endfunction() diff --git a/tests/OffscreenContextWGL.cc b/tests/OffscreenContextWGL.cc index 863da31..17c49c6 100644 --- a/tests/OffscreenContextWGL.cc +++ b/tests/OffscreenContextWGL.cc @@ -2,6 +2,13 @@ Create an OpenGL context without creating an OpenGL Window. for Windows. +For more info: + + http://www.nullterminator.net/opengl32.html by Blaine Hodge + http://msdn.microsoft.com/en-us/library/ee418815(v=vs.85).aspx + http://www.cprogramming.com/tutorial/wgl_wiggle_functions.html by RoD + ( which includes robot.cc by Steven Billington ) + http://blogs.msdn.com/b/oldnewthing/archive/2006/12/04/1205831.aspx by Tom */ #include <windows.h> @@ -35,13 +42,12 @@ void offscreen_context_init(OffscreenContext &ctx, int width, int height) ctx.fbo = NULL; } - void glewCheck() { #ifdef DEBUG cerr << "GLEW version " << glewGetString(GLEW_VERSION) << "\n"; cerr << (const char *)glGetString(GL_RENDERER) << "(" << (const char *)glGetString(GL_VENDOR) << ")\n" << "OpenGL version " << (const char *)glGetString(GL_VERSION) << "\n"; - cerr << "Extensions: " << (const char *)glGetString(GL_EXTENSIONS) << "\n"; + //cerr << "Extensions: " << (const char *)glGetString(GL_EXTENSIONS) << "\n"; if (GLEW_ARB_framebuffer_object) { cerr << "ARB_FBO supported\n"; @@ -57,46 +63,81 @@ void glewCheck() { LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { - return DefWindowProc( hwnd, message, wparam, lparam ); + return DefWindowProc( hwnd, message, wparam, lparam ); } bool create_wgl_dummy_context(OffscreenContext &ctx) { - // create window - - HINSTANCE inst = GetModuleHandle(0); - WNDCLASS wc; - ZeroMemory( &wc, sizeof( wc ) ); - wc.style = CS_OWNDC; - wc.lpfnWndProc = WndProc; - wc.hInstance = inst; - wc.lpszClassName = "OpenSCAD"; - RegisterClass( &wc ); - - HWND window = CreateWindow( "OpenSCAD", "OpenSCAD", - WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, - 0, 0, 256, 256, NULL, NULL, inst, NULL ); - + // this call alters ctx->window and ctx->openGLContext + // and ctx->dev_context if successfull + // create window + + HINSTANCE inst = GetModuleHandle(0); + WNDCLASS wc; + ZeroMemory( &wc, sizeof( wc ) ); + wc.style = CS_OWNDC; + wc.lpfnWndProc = WndProc; + wc.hInstance = inst; + wc.lpszClassName = "OpenSCAD"; + RegisterClass( &wc ); - // create WGL context, make current - - PIXELFORMATDESCRIPTOR pixformat; - int chosenformat; - HDC dev_context = GetDC( window ); - ZeroMemory( &pixformat, sizeof( pixformat ) ); - pixformat.nSize = sizeof( pixformat ); - pixformat.nVersion = 1; - pixformat.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - pixformat.iPixelType = PFD_TYPE_RGBA; - pixformat.cColorBits = 24; - pixformat.cDepthBits = 16; - pixformat.iLayerType = PFD_MAIN_PLANE; - chosenformat = ChoosePixelFormat( dev_context, &pixformat ); - SetPixelFormat( dev_context, chosenformat, &pixformat ); - HGLRC gl_render_context = wglCreateContext( dev_context ); - wglMakeCurrent( dev_context, gl_render_context ); - - return true; + HWND window = CreateWindow( "OpenSCAD", "OpenSCAD", + WS_CAPTION | WS_POPUPWINDOW, //| WS_VISIBLE, + 0, 0, ctx.width, ctx.height, NULL, NULL, inst, NULL ); + + if ( window==NULL ) { + cerr << "MS GDI - CreateWindow failed\n"; + return false; + } + + // create WGL context, make current + + PIXELFORMATDESCRIPTOR pixformat; + int chosenformat; + HDC dev_context = GetDC( window ); + if ( dev_context == NULL ) { + cerr << "MS GDI - GetDC failed\n"; + return false; + } + + ZeroMemory( &pixformat, sizeof( pixformat ) ); + pixformat.nSize = sizeof( pixformat ); + pixformat.nVersion = 1; + pixformat.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pixformat.iPixelType = PFD_TYPE_RGBA; + pixformat.cColorBits = 24; + pixformat.cDepthBits = 16; + pixformat.iLayerType = PFD_MAIN_PLANE; + chosenformat = ChoosePixelFormat( dev_context, &pixformat ); + if (chosenformat==0) { + cerr << "MS GDI - ChoosePixelFormat failed\n"; + return false; + } + + bool spfok = SetPixelFormat( dev_context, chosenformat, &pixformat ); + if (!spfok) { + cerr << "MS GDI - SetPixelFormat failed\n"; + return false; + } + + HGLRC gl_render_context = wglCreateContext( dev_context ); + if ( gl_render_context == NULL ) { + cerr << "MS WGL - wglCreateContext failed\n"; + ReleaseDC( ctx.window, ctx.dev_context ); + return false; + } + + bool mcok = wglMakeCurrent( dev_context, gl_render_context ); + if (!mcok) { + cerr << "MS GDI - wglMakeCurrent failed\n"; + return false; + } + + ctx.window = window; + ctx.dev_context = dev_context; + ctx.openGLContext = gl_render_context; + + return true; } @@ -105,22 +146,29 @@ OffscreenContext *create_offscreen_context(int w, int h) OffscreenContext *ctx = new OffscreenContext; offscreen_context_init( *ctx, w, h ); - // before an FBO can be setup, a WGL context must be created - // this call alters ctx->window and ctx->openGLContext + // Before an FBO can be setup, a WGL context must be created. + // This call alters ctx->window and ctx->openGLContext // and ctx->dev_context if successfull if (!create_wgl_dummy_context( *ctx )) { + cerr << "wgl dummy fail\n"; + fflush(stderr); return NULL; } - glewInit(); //must come after Context creation and before FBO calls. + GLenum err = glewInit(); // must come after Context creation and before FBO calls. + if (GLEW_OK != err) { + cerr << "Unable to init GLEW: " << glewGetErrorString(err) << "\n"; + fflush(stderr); + return NULL; + } glewCheck(); ctx->fbo = fbo_new(); if (!fbo_init(ctx->fbo, w, h)) { + cerr << "fbo didn't init\n"; return NULL; } - ctx = NULL; return ctx; } diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index d43e810..c72bc30 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -91,12 +91,13 @@ extern double getBoundingRadius(BoundingBox bbox); int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.png>\n", argv[0]); exit(1); } const char *filename = argv[1]; + const char *outfile = argv[2]; initialize_builtin_functions(); initialize_builtin_modules(); @@ -238,7 +239,7 @@ int main(int argc, char **argv) csgInfo.glview->setRenderer(&cgalRenderer); csgInfo.glview->paintGL(); - csgInfo.glview->save("/dev/stdout"); + csgInfo.glview->save(outfile); destroy_builtin_functions(); destroy_builtin_modules(); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 80b9b9c..643a64f 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -47,6 +47,7 @@ #include <assert.h> #include <iostream> #include <sstream> +#include <fstream> using std::cout; @@ -57,12 +58,13 @@ QString librarydir; int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]); exit(1); } const char *filename = argv[1]; + const char *outfilename = argv[2]; int rc = 0; @@ -161,12 +163,15 @@ 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"; + std::ofstream outfile; + outfile.open(outfilename); if (root_term) { - cout << root_term->dump() << "\n"; + outfile << root_term->dump() << "\n"; } else { - cout << "No top-level CSG object\n"; + outfile << "No top-level CSG object\n"; } + outfile.close(); destroy_builtin_functions(); destroy_builtin_modules(); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 11ff695..e87558d 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -69,12 +69,13 @@ AbstractNode *find_root_tag(AbstractNode *n) int csgtestcore(int argc, char *argv[], test_type_e test_type) { - if (argc < 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.png>\n", argv[0]); exit(1); } std::string filename(argv[1]); + std::string outfile(argv[2]); initialize_builtin_functions(); initialize_builtin_modules(); @@ -244,7 +245,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.glview->paintGL(); - csgInfo.glview->save("/dev/stdout"); + csgInfo.glview->save(outfile.c_str()); destroy_builtin_functions(); destroy_builtin_modules(); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 6badcfb..21ebf6a 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -45,6 +45,7 @@ #include <assert.h> #include <iostream> #include <sstream> +#include <fstream> std::string commandline_commands; QString currentdir; @@ -60,12 +61,13 @@ void csgTree(CSGTextCache &cache, const AbstractNode &root) int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]); exit(1); } const char *filename = argv[1]; + const char *outfilename = argv[2]; int rc = 0; @@ -151,7 +153,10 @@ int main(int argc, char **argv) csgTree(csgcache, *root_node); // std::cout << tree.getString(*root_node) << "\n"; - std::cout << csgcache[*root_node] << "\n"; + std::ofstream outfile; + outfile.open(outfilename); + outfile << csgcache[*root_node] << "\n"; + outfile.close(); destroy_builtin_functions(); destroy_builtin_modules(); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index e953689..3782446 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -45,6 +45,7 @@ #include <assert.h> #include <iostream> #include <sstream> +#include <fstream> using std::string; @@ -55,12 +56,13 @@ QString librarydir; int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]); exit(1); } const char *filename = argv[1]; + const char *outfilename = argv[2]; int rc = 0; @@ -148,7 +150,10 @@ int main(int argc, char **argv) string dumpstdstr_cached = tree.getString(*root_node); assert(dumpstdstr == dumpstdstr_cached); - std::cout << dumpstdstr << "\n"; + std::ofstream outfile; + outfile.open(outfilename); + outfile << dumpstdstr << "\n"; + outfile.close(); destroy_builtin_functions(); destroy_builtin_modules(); diff --git a/tests/imageutils-lodepng.cc b/tests/imageutils-lodepng.cc index 8636fa4..8460d9e 100644 --- a/tests/imageutils-lodepng.cc +++ b/tests/imageutils-lodepng.cc @@ -10,7 +10,8 @@ bool write_png(const char *filename, unsigned char *pixels, int width, int heigh unsigned char *dataout = (unsigned char *)malloc(width*height*4); LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8); //LodePNG_saveFile(dataout, dataout_size, "blah2.png"); - FILE *f = fopen(filename, "w"); + + FILE *f = fopen(filename, "wb"); if (!f) { free(dataout); return false; diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py index 3ac41dd..f4b9138 100755 --- a/tests/test_cmdline_tool.py +++ b/tests/test_cmdline_tool.py @@ -57,6 +57,7 @@ def execute_and_redirect(cmd, params, outfile): return retval def get_normalized_text(filename): + print >> sys.stderr, "debug normalize" , filename text = open(filename).read() return text.strip("\r\n").replace("\r\n", "\n") + "\n" @@ -70,10 +71,10 @@ def compare_default(resultfilename): return True def append_html_output(expectedfilename, resultfilename): - # if html directory & file not there, create them - # copy expected filename and result filename to dir - # append html to show differences - # dump platform.platform() + # 1 if html directory & file not there, create them + # 2 copy expected filename image and result filename image to dir + # 3 append html to show differences + # 4 dump platform.platform() expectedimg = os.path.basename(expectedfilename) resultimg = os.path.basename(resultfilename) template = ''' @@ -133,6 +134,7 @@ def run_test(testname, cmd, args): outputdir = os.path.join(os.getcwd(), cmdname + "-output") actualfilename = os.path.join(outputdir, testname + "-actual." + options.suffix) + actualfilename = os.path.normpath(actualfilename) if options.generate: if not os.path.exists(expecteddir): os.makedirs(expecteddir) @@ -140,9 +142,12 @@ def run_test(testname, cmd, args): else: if not os.path.exists(outputdir): os.makedirs(outputdir) outputname = actualfilename + outputname = os.path.normpath( outputname ) + outfile = open(outputname, "wb") try: - proc = subprocess.Popen([cmd] + args, stdout=outfile, stderr=subprocess.PIPE) + print >> sys.stderr, "debug ", [cmd], args, [outputname] + proc = subprocess.Popen([cmd] + args + [outputname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) errtext = proc.communicate()[1] if errtext != None and len(errtext) > 0: print >> sys.stderr, "Error output: " + errtext |