|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <s32file.h> |
|
17 #include <txtrich.h> |
|
18 #include <conpics.h> |
|
19 #include <e32test.h> |
|
20 |
|
21 #include <badesca.h> |
|
22 |
|
23 #include "caltestlib.h" |
|
24 #include "caltestoom.h" |
|
25 |
|
26 #include <calentryview.h> |
|
27 |
|
28 RTest test(_L("TOOMADD")); |
|
29 |
|
30 _LIT(KTestCaledarFile, "toomadd"); |
|
31 |
|
32 class CTestApp : public CBase , public MCalTestOomCallBack |
|
33 { |
|
34 public: |
|
35 static CTestApp* NewL(); |
|
36 ~CTestApp(); |
|
37 |
|
38 void TestWithUserHeapFailureL(CCalEntry::TType aEntryType); |
|
39 void StoreEntryL(const CCalEntry* aEntry); |
|
40 |
|
41 private: |
|
42 void ConstructL(); |
|
43 |
|
44 public: // from MCalOomTestCallBack |
|
45 void OomTestL(TType aType, TInt aFailAt); |
|
46 |
|
47 private: |
|
48 CCalTestLibrary* iCalTestLib; |
|
49 CCalEntry::TType iEntryType; // used in oom test |
|
50 |
|
51 CCalEntry* iOomEntryAppt; |
|
52 CCalEntry* iOomEntrySaved; |
|
53 |
|
54 TBool iStoreOnly; |
|
55 }; |
|
56 |
|
57 CTestApp* CTestApp::NewL() |
|
58 { |
|
59 CTestApp* self = new(ELeave) CTestApp; |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 void CTestApp::ConstructL() |
|
67 { |
|
68 iCalTestLib = CCalTestLibrary::NewL(); |
|
69 iCalTestLib->ReplaceFileL(KTestCaledarFile); |
|
70 iCalTestLib->OpenFileL(KTestCaledarFile); |
|
71 } |
|
72 |
|
73 CTestApp::~CTestApp() |
|
74 { |
|
75 TRAP_IGNORE(iCalTestLib->DeleteFileL(KTestCaledarFile ,ETrue)); |
|
76 delete iCalTestLib; |
|
77 } |
|
78 |
|
79 void CTestApp::StoreEntryL(const CCalEntry* aEntry) |
|
80 { |
|
81 RPointerArray<CCalEntry> entryArray; |
|
82 CleanupClosePushL(entryArray); |
|
83 entryArray.AppendL(aEntry); |
|
84 TInt numSuc; |
|
85 iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc); |
|
86 test(numSuc == entryArray.Count()); |
|
87 CleanupStack::PopAndDestroy(&entryArray); |
|
88 } |
|
89 |
|
90 void CTestApp::OomTestL(TType /*aType*/, TInt /*aFailAt*/) |
|
91 { |
|
92 test.Printf(_L(".")); |
|
93 if (iStoreOnly) |
|
94 { |
|
95 iOomEntrySaved->CompareL(*iOomEntryAppt); |
|
96 StoreEntryL(iOomEntryAppt); |
|
97 iOomEntrySaved->CompareL(*iOomEntryAppt); |
|
98 } |
|
99 else |
|
100 { |
|
101 HBufC8* guid = NULL; |
|
102 CCalEntry* entry = iCalTestLib->CreateCalEntryL(iEntryType, guid); |
|
103 CleanupStack::PushL(entry); |
|
104 iCalTestLib->SetEntryStartAndEndTimeL(entry, TTime(_L("20051123:120000.000000")), TTime(_L("20051123:130000.000000"))); |
|
105 StoreEntryL(entry); |
|
106 CleanupStack::PopAndDestroy(entry); |
|
107 } |
|
108 } |
|
109 |
|
110 void CTestApp::TestWithUserHeapFailureL(CCalEntry::TType aEntryType) |
|
111 { |
|
112 // make sure the entry view has been created before we start the oom test |
|
113 iCalTestLib->SynCGetEntryViewL(); |
|
114 iEntryType = aEntryType; |
|
115 CCalSession& calSession = iCalTestLib->GetSession(); |
|
116 CalTestOom::OutOfMemoryTestL(*this, EClient, calSession); |
|
117 CalTestOom::OutOfMemoryTestL(*this, EServer, calSession); |
|
118 } |
|
119 |
|
120 static void doMainL() |
|
121 { |
|
122 CTestApp* testApp = CTestApp::NewL(); |
|
123 CleanupStack::PushL(testApp); |
|
124 |
|
125 test.Next(_L("Starting Testing CAgnEntryModel with user-heap failure")); |
|
126 |
|
127 testApp->TestWithUserHeapFailureL(CCalEntry::EAppt); |
|
128 testApp->TestWithUserHeapFailureL(CCalEntry::EEvent); |
|
129 testApp->TestWithUserHeapFailureL(CCalEntry::EAnniv); |
|
130 testApp->TestWithUserHeapFailureL(CCalEntry::ETodo); |
|
131 testApp->TestWithUserHeapFailureL(CCalEntry::EReminder); |
|
132 |
|
133 CleanupStack::PopAndDestroy(testApp); |
|
134 } |
|
135 |
|
136 /** |
|
137 |
|
138 @SYMTestCaseID PIM-TOOMADD-0001 |
|
139 |
|
140 */ |
|
141 |
|
142 TInt E32Main() |
|
143 { |
|
144 |
|
145 __UHEAP_MARK; |
|
146 test.Start(_L("@SYMTESTCaseID:PIM-TOOMADD-0001 TOOMADD.CPP")); |
|
147 |
|
148 test.Title(); |
|
149 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
150 CActiveScheduler* scheduler = new CActiveScheduler; |
|
151 CActiveScheduler::Install(scheduler); |
|
152 TRAPD(ret,doMainL()); |
|
153 delete scheduler; |
|
154 test(ret==KErrNone); |
|
155 delete theCleanup; |
|
156 test.End(); |
|
157 test.Close(); |
|
158 __UHEAP_MARKEND; |
|
159 return(KErrNone); |
|
160 } |
|
161 |