Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Symbian OS Explained - Effective C++ Programming For Smartphones (2005) [eng].pdf
Скачиваний:
60
Добавлен:
16.08.2013
Размер:
2.62 Mб
Скачать

276

DEBUG MACROS AND TEST CLASSES

I’ve not illustrated the use of RTest::Printf() and RTest::Getch() in the example code, but they can be used in much the way you would expect, to print to the display/debug output and wait for an input character respectively.

Class RTest is useful for test code that runs in a simple console, and can be used to check conditional expressions, raising a panic if a result is false. If you want to use the cleanup stack in console-based test code, or link against a component which does so, you will need to create a cleanup stack as discussed in Chapter 3. If you write or link against any code which uses active objects, you will need to create an active scheduler, as described in Chapters 8 and 9.

17.4Summary

Memory is a limited resource on Symbian OS and must be managed carefully to ensure it is not wasted by memory leaks. In addition, an application must handle gracefully any exceptional conditions arising when memory resources are exhausted. Symbian OS provides a set of debug-only macros that can be added directly to code to check both that it is well-behaved and that it copes with out-of-memory conditions. This chapter described how to use the macros, and how to debug your code to find the root cause when the heap-checking code panics to indicate a heap inconsistency.

The chapter also discussed how to use the object invariance macro that Symbian OS provides to verify the state of an object. The macro can be added to any class and offers the opportunity to write customized debug state-checking for objects of the class.

Finally, the chapter described the RTest class, which is useful for console-based test code. The API for RTest can be found in e32test.h and is not published, so it may be changed without notice but, since it is used internally by Symbian OS test code, it is unlikely to be removed. RTest can be used to run test code in a console, and display the results to the screen, debug output and log file. The class also provides a means of testing return values or statements, which behaves rather like an assertion and panics when the check fails.