You should now test the actual engine class. Start by completing the following steps:
Include a
definition of the test target (CMapExampleSmsEngine) to the
source file (TestSource.cpp).
#include "cmapexamplesmsengine.h"
Add the test
target implementation to the project by uncommenting the line from the .mmp file:
SOURCE CMapExampleSMSEngine.cpp
Testability is not considered during implementation, so there can be
difficult dependencies, such as private fields, which make unit testing challenging.
In our case, there are messaging classes RSendAsMessage and RSendAs, which could be used, but simulating exceptions
would then be difficult.
The problem is solved by replacing the default library implementations
with your own. You can achieve this by not linking against existing libraries,
but by using your own implementations for the desired methods. We already
removed existing library definitions from the .mmp file and
thus the compiler will compile the source files, but the linker will refuse
to generate final binaries. Its errors look like this:
Undefined symbol: 'void RSendAsMessage::CreateL(class RSendAs &, class TUid) (?CreateL@RSendAsMessage@@QAEXAAVRSendAs@@VTUid@@@Z)'
Your task is to implement the methods with some functionality, which
satisfies the test needs. Simple empty implementations can be useful in the
first step. Methods are set to return NULL or other hard-coded default values.
Note that only methods that are used by the test target need to be implemented
(for example, there is no need to implement all 29 RSendAsMessage methods). Empty implementations similar
to the lines below can be used to satisfy linker:
void RSendAsMessage::CreateL(RSendAs &, TUid) {} TInt CMsvStore::HasBodyTextL(void) const { return KErrNone; } CMsvStore * CMsvEntry::ReadStoreL(void) { return NULL; }
When all missing methods have been implemented, the target compiles and links. The tests can be run and no errors should exist.