From d7b7b4b3391cf99ca63d8311eac3957df7a862ed Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 7 Jul 2009 04:22:49 +0000 Subject: New C++ dmnsn_display* wrapper for tests. --- tests/Makefile.am | 5 +++-- tests/glxx.cpp | 4 ++-- tests/tests.h | 5 +++++ tests/testsxx.cpp | 42 ++++++++++++++++++++++++++++++++---------- tests/testsxx.hpp | 27 ++++++++++++++++++++++++--- 5 files changed, 66 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 1f3f58c..9536052 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -38,7 +38,8 @@ libdimension_tests_la_LIBADD = ../libdimension/libdimension.la libdimensionxx_tests_la_SOURCES = testsxx.hpp \ testsxx.cpp -libdimensionxx_tests_la_LIBADD = ../libdimensionxx/libdimensionxx.la +libdimensionxx_tests_la_LIBADD = ./libdimension-tests.la \ + ../libdimensionxx/libdimensionxx.la warning_test_SOURCES = warning.c warning_test_LDADD = ./libdimension-tests.la @@ -62,4 +63,4 @@ gl_test_SOURCES = gl.c gl_test_LDADD = ./libdimension-tests.la glxx_test_SOURCES = glxx.cpp -glxx_test_LDADD = ./libdimension-tests.la ./libdimensionxx-tests.la +glxx_test_LDADD = ./libdimensionxx-tests.la diff --git a/tests/glxx.cpp b/tests/glxx.cpp index 1fc08c4..eb74209 100644 --- a/tests/glxx.cpp +++ b/tests/glxx.cpp @@ -60,7 +60,7 @@ main() { Raytracer raytracer(scene); GL_Drawer drawer(scene.canvas()); - dmnsn_display* display = dmnsn_new_display(scene.canvas().dmnsn()); + Dimension::Display display(scene.canvas()); // Render the scene for (unsigned int i = 0; i < 10; ++i) { @@ -69,7 +69,7 @@ main() { rprogress.finish(); drawer.draw(); - dmnsn_display_frame(display); + display.flush(); cube.trans(inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube.trans()); camera.trans(Matrix::rotation(Vector(0.0, -0.05, 0.0))*camera.trans()); diff --git a/tests/tests.h b/tests/tests.h index 30d4002..3ad81ec 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -17,6 +17,9 @@ * along with this program. If not, see . * *************************************************************************/ +#ifndef TESTS_H +#define TESTS_H + #include "../libdimension/dimension.h" #include #include @@ -62,3 +65,5 @@ void progressbar(const char *str, const dmnsn_progress *progress); #ifdef __cplusplus } #endif + +#endif /* TESTS_H */ diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp index 1247eee..f3dcca5 100644 --- a/tests/testsxx.cpp +++ b/tests/testsxx.cpp @@ -19,16 +19,38 @@ #include "testsxx.hpp" -// Print a progress bar of the progress of `progress' -std::ostream& -operator<<(std::ostream& ostr, const Dimension::Progress& progress) +namespace Dimension { - const unsigned int increments = 32; + Display::Display(const Canvas& canvas) + : m_display(dmnsn_new_display(canvas.dmnsn())) + { + if (!m_display) { + throw Dimension_Error("Couldn't create display."); + } + } + + Display::~Display() + { + dmnsn_delete_display(m_display); + } + + void + Display::flush() + { + dmnsn_display_frame(m_display); + } + + // 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; + 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; } - return ostr << "|" << std::flush; -} +} \ No newline at end of file diff --git a/tests/testsxx.hpp b/tests/testsxx.hpp index 45e944a..0e522ad 100644 --- a/tests/testsxx.hpp +++ b/tests/testsxx.hpp @@ -17,9 +17,30 @@ * along with this program. If not, see . * *************************************************************************/ +#ifndef TESTSXX_HPP +#define TESTSXX_HPP + +#include "tests.h" #include "../libdimensionxx/dimensionxx.hpp" #include -// Print a progress bar of the progress of `progress' -std::ostream& operator<<(std::ostream& ostr, - const Dimension::Progress& progress); +namespace Dimension +{ + class Display + { + public: + Display(const Canvas& canvas); + ~Display(); + + void flush(); + + private: + dmnsn_display* m_display; + }; + + // Print a progress bar of the progress of `progress' + std::ostream& operator<<(std::ostream& ostr, + const Dimension::Progress& progress); +} + +#endif // TESTSXX_HPP -- cgit v1.2.3