Carna  Version 3.0.1
TestFramebuffer.h
1 /*
2  * Copyright (C) 2010 - 2015 Leonid Kostrykin
3  *
4  * Chair of Medical Engineering (mediTEC)
5  * RWTH Aachen University
6  * Pauwelsstr. 20
7  * 52074 Aachen
8  * Germany
9  *
10  */
11 
12 #pragma once
13 
14 #include <Carna/Carna.h>
15 #include <Carna/base/Framebuffer.h>
16 #include <boost/current_function.hpp>
17 
18 class QImage;
19 
20 namespace Carna
21 {
22 
23 namespace testing
24 {
25 
26 
27 
28 // ----------------------------------------------------------------------------------
29 // TestFramebuffer
30 // ----------------------------------------------------------------------------------
31 
32 class TestFramebuffer
33 {
34 
35  const std::unique_ptr< QImage > frame;
36  const std::unique_ptr< base::Texture< 2 > > renderTexture;
37  const std::unique_ptr< base::Framebuffer > fbo;
38  const std::unique_ptr< base::Framebuffer::Binding > fboBinding;
39 
40  void grabFrame() const;
41 
42  double myEpsilon;
43 
44 public:
45 
46  const static double DEFAULT_EPSILON;
47 
48  base::GLContext& glContext;
49 
50  TestFramebuffer( base::GLContext& glContext, unsigned int width, unsigned int height );
51 
52  ~TestFramebuffer();
53 
54  unsigned int width() const;
55 
56  unsigned int height() const;
57 
58  void setEpsilon( double epsilon );
59 
60  double epsilon() const;
61 
62  void verifyFramebuffer( const std::string& signature ) const;
63 
64  void verifyFramebuffer
65  ( const std::string& expectedImageFilename
66  , const std::string& failureImageOutputFilename ) const;
67 
68 private:
69 
70  static bool areSimilar( const QImage&, const QImage&, double epsilon );
71 
72  static bool saveActualResult( const QImage& frame, const std::string& filename );
73 
74 }; // TestFramebuffer
75 
76 
77 
78 // ----------------------------------------------------------------------------------
79 // VERIFY_FRAMEBUFFER
80 // ----------------------------------------------------------------------------------
81 
82 #define VERIFY_FRAMEBUFFER( testFramebuffer ) \
83  ( testFramebuffer ).verifyFramebuffer( BOOST_CURRENT_FUNCTION );
84 
85 
86 
87 } // namespace testing
88 
89 } // namespace Carna
Defines Carna::base::Framebuffer.
T epsilon()
Defines the maximum difference of two objects treated as equal.
Definition: math.h:98