<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Unit testing OpenGL applications</title>
	<atom:link href="http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/feed/" rel="self" type="application/rss+xml" />
	<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/</link>
	<description>A technical blog from Daniel Rákos (aka aqnuep)</description>
	<lastBuildDate>Thu, 26 Aug 2010 18:01:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Unit testing</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-350</link>
		<dc:creator>Unit testing</dc:creator>
		<pubDate>Sat, 31 Jul 2010 10:51:08 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-350</guid>
		<description>Really great information earlier i am bit skeptical of using testing in GL applications ,frankly i am not much aware of such GL platforms and very much confused in  debugging,but after getting through to this post and some very good comments now i am bit confident and definatley try my hands on GL applications</description>
		<content:encoded><![CDATA[<p>Really great information earlier i am bit skeptical of using testing in GL applications ,frankly i am not much aware of such GL platforms and very much confused in  debugging,but after getting through to this post and some very good comments now i am bit confident and definatley try my hands on GL applications</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Crawfis</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-123</link>
		<dc:creator>Roger Crawfis</dc:creator>
		<pubDate>Fri, 26 Mar 2010 22:20:11 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-123</guid>
		<description>Daniel Rakos wrote:
&gt; Your example of switching from vertex arrays to VBOs should happen like the following:

The &quot;should happen&quot; is the crux of the problem. Your Unit Testing is dictating the implementation. I would not create a VBO class or a Vertex Array class. I instead might have a Cube class that was using glBegin and now I want to change it to a vertex array.

This is just a bad way to do this.</description>
		<content:encoded><![CDATA[<p>Daniel Rakos wrote:<br />
&gt; Your example of switching from vertex arrays to VBOs should happen like the following:</p>
<p>The &#8220;should happen&#8221; is the crux of the problem. Your Unit Testing is dictating the implementation. I would not create a VBO class or a Vertex Array class. I instead might have a Cube class that was using glBegin and now I want to change it to a vertex array.</p>
<p>This is just a bad way to do this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Rákos</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-122</link>
		<dc:creator>Daniel Rákos</dc:creator>
		<pubDate>Thu, 25 Mar 2010 23:50:47 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-122</guid>
		<description>You are right from the point of difficulties regarding to refactoring and tight coupling between the test cases and the implementation. However, the purpose of this approach is to somehow ensure that the correct invocation orders happen.

Your example of switching from vertex arrays to VBOs should happen like the following:
- create the vertex array class and write the test cases for it to check correct OpenGL behavior
- think about how to introduce VBOs
- create abstract base class that vertex array and VBO inherit from
- create the VBO implementation with it&#039;s own unit test set
- use the abstract base class in other modules as type and use factory pattern or whatever seems to be convenient
- simulate the vertex array/VBO functionality with mocks when testing other classes, so you don&#039;t depend on any implementation details
Business logic shall always use abstract interfaces, not knowing the implementation details. For unit testing that particular vertex array/VBO class it is not a problem to have dependencies. Dependencies shall be avoided between modules and by using factory pattern and a mocking framework when doing unit test will solve the problem flawlessly.</description>
		<content:encoded><![CDATA[<p>You are right from the point of difficulties regarding to refactoring and tight coupling between the test cases and the implementation. However, the purpose of this approach is to somehow ensure that the correct invocation orders happen.</p>
<p>Your example of switching from vertex arrays to VBOs should happen like the following:<br />
- create the vertex array class and write the test cases for it to check correct OpenGL behavior<br />
- think about how to introduce VBOs<br />
- create abstract base class that vertex array and VBO inherit from<br />
- create the VBO implementation with it&#8217;s own unit test set<br />
- use the abstract base class in other modules as type and use factory pattern or whatever seems to be convenient<br />
- simulate the vertex array/VBO functionality with mocks when testing other classes, so you don&#8217;t depend on any implementation details<br />
Business logic shall always use abstract interfaces, not knowing the implementation details. For unit testing that particular vertex array/VBO class it is not a problem to have dependencies. Dependencies shall be avoided between modules and by using factory pattern and a mocking framework when doing unit test will solve the problem flawlessly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Crawfis</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-121</link>
		<dc:creator>Roger Crawfis</dc:creator>
		<pubDate>Thu, 25 Mar 2010 19:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-121</guid>
		<description>Interesting, but I would not encourage this approach. I would not even call this Unit Testing! It is more functional testing. The problem I have with it is that you are testing what you expect to be the implemnentation, allowing no freedom in how it is implemented. For all of my graphics applications, the constructor never makes any OpenGL calls. These are done lazily to ensure they are on the proper thread. So your simple example of the class Buffer would have a different test on my implementation than yours. If I decide to switch drawing from vertex arrays to VBO&#039;s I have to change my tests.

The purpose of the tests to allow the implementations to be refactored / enhanced without too much worry about breaking the system. This seems to fail for your mock objects. There is a fundamental difference between say testing a encapsulated getter / setter pair in a class and the internal (non-public) order and set of OpenGL calls made in the implementation. If I change the getter, I can change the setter at the same time and the tests will still pass, regardless of what I did.

In summary, I think testing in this way is not a good idea and should be avoided. Sorry.

Roger</description>
		<content:encoded><![CDATA[<p>Interesting, but I would not encourage this approach. I would not even call this Unit Testing! It is more functional testing. The problem I have with it is that you are testing what you expect to be the implemnentation, allowing no freedom in how it is implemented. For all of my graphics applications, the constructor never makes any OpenGL calls. These are done lazily to ensure they are on the proper thread. So your simple example of the class Buffer would have a different test on my implementation than yours. If I decide to switch drawing from vertex arrays to VBO&#8217;s I have to change my tests.</p>
<p>The purpose of the tests to allow the implementations to be refactored / enhanced without too much worry about breaking the system. This seems to fail for your mock objects. There is a fundamental difference between say testing a encapsulated getter / setter pair in a class and the internal (non-public) order and set of OpenGL calls made in the implementation. If I change the getter, I can change the setter at the same time and the tests will still pass, regardless of what I did.</p>
<p>In summary, I think testing in this way is not a good idea and should be avoided. Sorry.</p>
<p>Roger</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Rákos</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-101</link>
		<dc:creator>Daniel Rákos</dc:creator>
		<pubDate>Fri, 12 Mar 2010 13:28:19 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-101</guid>
		<description>vj, your way of doing the test is the best way, however, it needs that all of your code should use the provided static class interface instead of the original OpenGL API functions, but if you start from straight the beginning then it is even better. Still, if you execute the actual OpenGL functions also in case of unit testing, then it&#039;s more like an integration test. Anyway, your way of doing it is still nice in my opinion.

About comparing rendering results, well yes, it is not suitable for unit testing but can be a valuable tool in higher level testing mechanisms.</description>
		<content:encoded><![CDATA[<p>vj, your way of doing the test is the best way, however, it needs that all of your code should use the provided static class interface instead of the original OpenGL API functions, but if you start from straight the beginning then it is even better. Still, if you execute the actual OpenGL functions also in case of unit testing, then it&#8217;s more like an integration test. Anyway, your way of doing it is still nice in my opinion.</p>
<p>About comparing rendering results, well yes, it is not suitable for unit testing but can be a valuable tool in higher level testing mechanisms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vj</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-100</link>
		<dc:creator>vj</dc:creator>
		<pubDate>Fri, 12 Mar 2010 08:51:10 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-100</guid>
		<description>Forgot to mention : I tried the first approach, but with the off screen rendering, and comparing, but creating such unit tests is really hard and slow. And it can cause problems and wrong results if the unit tests are run with valgrind to check the memory access.</description>
		<content:encoded><![CDATA[<p>Forgot to mention : I tried the first approach, but with the off screen rendering, and comparing, but creating such unit tests is really hard and slow. And it can cause problems and wrong results if the unit tests are run with valgrind to check the memory access.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vj</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-99</link>
		<dc:creator>vj</dc:creator>
		<pubDate>Fri, 12 Mar 2010 08:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-99</guid>
		<description>I am doing something similar to test my OpenGL code. Instead of introducing mock functions, I am introducint mock objects as template parameters. For example:

template 
class render
{
  public:
    void doRendering()
    {
        OpenGLApi::glBegin( GL_POINT );
           // vertex, texture, etc calls
        OpenGLApi::glEnd();
    }
};

For the real code, I have a class which just forward calls to the opengl functions, and in the unit tests I am checking the execution order (collecting them to the stringstream).</description>
		<content:encoded><![CDATA[<p>I am doing something similar to test my OpenGL code. Instead of introducing mock functions, I am introducint mock objects as template parameters. For example:</p>
<p>template<br />
class render<br />
{<br />
  public:<br />
    void doRendering()<br />
    {<br />
        OpenGLApi::glBegin( GL_POINT );<br />
           // vertex, texture, etc calls<br />
        OpenGLApi::glEnd();<br />
    }<br />
};</p>
<p>For the real code, I have a class which just forward calls to the opengl functions, and in the unit tests I am checking the execution order (collecting them to the stringstream).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iPhone ringtone maker</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-94</link>
		<dc:creator>iPhone ringtone maker</dc:creator>
		<pubDate>Mon, 08 Mar 2010 21:28:01 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-94</guid>
		<description>Obviously you know a lot about it.  I have been searching for this for a long time.</description>
		<content:encoded><![CDATA[<p>Obviously you know a lot about it.  I have been searching for this for a long time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Rákos</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-80</link>
		<dc:creator>Daniel Rákos</dc:creator>
		<pubDate>Fri, 05 Mar 2010 15:47:32 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-80</guid>
		<description>&lt;blockquote&gt;My point was that solution #1 – that you’ve actually referred as “naive”, “slow” and “expensive”, etc – is an important topic for several scientific reserches...&lt;/blockquote&gt;
I was saying it is a &quot;naive&quot; solution for unit testing as it wouldn&#039;t be real unit testing not talked about functional testing...
&lt;blockquote&gt;By the way now you keep saying that unit testing is for the early stage of development. Well, your OpenGL-based code mostly wont render anything in the early stage where you want to detect typing errors and such – in this case i don’t even see the point of mentioning solution #1.&lt;/blockquote&gt;
Yes, you are right at this point. Mentioning solution #1 and actually the whole flow of finding a good solution is for the purpose of showing what wouldn&#039;t be a suitable solution for unit testing and the reasons behind why we would like to take another step to find one. It is not for actual use, just illustrates the train of thought...

It is not easy to not take your posts as offense as we already heavily discussed about the topic with Chris (see above) so that checking for actual correct behavior on target hardware is a totally different story.

&lt;blockquote&gt;Testing code that does rendering without letting to do it’s job is like testing a car’s engine without even igniting it&lt;/blockquote&gt;
I don&#039;t agree with this as think about a complex class that invokes OpenGL function calls several times. How would you test if this class does exactly what it has to without having to put it together with the whole system? You have to mock out the OpenGL API anyway or you choose to setup a working OpenGL context and environment for your class but then if a problem pops up it is difficult to decide whether the problem is in the environment setup or in the actual class you would like to test. Also, this makes your code tightly coupled with the environment setup code and that can heavily affect the maintenance costs of the testing environment.</description>
		<content:encoded><![CDATA[<blockquote><p>My point was that solution #1 – that you’ve actually referred as “naive”, “slow” and “expensive”, etc – is an important topic for several scientific reserches&#8230;</p></blockquote>
<p>I was saying it is a &#8220;naive&#8221; solution for unit testing as it wouldn&#8217;t be real unit testing not talked about functional testing&#8230;</p>
<blockquote><p>By the way now you keep saying that unit testing is for the early stage of development. Well, your OpenGL-based code mostly wont render anything in the early stage where you want to detect typing errors and such – in this case i don’t even see the point of mentioning solution #1.</p></blockquote>
<p>Yes, you are right at this point. Mentioning solution #1 and actually the whole flow of finding a good solution is for the purpose of showing what wouldn&#8217;t be a suitable solution for unit testing and the reasons behind why we would like to take another step to find one. It is not for actual use, just illustrates the train of thought&#8230;</p>
<p>It is not easy to not take your posts as offense as we already heavily discussed about the topic with Chris (see above) so that checking for actual correct behavior on target hardware is a totally different story.</p>
<blockquote><p>Testing code that does rendering without letting to do it’s job is like testing a car’s engine without even igniting it</p></blockquote>
<p>I don&#8217;t agree with this as think about a complex class that invokes OpenGL function calls several times. How would you test if this class does exactly what it has to without having to put it together with the whole system? You have to mock out the OpenGL API anyway or you choose to setup a working OpenGL context and environment for your class but then if a problem pops up it is difficult to decide whether the problem is in the environment setup or in the actual class you would like to test. Also, this makes your code tightly coupled with the environment setup code and that can heavily affect the maintenance costs of the testing environment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Rákos</title>
		<link>http://rastergrid.com/blog/2010/02/unit-testing-opengl-applications/comment-page-1/#comment-78</link>
		<dc:creator>Daniel Rákos</dc:creator>
		<pubDate>Fri, 05 Mar 2010 14:31:31 +0000</pubDate>
		<guid isPermaLink="false">http://rastergrid.com/blog/?p=182#comment-78</guid>
		<description>Yes, I never said that image comparison is not an important phase of the testing of a graphics application.
Usually you need several levels of testing. The one you are talking about is a kind of integration or functional test, but that does not mean that you don&#039;t need unit testing. Unit testing is for testing code level requirements and image comparison on actual hardware is for testing functional requirements. Two different levels, they are not against each other. Simply the feedback time is different.

In case of image comparison you actually test the real and full functionality, but the execution needs dedicated hardware and quite a lot of time as comparing images is not like comparing two integers. Unit testing is to provide limited verification capabilities that provide fast regression executions thus providing smaller feedback cycles and identification of a subset of possible problems in the early phase of the development.

Comparing two things that serve different purposes is simply non-sense.</description>
		<content:encoded><![CDATA[<p>Yes, I never said that image comparison is not an important phase of the testing of a graphics application.<br />
Usually you need several levels of testing. The one you are talking about is a kind of integration or functional test, but that does not mean that you don&#8217;t need unit testing. Unit testing is for testing code level requirements and image comparison on actual hardware is for testing functional requirements. Two different levels, they are not against each other. Simply the feedback time is different.</p>
<p>In case of image comparison you actually test the real and full functionality, but the execution needs dedicated hardware and quite a lot of time as comparing images is not like comparing two integers. Unit testing is to provide limited verification capabilities that provide fast regression executions thus providing smaller feedback cycles and identification of a subset of possible problems in the early phase of the development.</p>
<p>Comparing two things that serve different purposes is simply non-sense.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
