Code Coverage Of Unit Tests Using Qt 5 On macOS

Qt Library

Qt Framework

I was inspired while watching a talk by Kevin Ottens about refactoring OpenGL code in Qt to take a look at gcov & lcov. gcov is used to analyze code coverage – which lines of code have actually been executed while running an application. lcov is a tool that can produce HTML reports from the gcov output.

If you have a suite of unit tests that you run on your code, you can use these tools to see which the lines of code are covered by your tests and which are not.

I couldn’t find a decent primer on how to set this up properly for my Qt projects on macOS so I could run it from Qt Creator, so I thought I’d write up how I did it.

Continue reading

Cppcheck

Cppcheck is an open source cool tool by Daniel Marjamäki used to statically analyse C/C++ code for errors, questionable code, and style. I’ve been tracking it for a number of months and, while it is still in active development, it is already a very useful tool. There are command line and GUI versions available for several platforms.

The Cppcheck wiki page gives a lot more information about it, and lists a couple of hundred checks that are performed on your code.

A git repository is available which makes it easy to keep up-to-date with the latest developments. The source also includes a Qt-based GUI which is quite straightforward to compile using Qt Creator. The GUI is functional, but could use a little bit of work to make it more friendly. In order to view error or warning in the source, for example, Cppcheck requires an external program. It really ought to show you the code in context in the main window, allowing you to correct things within the application.

Continue reading

ImageOptim

ImageOptim is a cool tool by Kornel Lesiński for Mac OS X used to optimize images. Why would I want to do that you ask? It reduces the size of images so they take up less disk space. This means if you are working on a website, it will load a little faster for your users. If you are working on games, it can reduce the amount of data being sent to the GPU which can speed up the loading of textures [make sure you are using lossless compression of course].

ImageOptim is a front-end to several image optimizing tools including AdvPNG, OptiPNG, Pngcrush, JpegOptim, jpegtran, and Gifsicle. It works on PNG, JPG, and GIF images.

ImageOptim Example

ImageOptim Example

Photoshop is especially bad at creating small files when it saves them. It’s incredible the number of images on the web that can be optimized to save everyone time and money. Anyone running a website should consider using ImageOptim or a tool like it on their images.