|
|
Classification: |
C++ |
Category: |
Errors & Error Handling |
Created: |
09/03/2002 |
Modified: |
09/10/2002 |
Number: |
FAQ-0815 |
Platform: |
Not Applicable |
|
Question: If I have a class that is documented as panicking on bad input, 'good' unit test code would check that it panics with the
documented panic code. How can I write an automated test script which checks this then continues with other tests?
Answer: The answer is to run the test on a separate thread and use User::SetJustIntime(EFalse) so that the thread only, not the whole emulator, is panicked. Here's a chunk of test code to demonstrate this.
LOCAL_C TInt IllegalPanicThing(TAny* aData) { // call the code which PANICS here
return 0; }
LOCAL_C void TestIllegal() { RThread thread; TRequestStatus threadstat; TBool jit = User::JustInTime(); User::SetJustInTime(EFalse); TInt ret = thread.Create(KThread2Name, IllegalPanicThing, KDefaultStackSize, KHeapSize, KHeapSize, &data); test(KErrNone == ret); thread.Logon(threadstat); thread.Resume(); User::WaitForRequest(threadstat); test (thread.ExitType() == EExitPanic); test (thread.ExitReason() == EXPECTEDPANIC); thread.Close(); User::SetJustInTime(jit); }
|
|
|