From c35d5af1c2845ad072525e69f3f7be01994bcc2f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 4 Oct 2009 19:04:59 +0000 Subject: Purge test suite and C++ wrapper - for now. --- tests/Makefile.am | 44 ----------- tests/error.cpp | 33 -------- tests/gl.cpp | 79 -------------------- tests/png.cpp | 65 ---------------- tests/tests.cpp | 220 ------------------------------------------------------ tests/tests.hpp | 61 --------------- tests/warning.cpp | 54 -------------- 7 files changed, 556 deletions(-) delete mode 100644 tests/Makefile.am delete mode 100644 tests/error.cpp delete mode 100644 tests/gl.cpp delete mode 100644 tests/png.cpp delete mode 100644 tests/tests.cpp delete mode 100644 tests/tests.hpp delete mode 100644 tests/warning.cpp (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index e26b181..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -########################################################################### -## Copyright (C) 2009 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build Suite is free software; you can redistribute it ## -## and/or modify it under the terms of the GNU General Public License as ## -## published by the Free Software Foundation; either version 3 of the ## -## License, or (at your option) any later version. ## -## ## -## The Dimension Build Suite is distributed in the hope that it will be ## -## useful, but WITHOUT ANY WARRANTY; without even the implied warranty ## -## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## -## General Public License for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program. If not, see . ## -########################################################################### - -check_LTLIBRARIES = libdimension-tests.la -check_PROGRAMS = warning-test \ - error-test \ - png-test \ - gl-test -TESTS = $(check_PROGRAMS) -XFAIL_TESTS = error-test - -INCLUDES = -I../libdimension -I../libdimensionxx - -libdimension_tests_la_SOURCES = tests.hpp \ - tests.cpp -libdimension_tests_la_LIBADD = ../libdimensionxx/libdimensionxx.la - -warning_test_SOURCES = warning.cpp -warning_test_LDADD = ./libdimension-tests.la - -error_test_SOURCES = error.cpp -error_test_LDADD = ./libdimension-tests.la - -png_test_SOURCES = png.cpp -png_test_LDADD = ./libdimension-tests.la - -gl_test_SOURCES = gl.cpp -gl_test_LDADD = ./libdimension-tests.la diff --git a/tests/error.cpp b/tests/error.cpp deleted file mode 100644 index 705e013..0000000 --- a/tests/error.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -/* Make sure that errors terminate us - this test should fail */ - -#include "tests.hpp" - -int -main() -{ - using namespace Dimension; - - resilience(SEVERITY_LOW); - dmnsn_error(SEVERITY_LOW, "This error is expected."); - - return EXIT_SUCCESS; -} diff --git a/tests/gl.cpp b/tests/gl.cpp deleted file mode 100644 index c01859b..0000000 --- a/tests/gl.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -#include "tests.hpp" -#include -#include - -int -main() { - using namespace Dimension; - - // Set the resilience low for tests - resilience(SEVERITY_LOW); - - // Create the default test scene - Scene scene = Tests::default_scene(); - - // Create a glX window - Tests::Display display(scene.canvas()); - - { - Raytracer raytracer(scene); - GL_Writer writer(scene.canvas()); - - // Render the scene - Progress progress = raytracer.render_async(); - - std::cout << "Raytracing scene: "; - Progress barprogress = Tests::progressbar_async(std::cout, progress); - - // Display the scene as it's rendered - while (progress.progress() < 1.0) { - writer.write(); - display.flush(); - } - - barprogress.finish(); - std::cout << std::endl; - - // Make sure we show the completed rendering - progress.finish(); - writer.write(); - display.flush(); - } - - // Pause for a second - sleep(1); - - // Read the canvas back from the GL buffer - GL_Reader reader; - Canvas canvas - = reader.read(0, 0, scene.canvas().width(), scene.canvas().height()); - - // And write it again - GL_Writer writer(canvas); - writer.write(); - display.flush(); - - // Pause for a second - sleep(1); - - return EXIT_SUCCESS; -} diff --git a/tests/png.cpp b/tests/png.cpp deleted file mode 100644 index 92a48d1..0000000 --- a/tests/png.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -#include "tests.hpp" -#include -#include - -int -main() { - using namespace Dimension; - - // Set the resilience low for tests - resilience(SEVERITY_LOW); - - // Perform the rendering - { - // Get the default test scene - Scene scene = Tests::default_scene(); - - std::ofstream ofile("pngxx1.png"); - PNG_Writer writer(scene.canvas(), ofile); - - // Render the scene - Raytracer raytracer(scene); - Progress rprogress = raytracer.render_async(); - std::cout << "Raytracing scene: " << rprogress << std::endl; - rprogress.finish(); - - // Write the canvas - Progress oprogress = writer.write_async(); - std::cout << "Writing PNG file: " << oprogress << std::endl; - } - - // Now test PNG import/export - { - std::ifstream ifile("pngxx1.png"); - PNG_Reader reader(ifile); - Progress iprogress = reader.read_async(); - std::cout << "Reading PNG file: " << iprogress << std::endl; - - Canvas canvas = PNG_Reader::finish(iprogress); - std::ofstream ofile("pngxx2.png"); - PNG_Writer writer(canvas, ofile); - Progress oprogress = writer.write_async(); - std::cout << "Writing PNG file: " << oprogress << std::endl; - } - - return EXIT_SUCCESS; -} diff --git a/tests/tests.cpp b/tests/tests.cpp deleted file mode 100644 index 002adbb..0000000 --- a/tests/tests.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -#include "tests.hpp" - -namespace Dimension -{ - namespace Tests - { - Scene - default_scene() - { - // Canvas - Canvas canvas(768, 480); - - // Camera - Perspective_Camera camera; - camera.trans( - Matrix::rotation(Vector(0.0, 1.0, 0.0)) - * Matrix::translation(Vector(0.0, 0.0, -4.0)) - * Matrix::scale( - Vector(static_cast(canvas.width())/canvas.height(), - 1.0, - 1.0) - ) - ); - - // Scene - Scene scene(camera, canvas); - - // Objects in scene - - Sphere sphere; - sphere.trans(inverse(Matrix::scale(Vector(1.25, 1.25, 1.25)))); - scene.objects().push(sphere); - - Cube cube; - cube.trans(inverse(Matrix::rotation(Vector(0.75, 0.0, 0.0)))); - scene.objects().push(cube); - - // Background color - Color background = sRGB(0.0, 0.1, 0.25); - background.filter(0.1); - scene.background(background); - - return scene; - } - - namespace - { - /* XIfEvent callback */ - Bool - WaitForNotify(::Display *d, XEvent *e, char *arg) - { - return (e->type == MapNotify) && (e->xmap.window == (Window)arg); - } - } - - Display::Display(const Canvas& canvas) - { - int attributeList[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - None - }; - XVisualInfo *vi; - XSetWindowAttributes swa; - - /* Get an X connection */ - m_dpy = XOpenDisplay(0); - if (!m_dpy) { - throw Dimension_Error("Couldn't create display."); - } - - /* Get an appropriate visual */ - vi = glXChooseVisual(m_dpy, DefaultScreen(m_dpy), - attributeList); - if (!vi) { - XCloseDisplay(m_dpy); - throw Dimension_Error("Couldn't create display."); - } - - /* Create a GLX context */ - m_cx = glXCreateContext(m_dpy, vi, 0, GL_TRUE); - if (!m_cx) { - XCloseDisplay(m_dpy); - throw Dimension_Error("Couldn't create display."); - } - - /* Create a color map */ - m_cmap = XCreateColormap(m_dpy, - RootWindow(m_dpy, vi->screen), - vi->visual, AllocNone); - if (!m_cmap) { - glXDestroyContext(m_dpy, m_cx); - XCloseDisplay(m_dpy); - throw Dimension_Error("Couldn't create display."); - } - - /* Create a window */ - swa.colormap = m_cmap; - swa.border_pixel = 0; - swa.event_mask = StructureNotifyMask; - m_win = XCreateWindow(m_dpy, - RootWindow(m_dpy, vi->screen), - 0, 0, canvas.width(), canvas.height(), - 0, vi->depth, InputOutput, vi->visual, - CWBorderPixel|CWColormap|CWEventMask, &swa); - if (!m_win) { - XFreeColormap(m_dpy, m_cmap); - glXDestroyContext(m_dpy, m_cx); - XCloseDisplay(m_dpy); - throw Dimension_Error("Couldn't create display."); - } - - XStoreName(m_dpy, m_win, "glX"); - - XMapWindow(m_dpy, m_win); - XIfEvent(m_dpy, &m_event, &WaitForNotify, (char*)m_win); - - /* Connect the context to the window */ - glXMakeCurrent(m_dpy, m_win, m_cx); - } - - Display::~Display() - { - XDestroyWindow(m_dpy, m_win); - XFreeColormap(m_dpy, m_cmap); - glXDestroyContext(m_dpy, m_cx); - XCloseDisplay(m_dpy); - } - - void - Display::flush() - { - glFlush(); - glXSwapBuffers(m_dpy, m_win); - } - - namespace - { - struct Progressbar_Payload - { - public: - std::ostream* ostr; - const Progress* progress; - }; - - void * - progressbar_thread(void *ptr) - { - Progressbar_Payload* payload - = reinterpret_cast(ptr); - - *payload->ostr << *payload->progress; - - int* ret = static_cast(std::malloc(sizeof(int))); - if (ret) { - *ret = 0; - } - return ret; - } - } - - Progress progressbar_async(std::ostream& ostr, - const Dimension::Progress& progress) - { - dmnsn_progress* barprogress = dmnsn_new_progress(); - if (!barprogress) { - throw Dimension_Error("Couldn't allocate progress object."); - } - - Progressbar_Payload* payload = new Progressbar_Payload; - payload->ostr = &ostr; - payload->progress = &progress; - - /* Create the worker thread */ - if (pthread_create(&barprogress->thread, NULL, &progressbar_thread, - reinterpret_cast(payload)) != 0) - { - throw Dimension_Error("Couldn't create background thread."); - } - - return Progress(barprogress); - } - } - - // Print a progress bar of the progress of `progress' - std::ostream& - operator<<(std::ostream& ostr, const Dimension::Progress& progress) - { - const unsigned int increments = 32; - - ostr << "|" << std::flush; - for (unsigned int i = 0; i < increments; ++i) { - progress.wait(static_cast(i + 1)/increments); - ostr << "=" << std::flush; - } - return ostr << "|" << std::flush; - } -} diff --git a/tests/tests.hpp b/tests/tests.hpp deleted file mode 100644 index 437bd36..0000000 --- a/tests/tests.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -#ifndef TESTSXX_HPP -#define TESTSXX_HPP - -#include "../libdimensionxx/dimensionxx.hpp" -#include -#include -#include - -namespace Dimension -{ - namespace Tests - { - // Helper to return a basic scene - Scene default_scene(); - - // Display abstraction - class Display - { - public: - Display(const Canvas& canvas); - ~Display(); - - void flush(); - - private: - ::Display *m_dpy; - Window m_win; - Colormap m_cmap; - GLXContext m_cx; - XEvent m_event; - }; - - Progress progressbar_async(std::ostream& ostr, - const Dimension::Progress& progress); - } - - // Print a progress bar of the progress of `progress' - std::ostream& operator<<(std::ostream& ostr, - const Dimension::Progress& progress); -} - -#endif // TESTSXX_HPP diff --git a/tests/warning.cpp b/tests/warning.cpp deleted file mode 100644 index 9d74e9d..0000000 --- a/tests/warning.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009 Tavian Barnes * - * * - * This file is part of The Dimension Test Suite. * - * * - * The Dimension Test Suite is free software; you can redistribute it * - * and/or modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Test Suite is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -/* Make sure warnings don't kill us - this test should pass */ - -#include "tests.hpp" - -int -main() -{ - using namespace Dimension; - - if (resilience() != SEVERITY_MEDIUM) { - return EXIT_FAILURE; - } - - resilience(SEVERITY_LOW); - if (resilience() != SEVERITY_LOW) { - return EXIT_FAILURE; - } - - resilience(SEVERITY_MEDIUM); - if (resilience() != SEVERITY_MEDIUM) { - return EXIT_FAILURE; - } - - dmnsn_error(SEVERITY_LOW, "This warning is expected."); - - resilience(SEVERITY_HIGH); - if (resilience() != SEVERITY_HIGH) { - return EXIT_FAILURE; - } - - dmnsn_error(SEVERITY_LOW, "This warning is expected."); - dmnsn_error(SEVERITY_MEDIUM, "This warning is expected."); - - return EXIT_SUCCESS; -} -- cgit v1.2.3