examples/SFExamples/Symbian_OS_Explained_Hercules-v9_Example_Code/testcode/testhercules.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 #include <e32base.h>
00017 #include <e32cons.h>
00018 
00019 #include "client.h"
00020 #include "client-server.h"
00021 #include "task.h"
00022 
00023 _LIT(KTextExampleCode,"Symbian OS Example Code");
00024 
00025 _LIT(KSlayNemeanLion, "Test SlayNemeanLion() passed\n");
00026 _LIT(KSlayHydra, "Test SlayHydra() passed\n");
00027 _LIT(KCaptureCeryneianHind, "Test CaptureCeryneianHind() passed\n");
00028 _LIT(KSlayErymanthianBoar, "Test SlayErymanthianBoar() passed\n");
00029 _LIT(KCleanAugeanStables, "Test CleanAugeanStables() passed\n");
00030 _LIT(KSlayStymphalianBirds, "Test SlayStymphalianBirds() passed\n");
00031 
00032 _LIT(KTasksInAdditionOrder, "Tasks in addition order\n");
00033 _LIT(KTasksInAscendingOrder, "Tasks in ascending order\n");
00034 
00035 _LIT(KTestArrays, "Array tests passed\n");
00036 
00037 _LIT(KTextOK, "All tests Passed OK!\n");
00038 _LIT(KTextPressAnyKey,"[Press any key]");
00039 
00040 CConsoleBase* gConsole;
00041         
00042 void TestClientServerL()
00043         {
00044         __UHEAP_MARK; // Checks for memory leaks
00045         
00046         // Open the client-server session
00047         RHerculesSession session;
00048         User::LeaveIfError(session.Connect());
00049         CleanupClosePushL(session); // Closes the session a leave occurs
00050                 
00051         // Test the SlayNemeanLion() method     
00052         ASSERT(session.SlayNemeanLion(KNemeanLionDes, KNemeanLionVal)==KErrNone);
00053         gConsole->Printf(KSlayNemeanLion);
00054                         
00055         // Test the SlayHydra() method)         
00056         TVersion version(1,0,0);
00057         THydraData hydraData;
00058         hydraData.iHydraVersion = version;
00059         hydraData.iHeadCount = KHydraHeadCount;
00060         ASSERT(session.SlayHydra(hydraData)==KErrNone);
00061         
00062         // Check hydraData, which was modified by the server
00063         ASSERT(hydraData.iHeadCount==KNoHeads);
00064         gConsole->Printf(KSlayHydra);
00065                 
00066         // Test the CaptureCeryneianHind() method
00067         TInt count=KInitialCount;
00068         if (session.CaptureCeryneianHind(count)!=KErrNone)
00069                 ASSERT(EFalse);
00070         
00071         // Check count which was set by the server
00072         if (count!=KCapturedCount)
00073                 ASSERT(EFalse);
00074         
00075         gConsole->Printf(KCaptureCeryneianHind);
00076         
00077         // Test the SlayErymanthianBoar() method
00078         CHerculesData* data = CHerculesData::NewLC(KHercules, KHeracles, KHerculesDataVal);
00079         if (session.SlayErymanthianBoar(*data)!=KErrNone)
00080                 ASSERT(EFalse);
00081         
00082         gConsole->Printf(KSlayErymanthianBoar);
00083 
00084         // Test the CleanAugeanStables() method
00085         TRequestStatus status;
00086         session.CleanAugeanStables(status);
00087         User::WaitForRequest(status);
00088         ASSERT(KErrNone==status.Int());
00089         gConsole->Printf(KCleanAugeanStables);
00090         
00091         // Test the SlayStymphalianBirds() method
00092         TBuf8<12> myBuf(KHercules); // Server reads this data and updates it asynchronously
00093         session.SlayStymphalianBirds(KBirdCount, myBuf, status);
00094         User::WaitForRequest(status);
00095         // Inspect the contents of myBuf, modified by the server
00096         ASSERT(myBuf.Compare(KHercules)==0);
00097         
00098         gConsole->Printf(KSlayStymphalianBirds);
00099         
00100         // Clean up
00101         CleanupStack::PopAndDestroy(2, &session); // data, session
00102                 
00103         // Check for memory leaks and end test
00104         __UHEAP_MARKEND;
00105         }
00106 
00107 void TestArraysL()
00108         {
00109         __UHEAP_MARK;
00110 
00111         // Create the CHerculeanTaskManager object
00112         CHerculeanTaskManager* taskManager = CHerculeanTaskManager::NewLC();
00113         
00114         // Add some tasks (OK to add the same one multiple times)
00115         taskManager->AppendTaskL(ESlayHydra);
00116         taskManager->AppendTaskL(ESlayNemeanLion);
00117         taskManager->AppendTaskL(ECaptureCeryneianHind);
00118         taskManager->AppendTaskL(ECleanAugeanStables);
00119         taskManager->AppendTaskL(ECaptureCerberus);
00120         taskManager->AppendTaskL(ECaptureMaresOfDiomedes);
00121         taskManager->AppendTaskL(ESlayHydra);
00122         taskManager->AppendTaskL(ESlayNemeanLion);
00123         taskManager->AppendTaskL(ECaptureOxenOfGeryon);
00124         taskManager->AppendTaskL(ESlayErymanthianBoar);
00125         
00126         ASSERT(taskManager->TaskCount()==10);
00127         RBuf taskBuf;
00128         
00129         // List the tasks (in the order they were added)
00130         taskManager->ListTasksL(taskBuf);
00131         gConsole->Printf(taskBuf);
00132         gConsole->Printf(KTasksInAdditionOrder);
00133         gConsole->Printf(KTextPressAnyKey);
00134         gConsole->Getch(); // get and ignore character
00135         
00136         taskBuf.Zero();
00137         taskBuf.ReAllocL(0);
00138         
00139         // Remove both the SlayHydra tasks
00140         taskManager->DeleteTask(ESlayHydra);
00141         ASSERT(taskManager->TaskCount()==8);
00142         
00143         // Now list tasks in ascending order
00144         taskManager->ListTasksAscendingL(taskBuf);
00145         gConsole->Printf(taskBuf);
00146         gConsole->Printf(KTasksInAscendingOrder);
00147         gConsole->Printf(KTextPressAnyKey);
00148         gConsole->Getch(); // get and ignore character
00149         taskBuf.Zero();
00150         taskBuf.ReAlloc(0); // Free buffer
00151         
00152         // Add some more tasks  
00153         taskManager->AppendTaskL(ECleanAugeanStables);
00154         taskManager->AppendTaskL(ECancelCleanAugeanStables);
00155         ASSERT(taskManager->TaskCount()==10);
00156         
00157         // List the tasks in ascending order    
00158         taskManager->ListTasksAscendingL(taskBuf);
00159         gConsole->Printf(taskBuf);
00160         gConsole->Printf(KTasksInAscendingOrder);
00161         gConsole->Printf(KTextPressAnyKey);
00162         gConsole->Getch(); // get and ignore character
00163         taskBuf.Zero();
00164         taskBuf.ReAlloc(0); // Free buffer
00165         
00166         // Test is complete
00167         gConsole->Printf(KTestArrays);
00168                 
00169         CleanupStack::PopAndDestroy(taskManager);
00170         
00171         // Check for memory leaks and end test  
00172         __UHEAP_MARKEND;
00173         }
00174 
00175 TInt E32Main()
00176         {
00177         __UHEAP_MARK;
00178         
00179         CTrapCleanup* theCleanupStack = CTrapCleanup::New();
00180         
00181         gConsole = Console::NewL(KTextExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00182 
00183         TRAPD(err, TestClientServerL());        
00184         ASSERT(KErrNone==err);
00185         // Delay to allow the server thread to shutdown and test for memory leaks
00186         User::After(500000); 
00187         
00188         TRAP(err, TestArraysL());
00189         ASSERT(KErrNone==err);
00190         
00191         // Print closing text and wait for input
00192         gConsole->Printf(KTextOK);
00193         gConsole->Printf(KTextPressAnyKey);
00194         gConsole->Getch(); // get and ignore character
00195         
00196         delete gConsole;
00197         delete theCleanupStack;
00198         
00199         __UHEAP_MARKEND;
00200         return (err);
00201         }
00202 

Generated by  doxygen 1.6.2