January 2019
Intermediate to advanced
512 pages
14h 5m
English
A unit testing framework, such as Google Test, allows us to execute some code and verify that the results are what they should be. The results that we can look at include any variable or expression that we can access from the test program. That definition does not extend, for example, to the amount of memory that is currently in use. So, if we want to verify that resources are not disappearing, we have to count them.
In the following simple test fixture, we use a special resource class instead of, say, the int keyword. This class is instrumented to count how many objects of this type have been created, and how many are currently alive:
struct object_counter { static int count; static int all_count; object_counter() { ++count; ...