Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write tests for a graphics library?

I'm writing an OpenGL 2D library in Python. Everything is going great, and the codebase is steadily growing.

Now I want to write unit tests so I don't accidently bring in new bugs while fixing others/making new features. But I have no idea how those would work with graphics libraries.

Some things I thought of:

  • make reference screenshots and compare them with autogenerated screenshots in the tests
  • replace opengl calls with logging statements and compare logs

But both seem a bad idea. What is the common way to test graphics libraries?

like image 571
orlp Avatar asked Jan 25 '12 09:01

orlp


People also ask

How do I write a test in Visual Studio?

Add a Google Test project in Visual Studio 2022In Solution Explorer, right-click on the solution node and choose Add > New Project. Set Language to C++ and type test in the search box. From the results list, choose Google Test Project. Give the test project a name and choose OK.

Which library should be used to unit test?

The purpose of JUnit usually is to enable you to create unit tests.

How do you write unit tests in CPP?

Create a test project in Visual Studio 2022 Define and run unit tests inside one or more test projects. A test project creates a separate app that calls the code in your executable and reports on its behavior. Create test projects in the same solution as the code you want to test.


1 Answers

The approach I have used in the past for component level testing is:

  • Use a uniform colored background, with a few different colors.
  • Use uniform colored rectangles as graphical objects in tests (with a few different colors).
  • Place rectangles in known places where you can calculate their projected position in the image by yourself.
  • Calculate expected intensity of each channel of each pixel (background, foreground or mixture).
  • If you have a test scenario that results in non-round positions, use a non-accurate compare (e.g. correlation)
  • Use calculations to create expected result images.
  • Compare output images to expected result images.
  • If you have a blur effect, compare sum of intensity instead of discrete intensities.

As graham stated, internal units may be unit-testable free from graphics calls.

like image 161
Danny Varod Avatar answered Sep 23 '22 17:09

Danny Varod