summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-07 04:22:49 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-07 04:22:49 +0000
commitd7b7b4b3391cf99ca63d8311eac3957df7a862ed (patch)
treeca25a171111abb0bfffc53fd61b01623b36992b6
parentc54af1b6644216335361e61e770037aca1527756 (diff)
downloaddimension-d7b7b4b3391cf99ca63d8311eac3957df7a862ed.tar.xz
New C++ dmnsn_display* wrapper for tests.
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/glxx.cpp4
-rw-r--r--tests/tests.h5
-rw-r--r--tests/testsxx.cpp42
-rw-r--r--tests/testsxx.hpp27
5 files changed, 66 insertions, 17 deletions
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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
+#ifndef TESTS_H
+#define TESTS_H
+
#include "../libdimension/dimension.h"
#include <GL/glx.h>
#include <GL/gl.h>
@@ -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<double>(i + 1)/increments);
- ostr << "=" << std::flush;
+ ostr << "|" << std::flush;
+ for (unsigned int i = 0; i < increments; ++i) {
+ progress.wait(static_cast<double>(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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
+#ifndef TESTSXX_HPP
+#define TESTSXX_HPP
+
+#include "tests.h"
#include "../libdimensionxx/dimensionxx.hpp"
#include <iostream>
-// 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