phonebookengines_old/contactsmodel/tsrc/T_ERROR.CPP
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     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 // This harness reqires a writeable drive other than C: or Z:, e.g. an MMC drive
       
    17 
       
    18 #include <e32test.h>
       
    19 #include "T_UTILS.H"
       
    20 #include "CContactDbEventQueue.h"
       
    21 #include <coreappstest/testserver.h>
       
    22 
       
    23 // Type definitions 
       
    24 LOCAL_D RTest test(_L("T_ERROR"));
       
    25 LOCAL_D RFs TheFs;
       
    26 LOCAL_D CContactIdArray* IdList;
       
    27 
       
    28 enum TOomFailureModes
       
    29 	{	
       
    30 	KOomFailNormal,
       
    31 	KOomFailFileServerGeneral,
       
    32 	KOomFailFileServerOom,
       
    33 	KOomFailContactServer,
       
    34 	KOomFailDbs,
       
    35 	KOomNumFailModes,
       
    36 	};	
       
    37 
       
    38 const TPtrC KDatabaseFileName = _L("C:T_ERROR");
       
    39 const TPtrC KDatabaseCreateFileName = _L("C:T_ERRORC");
       
    40 const TPtrC KFakeFDrive=_L("C:FAKEFDRIVE");
       
    41 
       
    42 typedef TBuf<0x40> TOomTestName;
       
    43 
       
    44 class COomTest;
       
    45 
       
    46 class COomFailBase : public CBase
       
    47 	{
       
    48 public:
       
    49 	~COomFailBase();
       
    50 	COomFailBase(COomTest* aOomTest);
       
    51 	virtual void ConstructL();
       
    52 	virtual void PreFailL();
       
    53 	virtual void ClearUpL();
       
    54 	virtual void FailL() = 0;
       
    55 	virtual TBool ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError);
       
    56 	virtual TOomTestName TestName() = 0;
       
    57 	virtual TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
    58 protected:
       
    59 	void RecoverL(TBool waitForEvent = EFalse); 
       
    60 	void WaitForEvent(TContactDbObserverEventType anEventType);
       
    61 
       
    62 protected:
       
    63 	COomTest* iOomTest;
       
    64 	CContactDatabase* iDb;
       
    65 	CContactDbEventQueue* iDbEventQueue;
       
    66 	TInt iCounter;
       
    67 	};
       
    68 
       
    69 class COomOpen : public COomFailBase
       
    70 	{
       
    71 public:
       
    72 	inline COomOpen(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
    73 	void FailL();
       
    74 	void ClearUpL();
       
    75 	inline TOomTestName TestName() {return(_L("Open"));};
       
    76 private:
       
    77 	CContactDatabase* iDb2;
       
    78 	CContactDatabase* iDb;
       
    79 	};
       
    80 
       
    81 class COomCreate : public COomFailBase
       
    82 	{
       
    83 public:
       
    84 	inline COomCreate(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
    85 	inline TOomTestName TestName() {return(_L("Create"));};
       
    86 	void PreFailL();
       
    87 	void FailL();
       
    88 	void ClearUpL();
       
    89 private:
       
    90 	CContactDatabase* iDb2;
       
    91 	};
       
    92 
       
    93 class COomSetDatabaseDrive : public COomFailBase
       
    94 	{
       
    95 public:
       
    96 	inline COomSetDatabaseDrive(COomTest* aOomTest, TDriveUnit aMmcDrive) : COomFailBase(aOomTest), iMmcDrive(aMmcDrive) {};
       
    97 	inline TOomTestName TestName() {return(_L("SetDatabaseDrive"));};
       
    98 	void PreFailL();
       
    99 	void ConstructL();
       
   100 	void FailL();
       
   101 	void ClearUpL();
       
   102 	TBool ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError);
       
   103 private:
       
   104 	// writeable drive found for testing with
       
   105 	TDriveUnit iMmcDrive;
       
   106 	};
       
   107 
       
   108 class COomGetDefaultName : public COomFailBase
       
   109 	{
       
   110 public:
       
   111 	inline COomGetDefaultName(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   112 	inline TOomTestName TestName() {return(_L("GetDefaultName"));};
       
   113 	void FailL();
       
   114 	};
       
   115 
       
   116 class COomViewDefinition : public COomFailBase
       
   117 	{
       
   118 public:
       
   119 	inline COomViewDefinition(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   120 	inline TOomTestName TestName() {return(_L("ViewDefinition"));};
       
   121 	void FailL();
       
   122 	};
       
   123 
       
   124 class COomTextDefinition : public COomFailBase
       
   125 	{
       
   126 public:
       
   127 	inline COomTextDefinition(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   128 	inline TOomTestName TestName() {return(_L("TextDefinition"));};
       
   129 	void FailL();
       
   130 	};
       
   131 
       
   132 class COomReadContact : public COomFailBase
       
   133 	{
       
   134 public:
       
   135 	inline COomReadContact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   136 	inline TOomTestName TestName() {return(_L("ReadContact"));};
       
   137 	void FailL();
       
   138 	};
       
   139 
       
   140 class COomAddNewContact : public COomFailBase
       
   141 	{
       
   142 public:
       
   143 	inline COomAddNewContact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   144 	inline TOomTestName TestName() {return(_L("AddNewContact"));};
       
   145 	void PreFailL();
       
   146 	void FailL();
       
   147 	void ClearUpL();
       
   148 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   149 protected:
       
   150 	TContactItemId iNewContactId;
       
   151 	};
       
   152 
       
   153 class COomReadContactTextDef : public COomFailBase
       
   154 	{
       
   155 public:
       
   156 	inline COomReadContactTextDef(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   157 	inline TOomTestName TestName() {return(_L("ReadContactTextDef"));};
       
   158 	void FailL();
       
   159 	};
       
   160 
       
   161 class COomOpenAndCloseContact : public COomFailBase
       
   162 	{
       
   163 public:
       
   164 	inline COomOpenAndCloseContact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   165 	inline TOomTestName TestName() {return(_L("OpenAndCloseContact"));};
       
   166 	void FailL();
       
   167 	};
       
   168 
       
   169 class COomOpenAndCloseContactX : public COomFailBase
       
   170 	{
       
   171 public:
       
   172 	inline COomOpenAndCloseContactX(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   173 	inline TOomTestName TestName() {return(_L("OpenAndCloseContactX"));};
       
   174 	void FailL();
       
   175 	};
       
   176 
       
   177 class COomOpenModifyAndCommitContact : public COomFailBase
       
   178 	{
       
   179 public:
       
   180 	inline COomOpenModifyAndCommitContact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   181 	inline TOomTestName TestName() {return(_L("OpenModifyAndCommitContact"));};
       
   182 	void PreFailL();
       
   183 	void FailL();
       
   184 	void ClearUpL();
       
   185 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   186 private:
       
   187 	CContactItem* iCard;
       
   188 	};
       
   189 
       
   190 class COomDeleteContact : public COomFailBase
       
   191 	{
       
   192 public:
       
   193 	inline COomDeleteContact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   194 	inline TOomTestName TestName() {return(_L("DeleteContact"));};
       
   195 	void PreFailL();
       
   196 	void FailL();
       
   197 	void ClearUpL();
       
   198 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   199 private:
       
   200 	TContactItemId iNewContactId;
       
   201 	TInt iStartCount;
       
   202 	};
       
   203 
       
   204 class COomDeleteContacts : public COomFailBase
       
   205 	{
       
   206 public:
       
   207 	inline COomDeleteContacts(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   208 	inline TOomTestName TestName() {return(_L("DeleteContacts"));};
       
   209 	void PreFailL();
       
   210 	void FailL();
       
   211 	void ClearUpL();
       
   212 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   213 private:
       
   214 	CContactIdArray* iNewContactIds;
       
   215 	TInt iStartCount;
       
   216 	};
       
   217 
       
   218 class COomCompact : public COomFailBase
       
   219 	{
       
   220 public:
       
   221 	inline COomCompact(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   222 	inline TOomTestName TestName() {return(_L("Compact"));};
       
   223 	void FailL();
       
   224 	void ClearUpL();
       
   225 	};
       
   226 
       
   227 class COomImportContacts : public COomFailBase
       
   228 	{
       
   229 public:
       
   230 	~COomImportContacts();
       
   231 	void ConstructL();
       
   232 	inline COomImportContacts(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   233 	inline TOomTestName TestName() {return(_L("ImportContacts"));};
       
   234 	void PreFailL();
       
   235 	void FailL();
       
   236 	void ClearUpL();
       
   237 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   238 private:
       
   239 	CFileStore* iStore;
       
   240 	RStoreReadStream iInStream;
       
   241 	TStreamId iStreamId;
       
   242 	CArrayPtr<CContactItem>* iImportedContacts;
       
   243 	TInt iOldRecordCount;
       
   244 	TContactItemId iDeleteMeId;
       
   245 	};
       
   246 
       
   247 class COomExportSelectedContacts : public COomFailBase
       
   248 	{
       
   249 public:
       
   250 	~COomExportSelectedContacts();
       
   251 	void ConstructL();
       
   252 	inline COomExportSelectedContacts(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   253 	inline TOomTestName TestName() {return(_L("ExportSelectedContacts"));};
       
   254 	void PreFailL();
       
   255 	void FailL();
       
   256 	void ClearUpL();
       
   257 	TBool ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError);
       
   258 private:
       
   259 	CContactIdArray* iIdList;
       
   260 	CFileStore* iStore;
       
   261 	RStoreWriteStream iOutStream;
       
   262 	TStreamId iStreamId;
       
   263 	};
       
   264 
       
   265 class COomFind : public COomFailBase
       
   266 	{
       
   267 public:
       
   268 	inline COomFind(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   269 	inline TOomTestName TestName() {return(_L("Find"));};
       
   270 	void FailL();
       
   271 	};
       
   272 
       
   273 class COomFindInTextDef : public COomFailBase
       
   274 	{
       
   275 public:
       
   276 	inline COomFindInTextDef(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   277 	~COomFindInTextDef();
       
   278 	void ConstructL();
       
   279 	inline TOomTestName TestName() {return(_L("Find In TextDef"));};
       
   280 	void FailL();
       
   281 private:
       
   282 	CDesCArrayFlat* iFindWords;
       
   283 	CContactTextDef* iTextDef;
       
   284 	};
       
   285 
       
   286 class COomFindAsyncInTextDef : public COomFailBase
       
   287 	{
       
   288 public:
       
   289 	inline COomFindAsyncInTextDef(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   290 	~COomFindAsyncInTextDef();
       
   291 	void ConstructL();
       
   292 	inline TOomTestName TestName() {return(_L("Find In TextDef ASync"));};
       
   293 	void FailL();
       
   294 private:
       
   295 	CDesCArrayFlat* iFindWords;
       
   296 	CContactTextDef* iTextDef;
       
   297 	};
       
   298 
       
   299 class COomFindAsync : public COomFailBase
       
   300 	{
       
   301 public:
       
   302 	inline COomFindAsync(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   303 	inline TOomTestName TestName() {return(_L("FindAsync"));};
       
   304 	void FailL();
       
   305 	};
       
   306 
       
   307 class COomSort : public COomFailBase
       
   308 	{
       
   309 public:
       
   310 	inline COomSort(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   311 	inline TOomTestName TestName() {return(_L("Sort"));};
       
   312 	void FailL();
       
   313 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   314 private:
       
   315 	TInt iPrevCount;
       
   316 	};
       
   317 
       
   318 class COomSortArray : public COomFailBase
       
   319 	{
       
   320 public:
       
   321 	~COomSortArray();
       
   322 	inline COomSortArray(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   323 	inline TOomTestName TestName() {return(_L("Sort Array"));};
       
   324 	void ConstructL();
       
   325 	void FailL();
       
   326 private:
       
   327 	CContactIdArray* iIdArray;
       
   328 	TInt iPrevCount;
       
   329 	CArrayFix<CContactDatabase::TSortPref>* iSortOrder;
       
   330 	};
       
   331 
       
   332 class COomCompress : public COomFailBase, public MContactUiCompactObserver
       
   333 	{
       
   334 public:
       
   335 	inline COomCompress(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   336 	inline TOomTestName TestName() {return(_L("Compress"));};
       
   337 	void PreFailL();
       
   338 	void FailL();
       
   339 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   340 	void ClearUpL();
       
   341 // from MContactUiCompactObserver
       
   342 	void Step(TInt aStep);
       
   343 	void HandleError(TInt aError);
       
   344 private:
       
   345 	TInt iRecievedError;
       
   346 	};
       
   347 
       
   348 class COomRecover : public COomFailBase, public MContactUiCompactObserver
       
   349 	{
       
   350 public:
       
   351 	inline COomRecover(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   352 	inline TOomTestName TestName() {return(_L("Recover"));};
       
   353 	void PreFailL();
       
   354 	void FailL();
       
   355 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   356 private:
       
   357 	void doRecoverL();
       
   358 // from MContactUiCompactObserver
       
   359 	void Step(TInt aStep);
       
   360 	void HandleError(TInt aError);
       
   361 private:
       
   362 	TInt iRecievedError;
       
   363 	};
       
   364 
       
   365 class COomCloseOpenTables : public COomFailBase
       
   366 	{
       
   367 public:
       
   368 	inline COomCloseOpenTables(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   369 	inline TOomTestName TestName() {return(_L("CloseOpenTables"));};
       
   370 	void FailL();
       
   371 	};
       
   372 
       
   373 class COomViewDefInternalize : public COomFailBase
       
   374 	{
       
   375 public:
       
   376 	~COomViewDefInternalize();
       
   377 	inline COomViewDefInternalize(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   378 	inline TOomTestName TestName() {return(_L("ViewDefInternalize"));};
       
   379 	void ConstructL();
       
   380 	void PreFailL();
       
   381 	void FailL();
       
   382 	void ClearUpL();
       
   383 protected:
       
   384 	CBufStore *iBufStore;
       
   385 	RStoreReadStream iReadStream;
       
   386 	TStreamId iStreamId;
       
   387 	};
       
   388 
       
   389 class COomViewDefExternalize : public COomFailBase
       
   390 	{
       
   391 public:
       
   392 	~COomViewDefExternalize();
       
   393 	inline COomViewDefExternalize(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   394 	inline TOomTestName TestName() {return(_L("ViewDefExternalize"));};
       
   395 	void ConstructL();
       
   396 	void PreFailL();
       
   397 	void FailL();
       
   398 	void ClearUpL();
       
   399 protected:
       
   400 	CBufStore* iBufStore;
       
   401 	RStoreWriteStream iWriteStream;
       
   402 	TStreamId iStreamId;
       
   403 	TBool iFailed;
       
   404 	};
       
   405 
       
   406 class COomContactChangeNotifier : public COomFailBase
       
   407 	{
       
   408 public:
       
   409 	class COomNotificationRec : public CBase, public MContactDbObserver
       
   410 		{
       
   411 	public:
       
   412 		static COomNotificationRec* NewL();
       
   413 		~COomNotificationRec();
       
   414 		void Wait(TBool aUnknownErrAllowed);
       
   415 		static TInt TimerCallBackL(TAny* aSelf);
       
   416 		inline TBool UnknownChange() const {return(iUnknownChange);};
       
   417 	public: // from MContactDbObserver
       
   418 		void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
       
   419 	private:
       
   420 		void ConstructL();
       
   421 	private:
       
   422 		CPeriodic* iTimer;
       
   423 		TBool iWaiting;
       
   424 		TBool iGotMessage;
       
   425 		TBool iUnknownErrAllowed;
       
   426 		TBool iUnknownChange;
       
   427 		};
       
   428 public:
       
   429 	~COomContactChangeNotifier();
       
   430 	inline COomContactChangeNotifier(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   431 	inline TOomTestName TestName() {return(_L("ContactChangeNotifier"));};
       
   432 	void ConstructL();
       
   433 	void PreFailL();
       
   434 	void FailL();
       
   435 	void ClearUpL();
       
   436 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   437 protected:
       
   438 	COomNotificationRec* iRec;
       
   439 	CContactItem* iItem1;
       
   440 	CContactItem* iItem2;
       
   441 	CContactItem* iItem3;
       
   442 	};
       
   443 
       
   444 class COomFieldSetStore : public COomFailBase
       
   445 	{
       
   446 public:
       
   447 	~COomFieldSetStore();
       
   448 	inline COomFieldSetStore(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   449 	inline TOomTestName TestName() {return(_L("FieldSetStore"));};
       
   450 	void ConstructL();
       
   451 	void FailL();
       
   452 	void ClearUpL();
       
   453 protected:
       
   454 	CBufStore* iBufStore;
       
   455 	CBufStore* iBlobStore;
       
   456 	CBufStore* iTextStore;
       
   457 	CContactItemFieldSet* iItemFieldSet;
       
   458 	TStreamId iStreamId;
       
   459 	};
       
   460 
       
   461 class COomFieldSetRestore : public COomFailBase
       
   462 	{
       
   463 public:
       
   464 	~COomFieldSetRestore();
       
   465 	inline COomFieldSetRestore(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   466 	inline TOomTestName TestName() {return(_L("FieldSetRestore"));};
       
   467 	void ConstructL();
       
   468 	void PreFailL();
       
   469 	void FailL();
       
   470 	void ClearUpL();
       
   471 protected:
       
   472 	CBufStore* iBufStore;
       
   473 	CBufStore* iTextStore;
       
   474 	CBufStore* iBlobStore;
       
   475 	TStreamId iStreamId;
       
   476 	TStreamId iTextStreamId;
       
   477 	CContactViewDef* iViewDef;
       
   478 	};
       
   479 
       
   480 class COomContactCardClone : public COomFailBase
       
   481 	{
       
   482 public:
       
   483 	~COomContactCardClone();
       
   484 	inline COomContactCardClone(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   485 	inline TOomTestName TestName() {return(_L("ContactCardClone"));};
       
   486 	void ConstructL();
       
   487 	void FailL();
       
   488 private:
       
   489 	CContactCard* iSourceCard;
       
   490 	};
       
   491 
       
   492 class COomPhoneNumberLookup : public COomFailBase
       
   493 	{
       
   494 public:
       
   495 	~COomPhoneNumberLookup();
       
   496 	inline COomPhoneNumberLookup(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   497 	inline TOomTestName TestName() {return(_L("Phone Number Lookup"));};
       
   498 	void ConstructL();
       
   499 	void PreFailL();
       
   500 	void FailL();
       
   501 	void ClearUpL();
       
   502 private:
       
   503 	TInt FileSizeL();
       
   504 private:
       
   505 	TContactItemId iAddId;
       
   506 	CContactCard* iAddCard;
       
   507 	};
       
   508 
       
   509 class COomContactsChangedSince : public COomFailBase
       
   510 	{
       
   511 public:
       
   512 	~COomContactsChangedSince();
       
   513 	inline COomContactsChangedSince(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   514 	inline TOomTestName TestName() {return(_L("ContactsChangedSince"));};
       
   515 	void ConstructL();
       
   516 	void FailL();
       
   517 private:
       
   518 	TContactItemId iNewContactId1;
       
   519 	TContactItemId iNewContactId2;
       
   520 	TTime iBeforeTime;
       
   521 	};
       
   522 
       
   523 class COomGroups : public COomFailBase
       
   524 	{
       
   525 public:
       
   526 	~COomGroups();
       
   527 	inline COomGroups(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   528 	inline TOomTestName TestName() {return(_L("Groups"));};
       
   529 	void ConstructL();
       
   530 	void FailL();
       
   531 	void ClearUpL();
       
   532 	TBool Skip(TInt aCount, TOomFailureModes aMode) const;
       
   533 private:
       
   534 	TContactItemId iGroupId;
       
   535 	CContactCard* iItem1;
       
   536 	};
       
   537 
       
   538 class COomGroups2 : public COomFailBase
       
   539 	{
       
   540 public:
       
   541 	~COomGroups2();
       
   542 	inline COomGroups2(COomTest* aOomTest) : COomFailBase(aOomTest) {};
       
   543 	inline TOomTestName TestName() {return(_L("Groups 2"));};
       
   544 	void ConstructL();
       
   545 	void FailL();
       
   546 	void ClearUpL();
       
   547 private:
       
   548 	TContactItemId iGroupId1;
       
   549 	TContactItemId iGroupId2;
       
   550 	};
       
   551 
       
   552 //
       
   553 
       
   554 class COomTest : public CBase
       
   555 	{
       
   556 public:
       
   557 	COomTest(TDriveUnit aMmcDrive);
       
   558 	void ConstructL();
       
   559 	~COomTest();
       
   560 	TBool DoTestL();
       
   561 	void DoOomTestL(COomFailBase *aOomTest, TOomFailureModes aMode);
       
   562 	void Test(TBool aMustBeTrue);
       
   563 	TBool TestsL();
       
   564 private:
       
   565 	TInt GetRecordCountL();
       
   566 private:
       
   567 	RDbs iDbs;
       
   568 	TDriveUnit iMmcDrive;
       
   569 	};
       
   570 
       
   571 
       
   572 LOCAL_C void AddNewContactsL()
       
   573 //
       
   574 // Add 2 new contacts with varying numbers of text fields
       
   575 //
       
   576 	{
       
   577 	CContactDatabase* db=CContactDatabase::OpenL(KDatabaseFileName);
       
   578 	CleanupStack::PushL(db);
       
   579 	CContactCard* card=CContactCard::NewL();
       
   580 	CleanupStack::PushL(card);
       
   581 	TContactItemId id=KNullContactId;
       
   582 	TContactItemId newId=KNullContactId;
       
   583 	for (TInt ii=0;ii<5;ii++)
       
   584 		{
       
   585 		TBuf<16> name;
       
   586 		name.Format(_L("NAME #%d"),ii);
       
   587 		SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,name,EFalse);
       
   588 		name.Format(_L("GivenName #%d"),ii);
       
   589 		SetNameL(*card,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,name,EFalse);
       
   590 		CContactItemField* field=CContactItemField::NewLC(KStorageTypeText);
       
   591 		card->AddFieldL(*field);
       
   592 		CleanupStack::Pop(); // field
       
   593 		newId=db->AddNewContactL(*card);
       
   594 		id=newId;
       
   595 		IdList->AddL(id);
       
   596 		}
       
   597 	CleanupStack::PopAndDestroy(2); // card, db
       
   598 	}
       
   599 
       
   600 LOCAL_C void CreateDatabaseL()
       
   601 //
       
   602 // Create a database in a store
       
   603 //
       
   604 	{
       
   605 	CContactDatabase* db=CContactDatabase::ReplaceL(KDatabaseFileName);
       
   606 	delete db;
       
   607 	}
       
   608 
       
   609 //	
       
   610 //
       
   611 // COomFailBase
       
   612 //
       
   613 
       
   614 COomFailBase::COomFailBase(COomTest* aOomTest) : iOomTest(aOomTest), iCounter(0)
       
   615 	{}
       
   616 
       
   617 COomFailBase::~COomFailBase()
       
   618 	{
       
   619 	delete iDbEventQueue;
       
   620 	delete iDb;
       
   621 	}
       
   622 
       
   623 void COomFailBase::ConstructL()
       
   624 	{
       
   625 	iDb=CContactDatabase::OpenL(KDatabaseFileName);
       
   626 	iDbEventQueue = CContactDbEventQueue::NewL(iDb);
       
   627 	}
       
   628 
       
   629 void COomFailBase::WaitForEvent(TContactDbObserverEventType anEventType)
       
   630 	{
       
   631 	TContactDbObserverEvent event;
       
   632 	++iCounter;
       
   633 	FOREVER
       
   634 		{
       
   635 		event.iType = EContactDbObserverEventNull;
       
   636 		iDbEventQueue->ListenForEvent(1,event);  //1 second timeout
       
   637 		//RDebug::Print(_L("%d Message: %d"), iCounter, event.iType);
       
   638 		
       
   639 		if (event.iType == anEventType || event.iType == EContactDbObserverEventNull)
       
   640 			break;
       
   641 		}
       
   642 	}
       
   643 
       
   644 void COomFailBase::PreFailL()
       
   645 	{}
       
   646 
       
   647 void COomFailBase::ClearUpL()
       
   648 	{}
       
   649 
       
   650 TBool COomFailBase::ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError)
       
   651 	{
       
   652 	if(aMode == KOomFailFileServerGeneral)
       
   653 		{
       
   654 		if (aError != KErrGeneral)
       
   655 			{
       
   656 			test.Printf(_L("ErrorOk test failed - Mode %i, iteration %i, error %i"), aMode, aIteration, aError);
       
   657 			return EFalse;
       
   658 			}
       
   659 		return ETrue;
       
   660 		}
       
   661 	else
       
   662 		{
       
   663 		if (aError != KErrNoMemory)
       
   664 			{
       
   665 			test.Printf(_L("ErrorOk test failed - Mode %i, iteration %i, error %i"), aMode, aIteration, aError);
       
   666 			return EFalse;
       
   667 			}
       
   668 		return ETrue;
       
   669 		}
       
   670 	}
       
   671 
       
   672 void COomFailBase::RecoverL(TBool waitForEvent)
       
   673 	{
       
   674 	iDb->RecoverL();
       
   675 	if (waitForEvent)
       
   676 		{
       
   677 		WaitForEvent(EContactDbObserverEventRecover);
       
   678 		}
       
   679 	else
       
   680 		{
       
   681 		iDbEventQueue->Clear();
       
   682 		}
       
   683 		
       
   684 	}
       
   685 
       
   686 TBool COomFailBase::Skip(TInt , TOomFailureModes ) const
       
   687 	{
       
   688 	// When trying to figure out why we need this, please see DEF037382 and DEF037234
       
   689 	// Basically, certain conditions cause the DBMS system to corrupt the database
       
   690 	// and we hop over those particular cases.
       
   691 	//
       
   692 	// Generally, one particular case, perhaps when count==71 or whatever, will be
       
   693 	// the only problem. However, new builds and commenting out other test cases
       
   694 	// can both change this number, so in a lot of cases every test is skipped instead.
       
   695 	return(EFalse);
       
   696 	}
       
   697 
       
   698 //
       
   699 // COomOpen
       
   700 //
       
   701 
       
   702 void COomOpen::FailL()
       
   703 	{
       
   704 	iDb2=CContactDatabase::OpenL(KDatabaseFileName);
       
   705 	iDb2->CountL();
       
   706 	}
       
   707 
       
   708 void COomOpen::ClearUpL()
       
   709 	{
       
   710 	RecoverL();
       
   711 	delete iDb2;
       
   712 	iDb2=NULL;
       
   713 	}
       
   714 
       
   715 //
       
   716 // COomCreate
       
   717 //
       
   718 
       
   719 void COomCreate::PreFailL()
       
   720 	{
       
   721 	if(CContactDatabase::ContactDatabaseExistsL(KDatabaseCreateFileName))
       
   722     	CContactDatabase::DeleteDatabaseL(KDatabaseCreateFileName);
       
   723 	}
       
   724 
       
   725 void COomCreate::FailL()
       
   726 	{
       
   727 	iDb2=CContactDatabase::CreateL(KDatabaseCreateFileName);
       
   728 	}
       
   729 
       
   730 void COomCreate::ClearUpL()
       
   731 	{
       
   732 	RecoverL();
       
   733 	delete iDb2;
       
   734 	iDb2=NULL;
       
   735     TRAPD(err,CContactDatabase::DeleteDatabaseL(KDatabaseCreateFileName));
       
   736 	if (err != KErrNotFound)
       
   737 		{
       
   738 		User::LeaveIfError(err);
       
   739 		}
       
   740 	}
       
   741 
       
   742 //
       
   743 // COomSetDatabaseDrive
       
   744 //
       
   745 
       
   746 void COomSetDatabaseDrive::ConstructL()
       
   747 	{
       
   748 	COomFailBase::ConstructL();
       
   749 	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse);
       
   750 	}
       
   751 
       
   752 void COomSetDatabaseDrive::PreFailL()
       
   753 	{
       
   754 	// select test drive
       
   755 	CContactDatabase::SetDatabaseDriveL(iMmcDrive,EFalse);
       
   756 	// delete default database, if present
       
   757 	TRAP_IGNORE(CContactDatabase::DeleteDefaultFileL());
       
   758 	// switch back to C: drive
       
   759 	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse);
       
   760 	// ensure a default database file exists on C:
       
   761 	if (!CContactDatabase::DefaultContactDatabaseExistsL())
       
   762 		{
       
   763 		CContactDatabase* newDb = CContactDatabase::ReplaceL();
       
   764 		delete newDb;
       
   765 		}
       
   766 	}
       
   767 
       
   768 void COomSetDatabaseDrive::FailL()
       
   769 	{
       
   770 	CContactDatabase::SetDatabaseDriveL(iMmcDrive);
       
   771 	}
       
   772 
       
   773 void COomSetDatabaseDrive::ClearUpL()
       
   774 	{
       
   775 // Below needed because of problem with CDictionaryStore reporting error when it has successfully
       
   776 // committed changes to the DatabaseDrive ini variable
       
   777 	RecoverL();
       
   778 	
       
   779 	TRAPD(error,CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),ETrue));
       
   780 	if (error==KErrNotFound || error==KErrAlreadyExists)
       
   781 		{
       
   782 		CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse);
       
   783 		}
       
   784 	else 
       
   785 		{
       
   786 		User::LeaveIfError(error);
       
   787 		}
       
   788 	}
       
   789 
       
   790 TBool COomSetDatabaseDrive::ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError)
       
   791 	{
       
   792 	if(aMode != KOomFailFileServerGeneral)
       
   793 		{
       
   794 		if (aError != KErrNoMemory)
       
   795 			{
       
   796 			TPtrC drvPtr(iMmcDrive.Name());
       
   797 
       
   798 			test.Printf(_L("ErrorOk test failed for SetDatabaseDrive(%S) - Mode %i, iteration %i, error %i"), 
       
   799 				&drvPtr, aMode, aIteration, aError);
       
   800 
       
   801 #ifdef __WINS__
       
   802 			if (aError == KErrNotReady)
       
   803 				{
       
   804 				test.Printf(_L("Writeable directory must map to an extra drive (e.g. F: or D:). In epoc.ini file add _EPOC_DRIVE_F \\epoc32\\winscw\\f"));
       
   805 				}
       
   806 			else if (aError == KErrPathNotFound)
       
   807 				{
       
   808 				test.Printf(_L("Drive %S mapped in epoc.ini file, but probably the mapped directory does not exist."), &drvPtr);
       
   809 				}
       
   810 #else
       
   811 			// hardware build
       
   812 			if (aError == KErrNotReady)
       
   813 				{
       
   814 				test.Printf(_L("Drive %s not ready."), &drvPtr);
       
   815 				}
       
   816 #endif
       
   817 			return EFalse;
       
   818 			}
       
   819 		return ETrue;
       
   820 		}
       
   821 	else
       
   822 		{
       
   823 		return(COomFailBase::ErrorOk(aMode, aIteration, aError));
       
   824 		}
       
   825 	}
       
   826 
       
   827 //
       
   828 // COomGetDefaultName
       
   829 //
       
   830 
       
   831 void COomGetDefaultName::FailL()
       
   832 	{
       
   833 	TFileName fileName;
       
   834 	CContactDatabase::GetDefaultNameL(fileName);
       
   835 	}
       
   836 
       
   837 //
       
   838 // COomViewDefinition
       
   839 //
       
   840 
       
   841 void COomViewDefinition::FailL()
       
   842 	{
       
   843 	CContactItemViewDef* itemViewDef=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
       
   844 	itemViewDef->AddL(KUidContactFieldCompanyName);
       
   845 	CContactViewDef* viewDef=CContactViewDef::NewL(itemViewDef);
       
   846 	CleanupStack::Pop();	// itemViewDef
       
   847 	delete viewDef;
       
   848 	}
       
   849 
       
   850 //
       
   851 // COomTextDefinition
       
   852 //
       
   853 
       
   854 void COomTextDefinition::FailL()
       
   855 	{
       
   856 	CContactTextDef *textDef=CContactTextDef::NewLC();
       
   857 	textDef->AppendL(TContactTextDefItem(KUidContactFieldPhoneNumber));
       
   858 	CleanupStack::PopAndDestroy();	// textDef
       
   859 	}
       
   860 
       
   861 //
       
   862 // COomReadContact
       
   863 //
       
   864 
       
   865 void COomReadContact::FailL()
       
   866 	{
       
   867 	iDb->ReadContactLC((*IdList)[0]);
       
   868 	CContactItem* card2=iDb->ReadContactL((*IdList)[1]);
       
   869 	CleanupStack::PopAndDestroy();	// card1
       
   870 	delete card2;
       
   871 	}
       
   872 
       
   873 //
       
   874 // COomAddNewContact
       
   875 //
       
   876 void COomAddNewContact::PreFailL()
       
   877 	{
       
   878 	iDbEventQueue->Flush();
       
   879 	iNewContactId=KNullContactId;
       
   880 	}
       
   881 
       
   882 void COomAddNewContact::FailL()
       
   883 	{
       
   884 	CContactCard* card=CContactCard::NewL();
       
   885 	CleanupStack::PushL(card);
       
   886 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("OOM"),EFalse);
       
   887 	iNewContactId=iDb->AddNewContactL(*card);
       
   888 	CleanupStack::PopAndDestroy(); // card
       
   889 	}
       
   890 
       
   891 void COomAddNewContact::ClearUpL()
       
   892 	{
       
   893 	RecoverL(ETrue); //Wait for recover complete
       
   894 
       
   895 	if (iNewContactId!=KNullContactId)
       
   896 		iDb->DeleteContactL(iNewContactId);
       
   897 	}
       
   898 
       
   899 TBool COomAddNewContact::Skip(TInt aCount, TOomFailureModes aMode) const
       
   900 	{
       
   901 	// Skipped because KErrCorrupt when recovering.
       
   902 	if (aMode==KOomFailFileServerGeneral) return aCount==10;
       
   903 	if (aMode==KOomFailFileServerOom) return aCount==10;
       
   904 	return EFalse;
       
   905 	}
       
   906 
       
   907 //
       
   908 // COomReadContactTextDef
       
   909 //
       
   910 
       
   911 void COomReadContactTextDef::FailL()
       
   912 	{
       
   913 	CContactTextDef *textDef=CContactTextDef::NewLC();
       
   914 	textDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName,_L("==")));
       
   915 	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName,_L(", ")));
       
   916 	TBuf<0x100> buf;
       
   917 	iDb->ReadContactTextDefL((*IdList)[1],buf,textDef);
       
   918 	iDb->ReadContactTextDefL((*IdList)[3],buf,textDef);
       
   919 	CleanupStack::PopAndDestroy();	// textDef
       
   920 	}
       
   921 
       
   922 //
       
   923 // COomOpenAndCloseContact
       
   924 //
       
   925 
       
   926 void COomOpenAndCloseContact::FailL()
       
   927 	{
       
   928 	CContactItem* card=iDb->OpenContactL((*IdList)[0]);
       
   929 	delete card;
       
   930 	iDb->CloseContactL((*IdList)[0]);
       
   931 	}
       
   932 
       
   933 //
       
   934 // COomOpenAndCloseContactX
       
   935 //
       
   936 
       
   937 void COomOpenAndCloseContactX::FailL()
       
   938 	{
       
   939 	CContactItem* card=iDb->OpenContactLX((*IdList)[0]);
       
   940 	CleanupStack::PushL(card);
       
   941 	CleanupStack::PushL(HBufC::NewL(10));	// any old alloc to trigger a fail between the open and close
       
   942 	iDb->CloseContactL((*IdList)[0]);
       
   943 	CleanupStack::PopAndDestroy(2); // HBufC & card
       
   944 	CleanupStack::Pop(); // card close
       
   945 	}
       
   946 
       
   947 //
       
   948 // COomOpenModifyAndCommitContact
       
   949 //
       
   950 
       
   951 void COomOpenModifyAndCommitContact::PreFailL()
       
   952 	{
       
   953 	iCard=iDb->OpenContactL((*IdList)[1]);
       
   954 	iDbEventQueue->Flush();
       
   955 	}
       
   956 
       
   957 void COomOpenModifyAndCommitContact::FailL()
       
   958 	{
       
   959 	SetNameL(*iCard,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,_L("Hacked name"),EFalse);
       
   960 	iDb->CommitContactL(*iCard);
       
   961 	}
       
   962 
       
   963 void COomOpenModifyAndCommitContact::ClearUpL()
       
   964 	{
       
   965 	iDb->CloseContactL((*IdList)[1]);
       
   966 	delete iCard;
       
   967 	RecoverL(ETrue); //wait for event
       
   968 	}
       
   969 
       
   970 TBool COomOpenModifyAndCommitContact::Skip(TInt aCount, TOomFailureModes aMode) const
       
   971 	{
       
   972 	// KErrCorrupt when recovering
       
   973 	if (aMode==KOomFailFileServerGeneral) return aCount==11;
       
   974 	if (aMode==KOomFailFileServerOom) return aCount==11;
       
   975 	return(EFalse);
       
   976 	}
       
   977 
       
   978 //
       
   979 // COomDeleteContact
       
   980 //
       
   981 
       
   982 void COomDeleteContact::PreFailL()
       
   983 	{
       
   984 	iStartCount=iDb->CountL();
       
   985 	CContactCard* card=CContactCard::NewL();
       
   986 	CleanupStack::PushL(card);
       
   987 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("DeleteMe"),EFalse);
       
   988 	iNewContactId=iDb->AddNewContactL(*card);
       
   989 	CleanupStack::PopAndDestroy(); // card
       
   990 	}
       
   991 
       
   992 void COomDeleteContact::FailL()
       
   993 	{
       
   994 	iDb->DeleteContactL(iNewContactId);
       
   995 	}
       
   996 
       
   997 void COomDeleteContact::ClearUpL()
       
   998 	{
       
   999 	RecoverL();
       
  1000 	TRAP_IGNORE(iDb->DeleteContactL(iNewContactId));
       
  1001 	test(iStartCount==iDb->CountL());
       
  1002 	}
       
  1003 
       
  1004 TBool COomDeleteContact::Skip(TInt aCount, TOomFailureModes aMode) const
       
  1005 	{
       
  1006 	// KErrCorrupt when recovering.
       
  1007 	if (aMode==KOomFailFileServerGeneral) return aCount==11;
       
  1008 	if (aMode==KOomFailFileServerOom) return aCount==11;
       
  1009 	return(EFalse);
       
  1010 	}
       
  1011 
       
  1012 //
       
  1013 // COomDeleteContacts
       
  1014 //
       
  1015 
       
  1016 void COomDeleteContacts::PreFailL()
       
  1017 	{
       
  1018 	iStartCount=iDb->CountL();
       
  1019 	CContactCard* card=CContactCard::NewL();
       
  1020 	CleanupStack::PushL(card);
       
  1021 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("DeleteMe"),EFalse);
       
  1022 	iNewContactIds=CContactIdArray::NewL();
       
  1023 	iNewContactIds->AddL(iDb->AddNewContactL(*card));
       
  1024 	iNewContactIds->AddL(iDb->AddNewContactL(*card));
       
  1025 	iNewContactIds->AddL(iDb->AddNewContactL(*card));
       
  1026 	CleanupStack::PopAndDestroy(); // card
       
  1027 	}
       
  1028 
       
  1029 void COomDeleteContacts::FailL()
       
  1030 	{
       
  1031 	iDb->DeleteContactsL(*iNewContactIds);
       
  1032 	}
       
  1033 
       
  1034 void COomDeleteContacts::ClearUpL()
       
  1035 	{
       
  1036 	RecoverL();
       
  1037 	for(TInt loop=0;loop<iNewContactIds->Count();loop++)
       
  1038 		{
       
  1039 		TRAP_IGNORE(iDb->DeleteContactL((*iNewContactIds)[loop]));
       
  1040 		}
       
  1041 	delete iNewContactIds;
       
  1042 	test(iStartCount==iDb->CountL());
       
  1043 	}
       
  1044 
       
  1045 TBool COomDeleteContacts::Skip(TInt /*aCount*/, TOomFailureModes aMode) const
       
  1046 	{
       
  1047 	// KErrCorrupt when recovering.
       
  1048 	// This fails on one test case (usually around 60 - 70) but which
       
  1049 	// one changes between builds.
       
  1050 	if (aMode==KOomFailFileServerGeneral) return ETrue;
       
  1051 	if (aMode==KOomFailFileServerOom) return ETrue;
       
  1052 	return EFalse;
       
  1053 	}
       
  1054 
       
  1055 //
       
  1056 // COomCompact
       
  1057 //
       
  1058 
       
  1059 void COomCompact::FailL()
       
  1060 	{
       
  1061 	iDb->CompactL();
       
  1062 	}
       
  1063 
       
  1064 void COomCompact::ClearUpL()
       
  1065 	{
       
  1066 	RecoverL();
       
  1067 	}
       
  1068 
       
  1069 //
       
  1070 // COomExportSelectedContacts
       
  1071 //
       
  1072 
       
  1073 COomExportSelectedContacts::~COomExportSelectedContacts()
       
  1074 	{
       
  1075 	delete iIdList;
       
  1076 	}
       
  1077 
       
  1078 void COomExportSelectedContacts::ConstructL()
       
  1079 	{
       
  1080 	COomFailBase::ConstructL();
       
  1081 //
       
  1082 	CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
       
  1083 	CleanupStack::PushL(sortOrder);
       
  1084 	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName));
       
  1085 	iDb->SortL(sortOrder);
       
  1086 	CleanupStack::Pop(); // sortOrder
       
  1087 //
       
  1088 	iIdList=CContactIdArray::NewL(iDb->SortedItemsL());
       
  1089 	while(iIdList->Count()>2)
       
  1090 		iIdList->Remove(0);	// only leave 2 in the array
       
  1091 	}
       
  1092 
       
  1093 void COomExportSelectedContacts::PreFailL()
       
  1094 	{
       
  1095 	iStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\TErrorExport"),EFileWrite);
       
  1096    	iStore->SetTypeL(KDirectFileStoreLayoutUid);
       
  1097 	iStreamId=iOutStream.CreateL(*iStore);
       
  1098 	}
       
  1099 
       
  1100 void COomExportSelectedContacts::FailL()
       
  1101 	{
       
  1102    	iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl),*iIdList,iOutStream,CContactDatabase::ETTFormat);
       
  1103 	}
       
  1104 
       
  1105 void COomExportSelectedContacts::ClearUpL()
       
  1106 	{
       
  1107 	RecoverL();
       
  1108 	iOutStream.CommitL();
       
  1109 	iStore->SetRootL(iStreamId);
       
  1110 	iStore->CommitL();  	
       
  1111 	iOutStream.Close();
       
  1112 	delete iStore;
       
  1113 	}
       
  1114 
       
  1115 TBool COomExportSelectedContacts::ErrorOk(TOomFailureModes aMode, TInt aIteration, TInt aError)
       
  1116 	{
       
  1117 	// LoadPluginL interprets all file server errors as KErrNotFound, except KErrNoMemory.
       
  1118 	if(aMode == KOomFailFileServerGeneral)
       
  1119 		{
       
  1120 		if (aError == KErrGeneral || aError == KErrNotFound)
       
  1121 			return ETrue;
       
  1122 		
       
  1123 		test.Printf(_L("ErrorOk test - Mode %i, iteration %i, error %i"), aMode, aIteration, aError);
       
  1124 		return EFalse;
       
  1125 		}
       
  1126 	else if(aMode == KOomFailFileServerOom)
       
  1127 		{
       
  1128 		if (aError == KErrNoMemory || aError == KErrNotFound)
       
  1129 			return ETrue;
       
  1130 
       
  1131 		test.Printf(_L("ErrorOk test - Mode %i, iteration %i, error %i"), aMode, aIteration, aError);
       
  1132 		return EFalse;
       
  1133 		}
       
  1134 	else
       
  1135 		{
       
  1136 		return(COomFailBase::ErrorOk(aMode, aIteration, aError));
       
  1137 		}
       
  1138 	}
       
  1139 
       
  1140 //
       
  1141 // COoomImportContacts
       
  1142 //
       
  1143 
       
  1144 COomImportContacts::~COomImportContacts()
       
  1145 	{
       
  1146 	TRAP_IGNORE(iDb->DeleteContactL(iDeleteMeId));
       
  1147 	delete iStore;
       
  1148 	}
       
  1149 
       
  1150 void COomImportContacts::ConstructL()
       
  1151 	{
       
  1152 //zzz Need a ttformat version of this
       
  1153 	COomFailBase::ConstructL();
       
  1154 //
       
  1155 	CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
       
  1156 	CleanupStack::PushL(sortOrder);
       
  1157 	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName));
       
  1158 	iDb->SortL(sortOrder);
       
  1159 	CleanupStack::Pop(); // sortOrder
       
  1160 //
       
  1161 	iStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\TErrorExport"),EFileWrite);
       
  1162   	iStore->SetTypeL(KDirectFileStoreLayoutUid);
       
  1163 	RStoreWriteStream outStream;
       
  1164 	iStreamId=outStream.CreateLC(*iStore);
       
  1165 //
       
  1166 	CContactIdArray *idList=CContactIdArray::NewLC();
       
  1167 	CContactCard *card=CContactCard::NewLC();
       
  1168 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("ABCDE"),EFalse);
       
  1169 	SetNameL(*card,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,_L("123"),EFalse);
       
  1170 	idList->AddL(iDb->AddNewContactL(*card));
       
  1171 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("ZYX"),EFalse);
       
  1172 	SetNameL(*card,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,_L("987"),EFalse);
       
  1173 	idList->AddL(iDb->AddNewContactL(*card));
       
  1174 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("QQQQ"),EFalse);
       
  1175 	SetNameL(*card,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,_L("666"),EFalse);
       
  1176 	idList->AddL(iDb->AddNewContactL(*card));
       
  1177 	CleanupStack::PopAndDestroy();	// card
       
  1178    	iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl),*idList,outStream,CContactDatabase::EExcludeUid);
       
  1179 	iDb->DeleteContactL((*idList)[0]);
       
  1180 	iDb->DeleteContactL((*idList)[1]);
       
  1181 	iDeleteMeId=(*idList)[2];	// Leave this one in the DB so it is imported as an updated entry
       
  1182 //
       
  1183 	outStream.CommitL();
       
  1184 	iStore->SetRootL(iStreamId);
       
  1185 	iStore->CommitL();  	
       
  1186 	CleanupStack::PopAndDestroy(2);	// outStream,idList
       
  1187 	iOldRecordCount=iDb->CountL();
       
  1188 	}
       
  1189 
       
  1190 void COomImportContacts::PreFailL()
       
  1191 	{
       
  1192 	iInStream.OpenL(*iStore,iStreamId);
       
  1193 	}
       
  1194 
       
  1195 void COomImportContacts::FailL()
       
  1196 	{
       
  1197 	TBool success=EFalse;
       
  1198 	iImportedContacts=iDb->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),iInStream,success,0);
       
  1199 	test(iImportedContacts->Count()==3);
       
  1200 	test(success);
       
  1201 	}
       
  1202 
       
  1203 void COomImportContacts::ClearUpL()
       
  1204 	{
       
  1205 	RecoverL();
       
  1206 	if (iImportedContacts)
       
  1207 		{
       
  1208 		while(iImportedContacts->Count()>0)
       
  1209 			{
       
  1210 			iDb->DeleteContactL((*iImportedContacts)[0]->Id());
       
  1211 			delete (*iImportedContacts)[0];
       
  1212 			iImportedContacts->Delete(0);
       
  1213 			}
       
  1214 		delete iImportedContacts;
       
  1215 		iImportedContacts=NULL;
       
  1216 		}
       
  1217 	test(iDb->CountL()==iOldRecordCount);
       
  1218 	iInStream.Close();
       
  1219 	}
       
  1220 
       
  1221 TBool COomImportContacts::Skip(TInt, TOomFailureModes aMode) const
       
  1222 	{
       
  1223 	// KErrCorrupt when recovering
       
  1224 	// This test only fails on one or two counts in each loop through the harness,
       
  1225 	// but the particular counts on which it fails seem to vary with each execution.
       
  1226 	if (aMode==KOomFailFileServerGeneral) return ETrue;
       
  1227 	if (aMode==KOomFailFileServerOom) return ETrue;
       
  1228 	return(EFalse);
       
  1229 	}
       
  1230 
       
  1231 //
       
  1232 // COomFind
       
  1233 //
       
  1234 
       
  1235 void COomFind::FailL()
       
  1236 	{
       
  1237 	CContactItemFieldDef *fieldDef=new(ELeave) CContactItemFieldDef;
       
  1238 	CleanupStack::PushL(fieldDef);
       
  1239 	fieldDef->AppendL(KUidContactFieldFamilyName);
       
  1240 	CContactIdArray* ids=iDb->FindLC(_L("NAME"),fieldDef);
       
  1241 	test(ids->Count()==5);
       
  1242 	CleanupStack::PopAndDestroy(2);	// ids & fieldDef
       
  1243 	}
       
  1244 
       
  1245 //
       
  1246 // COomFindInTextDef
       
  1247 //
       
  1248 
       
  1249 LOCAL_C TInt findWordSplitterL(TAny *aParams)
       
  1250 	{
       
  1251 	SFindInTextDefWordParser *parser=(SFindInTextDefWordParser *)aParams;
       
  1252 	const TText *ptr=parser->iSearchString->Ptr();
       
  1253 	const TText *end=ptr+parser->iSearchString->Length();
       
  1254 	const TText *startOfWord=NULL;
       
  1255 	FOREVER
       
  1256 		{
       
  1257 		if (ptr==end || !TChar(*ptr).IsAlphaDigit())
       
  1258 			{
       
  1259 			if (startOfWord)
       
  1260 				{
       
  1261 				TPtrC addWord(startOfWord,ptr-startOfWord);
       
  1262 				parser->iWordArray->AppendL(addWord);
       
  1263 				startOfWord=NULL;
       
  1264 				}
       
  1265 			if (ptr==end)
       
  1266 				break;
       
  1267 			}
       
  1268 		else if (!startOfWord)
       
  1269 			startOfWord=ptr;
       
  1270 		ptr++;
       
  1271 		}
       
  1272 	return(KErrNone);
       
  1273 	}
       
  1274 
       
  1275 COomFindInTextDef::~COomFindInTextDef()
       
  1276 	{
       
  1277 	delete iTextDef;
       
  1278 	delete iFindWords;
       
  1279 	}
       
  1280 
       
  1281 void COomFindInTextDef::ConstructL()
       
  1282 	{
       
  1283 	COomFailBase::ConstructL();
       
  1284 	iTextDef=CContactTextDef::NewL();
       
  1285 	iTextDef->AppendL(KUidContactFieldFamilyName);
       
  1286 	iTextDef->AppendL(KUidContactFieldGivenName);
       
  1287 	iFindWords=new(ELeave) CDesCArrayFlat(2);
       
  1288 	iFindWords->AppendL(_L("NAME"));
       
  1289 	iFindWords->AppendL(_L("GivenName"));
       
  1290 	}
       
  1291 
       
  1292 void COomFindInTextDef::FailL()
       
  1293 	{
       
  1294 	TCallBack callBack(findWordSplitterL);
       
  1295 	CContactIdArray* ids=iDb->FindInTextDefLC(*iFindWords,iTextDef,callBack);
       
  1296 	test(ids->Count()==5);
       
  1297 	CleanupStack::PopAndDestroy();	// ids
       
  1298 	}
       
  1299 
       
  1300 //
       
  1301 // COomFindAsync
       
  1302 //
       
  1303 
       
  1304 class CAsyncFinder : public CBase, public MIdleFindObserver
       
  1305 	{
       
  1306 public:
       
  1307 	~CAsyncFinder();
       
  1308 	void ConstructL(CContactDatabase *aContactDatabase, const TDesC& aText,const CContactItemFieldDef *aFieldDef);
       
  1309 	void ConstructL(CContactDatabase *aContactDatabase, const CDesCArrayFlat &iFindWords,CContactTextDef* iTextDef, const TCallBack &aCallBack);
       
  1310 	inline CContactIdArray *TakeContactIds() {return(iFinder->TakeContactIds());};
       
  1311 	inline TInt Error() const {return(iFinder->Error());};
       
  1312 protected:
       
  1313 // from MIdleFindObserver
       
  1314 	void IdleFindCallback();
       
  1315 private:
       
  1316 	CIdleFinder *iFinder;
       
  1317 	};
       
  1318 
       
  1319 CAsyncFinder::~CAsyncFinder()
       
  1320 	{
       
  1321 	delete iFinder;
       
  1322 	}
       
  1323 
       
  1324 void CAsyncFinder::ConstructL(CContactDatabase *aContactDatabase, const TDesC& aText,const CContactItemFieldDef *aFieldDef)
       
  1325 	{
       
  1326 	iFinder=aContactDatabase->FindAsyncL(aText, aFieldDef, this);
       
  1327 	}
       
  1328 
       
  1329 void CAsyncFinder::ConstructL(CContactDatabase *aContactDatabase, const CDesCArrayFlat &aFindWords,CContactTextDef* iTextDef, const TCallBack &aCallBack)
       
  1330 	{
       
  1331 	iFinder=aContactDatabase->FindInTextDefAsyncL(aFindWords, iTextDef, this, aCallBack);
       
  1332 	}
       
  1333 
       
  1334 void CAsyncFinder::IdleFindCallback()
       
  1335 	{
       
  1336 	if (iFinder->IsComplete())
       
  1337 		CActiveScheduler::Stop();
       
  1338 	}
       
  1339 
       
  1340 void COomFindAsync::FailL()
       
  1341 	{
       
  1342 	CAsyncFinder *finder=new(ELeave) CAsyncFinder;
       
  1343 	CleanupStack::PushL(finder);
       
  1344 	finder->ConstructL(iDb,_L("NAME"),NULL);
       
  1345 	CActiveScheduler::Start();
       
  1346 	User::LeaveIfError(finder->Error());
       
  1347 	CContactIdArray *ids=finder->TakeContactIds();
       
  1348 	CleanupStack::PushL(ids);
       
  1349 	test(ids->Count()==5);
       
  1350 	CleanupStack::PopAndDestroy(2);	// ids,finder
       
  1351 	}
       
  1352 
       
  1353 //
       
  1354 // COomFindAsyncInTextDef
       
  1355 //
       
  1356 
       
  1357 COomFindAsyncInTextDef::~COomFindAsyncInTextDef()
       
  1358 	{
       
  1359 	delete iTextDef;
       
  1360 	delete iFindWords;
       
  1361 	}
       
  1362 
       
  1363 void COomFindAsyncInTextDef::ConstructL()
       
  1364 	{
       
  1365 	COomFailBase::ConstructL();
       
  1366 	iTextDef=CContactTextDef::NewL();
       
  1367 	iTextDef->AppendL(KUidContactFieldFamilyName);
       
  1368 	iTextDef->AppendL(KUidContactFieldGivenName);
       
  1369 	iFindWords=new(ELeave) CDesCArrayFlat(2);
       
  1370 	iFindWords->AppendL(_L("NAME"));
       
  1371 	iFindWords->AppendL(_L("GivenName"));
       
  1372 	}
       
  1373 
       
  1374 void COomFindAsyncInTextDef::FailL()
       
  1375 	{
       
  1376 	TCallBack callBack(findWordSplitterL);
       
  1377 	CAsyncFinder *finder=new(ELeave) CAsyncFinder;
       
  1378 	CleanupStack::PushL(finder);
       
  1379 	finder->ConstructL(iDb,*iFindWords,NULL,callBack);
       
  1380 	CActiveScheduler::Start();
       
  1381 	User::LeaveIfError(finder->Error());
       
  1382 	CContactIdArray *ids=finder->TakeContactIds();
       
  1383 	CleanupStack::PushL(ids);
       
  1384 //	test(ids->Count()==5);
       
  1385 	CleanupStack::PopAndDestroy(2);	// ids,finder
       
  1386 	}
       
  1387 
       
  1388 //
       
  1389 // COomSort
       
  1390 //
       
  1391 
       
  1392 TBool COomSort::Skip(TInt /*aCount*/, TOomFailureModes aMode) const
       
  1393 	{
       
  1394 	if(aMode == KOomFailFileServerGeneral)
       
  1395 		return ETrue;
       
  1396 	return ETrue;
       
  1397 	}
       
  1398 void COomSort::FailL()
       
  1399 	{
       
  1400 	CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
       
  1401 	CleanupStack::PushL(sortOrder);
       
  1402 	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName));
       
  1403 	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldGivenName));
       
  1404 	iDb->SortL(sortOrder);
       
  1405 	CleanupStack::Pop(); // sortOrder
       
  1406 	const CContactIdArray *ids=iDb->SortedItemsL();
       
  1407 	test(ids->Count()>0);
       
  1408 	if (iPrevCount>0)
       
  1409 		test(ids->Count()==iPrevCount);
       
  1410 	else
       
  1411 		iPrevCount=ids->Count();
       
  1412 	}
       
  1413 
       
  1414 //
       
  1415 // COomSortArray
       
  1416 //
       
  1417 
       
  1418 COomSortArray::~COomSortArray()
       
  1419 	{
       
  1420 	delete iSortOrder;
       
  1421 	delete iIdArray;
       
  1422 	}
       
  1423 
       
  1424 void COomSortArray::ConstructL()
       
  1425 	{
       
  1426 	COomFailBase::ConstructL();
       
  1427 	iSortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
       
  1428 	iSortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName));
       
  1429 	iSortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldGivenName));
       
  1430 	iIdArray=CContactIdArray::NewL(iDb->SortedItemsL());
       
  1431 	}
       
  1432 
       
  1433 void COomSortArray::FailL()
       
  1434 	{
       
  1435 	CContactIdArray *sortedIds=iDb->SortArrayL(iIdArray,iSortOrder);
       
  1436 	test(sortedIds->Count()==iIdArray->Count());
       
  1437 	delete sortedIds;
       
  1438 	}
       
  1439 
       
  1440 //
       
  1441 // COomCompress
       
  1442 //
       
  1443 
       
  1444 void COomCompress::Step(TInt )
       
  1445 	{
       
  1446 	}
       
  1447 
       
  1448 void COomCompress::HandleError(TInt aError)
       
  1449 	{
       
  1450 	iRecievedError=aError;
       
  1451 	}
       
  1452 
       
  1453 void COomCompress::PreFailL()
       
  1454 	{
       
  1455 	CContactCard* card=CContactCard::NewL();
       
  1456 	CleanupStack::PushL(card);
       
  1457 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("DeleteMe"),EFalse);
       
  1458 	iDb->DeleteContactL(iDb->AddNewContactL(*card));	// Make sure a compress is required
       
  1459 	iDb->DeleteContactL(iDb->AddNewContactL(*card));
       
  1460 	iDb->DeleteContactL(iDb->AddNewContactL(*card));
       
  1461 	iDb->DeleteContactL(iDb->AddNewContactL(*card));
       
  1462 	CleanupStack::PopAndDestroy(); // card
       
  1463 	iRecievedError=KErrNone;
       
  1464 	}
       
  1465 
       
  1466 void COomCompress::FailL()
       
  1467 	{
       
  1468 	CContactActiveCompress* compressor=iDb->CreateCompressorLC();
       
  1469 	compressor->SetObserver(this);
       
  1470 	while(compressor->Step()) {};
       
  1471 	test(iRecievedError==compressor->Error());
       
  1472 	User::LeaveIfError(compressor->Error());
       
  1473 	CleanupStack::PopAndDestroy();	// compressor
       
  1474 	}
       
  1475 
       
  1476 void COomCompress::ClearUpL()
       
  1477 	{
       
  1478 	RecoverL();
       
  1479 	}
       
  1480 
       
  1481 TBool COomCompress::Skip(TInt /*aCount*/, TOomFailureModes aMode) const
       
  1482 	{
       
  1483 	// KErrCorrupt.
       
  1484 	// This fails on 3 or 4 tests in each run, but which ones varies between executions.
       
  1485 	if (aMode==KOomFailFileServerGeneral || aMode==KOomFailFileServerOom) return ETrue;
       
  1486 	return(EFalse);
       
  1487 	}
       
  1488 
       
  1489 //
       
  1490 // COomRecover
       
  1491 //
       
  1492 
       
  1493 void COomRecover::Step(TInt )
       
  1494 	{
       
  1495 	}
       
  1496 
       
  1497 void COomRecover::HandleError(TInt aError)
       
  1498 	{
       
  1499 	iRecievedError=aError;
       
  1500 	}
       
  1501 
       
  1502 void COomRecover::PreFailL()
       
  1503 	{
       
  1504 	iRecievedError = KErrNone;
       
  1505 	if (iDb->IsDamaged())
       
  1506 		{
       
  1507 		doRecoverL();
       
  1508 		}
       
  1509 	iDb->DamageDatabaseL(0x666);
       
  1510 	}
       
  1511 
       
  1512 void COomRecover::doRecoverL()
       
  1513 	{
       
  1514 	CContactActiveRecover* recover=iDb->CreateRecoverLC();
       
  1515 	recover->SetObserver(this);
       
  1516 	while(recover->Step()) {};
       
  1517 	test(iRecievedError==recover->Error());
       
  1518 	User::LeaveIfError(recover->Error());
       
  1519 	CleanupStack::PopAndDestroy();	// recover
       
  1520 	}
       
  1521 
       
  1522 void COomRecover::FailL()
       
  1523 	{
       
  1524 	test(DbShouldBeInDamagedState(iDb) );
       
  1525 	doRecoverL();
       
  1526 	}
       
  1527 
       
  1528 TBool COomRecover::Skip(TInt, TOomFailureModes aMode) const
       
  1529 	{
       
  1530 	// KErrCorrupt
       
  1531 	// This test usually only fails on one value of count, but exactly which
       
  1532 	// one it will be varies between executions of the harness. Not good.
       
  1533 	if (aMode==KOomFailFileServerGeneral) return ETrue;
       
  1534 	if (aMode==KOomFailFileServerOom) return ETrue;
       
  1535 	if (aMode==KOomFailDbs) return ETrue; //fixes INC052869 - remove for DEF054579
       
  1536 	return(EFalse);
       
  1537 	}
       
  1538 
       
  1539 //
       
  1540 // COomCloseOpenTables
       
  1541 //
       
  1542 
       
  1543 void COomCloseOpenTables::FailL()
       
  1544 	{
       
  1545 	iDb->CloseTables();
       
  1546 	iDbEventQueue->Clear();
       
  1547 	}
       
  1548 
       
  1549 //
       
  1550 // COomViewDefInternalize
       
  1551 //
       
  1552 
       
  1553 COomViewDefInternalize::~COomViewDefInternalize()
       
  1554 	{
       
  1555 	delete iBufStore;
       
  1556 	}
       
  1557 
       
  1558 void COomViewDefInternalize::ConstructL()
       
  1559 	{
       
  1560 	COomFailBase::ConstructL();
       
  1561 	CContactItemViewDef* itemViewDef=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
       
  1562 	itemViewDef->AddL(KUidContactFieldCompanyName);
       
  1563 	itemViewDef->AddL(KUidContactFieldGivenName);
       
  1564 	CContactViewDef* viewDef=CContactViewDef::NewL(itemViewDef);
       
  1565 	CleanupStack::Pop();	// itemViewDef
       
  1566 	CleanupStack::PushL(viewDef);	// viewDef
       
  1567 //
       
  1568 	iBufStore=CBufStore::NewL(0x400);
       
  1569 	RStoreWriteStream writeStream;
       
  1570 	iStreamId=writeStream.CreateLC(*iBufStore);
       
  1571 	viewDef->ExternalizeL(writeStream);
       
  1572 	CleanupStack::PopAndDestroy(2);	// writeStream,viewDef
       
  1573 	}
       
  1574 
       
  1575 void COomViewDefInternalize::PreFailL()
       
  1576 	{
       
  1577 	iReadStream.OpenL(*iBufStore,iStreamId);
       
  1578 	}
       
  1579 
       
  1580 void COomViewDefInternalize::FailL()
       
  1581 	{
       
  1582 	CContactViewDef* viewDef=CContactViewDef::NewLC();
       
  1583 	viewDef->InternalizeL(iReadStream);
       
  1584 	CleanupStack::PopAndDestroy();	// viewDef
       
  1585 	}
       
  1586 
       
  1587 void COomViewDefInternalize::ClearUpL()
       
  1588 	{
       
  1589 	RecoverL();
       
  1590 	iReadStream.Close();
       
  1591 	}
       
  1592 
       
  1593 //
       
  1594 // COomViewDefExternalize
       
  1595 //
       
  1596 
       
  1597 COomViewDefExternalize::~COomViewDefExternalize()
       
  1598 	{
       
  1599 	delete iBufStore;
       
  1600 	}
       
  1601 
       
  1602 void COomViewDefExternalize::ConstructL()
       
  1603 	{
       
  1604 	COomFailBase::ConstructL();
       
  1605 	iBufStore=CBufStore::NewL(0x400);
       
  1606 	}
       
  1607 
       
  1608 void COomViewDefExternalize::PreFailL()
       
  1609 	{
       
  1610 	iStreamId=iWriteStream.CreateL(*iBufStore);
       
  1611 	iFailed=ETrue;
       
  1612 	}
       
  1613 
       
  1614 void COomViewDefExternalize::FailL()
       
  1615 	{
       
  1616 	CContactItemViewDef* itemViewDef=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
       
  1617 	itemViewDef->AddL(KUidContactFieldCompanyName);
       
  1618 	itemViewDef->AddL(KUidContactFieldGivenName);
       
  1619 	CContactViewDef* viewDef=CContactViewDef::NewL(itemViewDef);
       
  1620 	CleanupStack::Pop();	// itemViewDef
       
  1621 	CleanupStack::PushL(viewDef);	// viewDef
       
  1622 	viewDef->ExternalizeL(iWriteStream);
       
  1623 	CleanupStack::PopAndDestroy();	// viewDef
       
  1624 	iFailed=EFalse;
       
  1625 	}
       
  1626 
       
  1627 void COomViewDefExternalize::ClearUpL()
       
  1628 	{
       
  1629 	RecoverL();
       
  1630 	iWriteStream.Close();
       
  1631 	if (!iFailed)
       
  1632 		{
       
  1633 		RStoreReadStream readStream;
       
  1634 		readStream.OpenL(*iBufStore,iStreamId);
       
  1635 		CContactViewDef* viewDef=CContactViewDef::NewLC();
       
  1636 		viewDef->InternalizeL(readStream);
       
  1637 		CleanupStack::PopAndDestroy();	// viewDef
       
  1638 		readStream.Close();
       
  1639 		}
       
  1640 	iBufStore->Delete(iStreamId);
       
  1641 	}
       
  1642 
       
  1643 //
       
  1644 // COomFieldSetStore
       
  1645 //
       
  1646 
       
  1647 COomFieldSetStore::~COomFieldSetStore()
       
  1648 	{
       
  1649 	delete iItemFieldSet;
       
  1650 	delete iBufStore;
       
  1651 	delete iBlobStore;
       
  1652 	delete iTextStore;
       
  1653 	}
       
  1654 
       
  1655 void COomFieldSetStore::ConstructL()
       
  1656 	{
       
  1657 	COomFailBase::ConstructL();
       
  1658 	iBufStore=CBufStore::NewL(0x400);
       
  1659 	iBlobStore=CBufStore::NewL(0x400);
       
  1660 	iTextStore=CBufStore::NewL(0x400);
       
  1661 	CContactItemField* itemField=CContactItemField::NewLC(KStorageTypeText, KUidContactFieldAddress);
       
  1662 	iItemFieldSet=CContactItemFieldSet::NewL();
       
  1663 	iItemFieldSet->AddL(*itemField);
       
  1664 	CleanupStack::Pop();	// itemField
       
  1665 	}
       
  1666 
       
  1667 void COomFieldSetStore::FailL()
       
  1668 	{
       
  1669 	iStreamId=KNullStreamId;
       
  1670 	RStoreWriteStream stream;
       
  1671 	stream.CreateLC(*iTextStore);
       
  1672 	iStreamId=iItemFieldSet->StoreL(*iBufStore,stream,*iBlobStore);
       
  1673 	CleanupStack::PopAndDestroy();
       
  1674 	}
       
  1675 
       
  1676 void COomFieldSetStore::ClearUpL()
       
  1677 	{
       
  1678 	RecoverL();
       
  1679 	iBufStore->Delete(iStreamId);
       
  1680 	}
       
  1681 
       
  1682 //
       
  1683 // COomFieldSetRestore
       
  1684 //
       
  1685 
       
  1686 COomFieldSetRestore::~COomFieldSetRestore()
       
  1687 	{
       
  1688 	delete iBufStore;
       
  1689 	delete iTextStore;
       
  1690 	delete iBlobStore;
       
  1691 	delete iViewDef;
       
  1692 	}
       
  1693 
       
  1694 void COomFieldSetRestore::ConstructL()
       
  1695 	{
       
  1696 	COomFailBase::ConstructL();
       
  1697 	iBufStore=CBufStore::NewL(0x400);
       
  1698 	iTextStore=CBufStore::NewL(0x400);
       
  1699 	iBlobStore=CBufStore::NewL(0x400);
       
  1700 	CContactItemViewDef* itemViewDef=CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
       
  1701 	itemViewDef->AddL(KUidContactFieldAddress);
       
  1702 	iViewDef=CContactViewDef::NewL(itemViewDef);
       
  1703 	CleanupStack::Pop();	// itemViewDef
       
  1704 	}
       
  1705 
       
  1706 void COomFieldSetRestore::PreFailL()
       
  1707 	{
       
  1708 	CContactItemFieldSet *itemFieldSet=CContactItemFieldSet::NewLC();
       
  1709 	CContactItemField* itemField=CContactItemField::NewLC(KStorageTypeText, KUidContactFieldAddress);
       
  1710 	itemFieldSet->AddL(*itemField);
       
  1711 	RStoreWriteStream stream;
       
  1712 	iTextStreamId=stream.CreateLC(*iTextStore);
       
  1713 	iStreamId=itemFieldSet->StoreL(*iBufStore,stream,*iBlobStore);
       
  1714 	CleanupStack::PopAndDestroy();	// stream
       
  1715 	CleanupStack::Pop();	// itemField
       
  1716 	CleanupStack::PopAndDestroy();	// itemFieldSet
       
  1717 	}
       
  1718 
       
  1719 void COomFieldSetRestore::FailL()
       
  1720 	{
       
  1721 	CContactItemFieldSet *itemFieldSet=CContactItemFieldSet::NewLC();
       
  1722 	RStoreReadStream stream;
       
  1723 	stream.OpenLC(*iTextStore,iTextStreamId);
       
  1724 	itemFieldSet->RestoreL(*iBufStore,iStreamId,iBlobStore,iViewDef->ItemDef(),stream);
       
  1725 	CleanupStack::PopAndDestroy(2);	// itemFieldSet
       
  1726 	}
       
  1727 
       
  1728 void COomFieldSetRestore::ClearUpL()
       
  1729 	{
       
  1730 	RecoverL();
       
  1731 	iBufStore->Delete(iStreamId);
       
  1732 	}
       
  1733 
       
  1734 //
       
  1735 // COomContactCardClone
       
  1736 //
       
  1737 
       
  1738 COomContactCardClone::~COomContactCardClone()
       
  1739 	{
       
  1740 	delete iSourceCard;
       
  1741 	}
       
  1742 
       
  1743 void COomContactCardClone::ConstructL()
       
  1744 	{
       
  1745 	COomFailBase::ConstructL();
       
  1746 	iSourceCard=CContactCard::NewL();
       
  1747 	CContactItemField *field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldAddress);
       
  1748 	iSourceCard->AddFieldL(*field);
       
  1749 	CleanupStack::Pop();	// field
       
  1750 	field=CContactItemField::NewLC(KStorageTypeDateTime,TUid::Uid(0x123));
       
  1751 	iSourceCard->AddFieldL(*field);
       
  1752 	CleanupStack::Pop();	// field
       
  1753 	}
       
  1754 
       
  1755 void COomContactCardClone::FailL()
       
  1756 	{
       
  1757 	CContactCard::NewLC(iSourceCard);
       
  1758 	CleanupStack::PopAndDestroy();	// card
       
  1759 	}
       
  1760 
       
  1761 //
       
  1762 // COomContactChangeNotifier
       
  1763 //
       
  1764 
       
  1765 COomContactChangeNotifier::COomNotificationRec* COomContactChangeNotifier::COomNotificationRec::NewL()
       
  1766 	{ // static
       
  1767 	COomContactChangeNotifier::COomNotificationRec* self=new(ELeave) COomContactChangeNotifier::COomNotificationRec;
       
  1768 	CleanupStack::PushL(self);
       
  1769 	self->ConstructL();
       
  1770 	CleanupStack::Pop();	// self
       
  1771 	return self;
       
  1772 	}
       
  1773 
       
  1774 COomContactChangeNotifier::COomNotificationRec::~COomNotificationRec()
       
  1775 	{
       
  1776 	delete iTimer;
       
  1777 	}
       
  1778 
       
  1779 void COomContactChangeNotifier::COomNotificationRec::ConstructL()
       
  1780 	{
       
  1781 	iTimer=CPeriodic::NewL(0);
       
  1782 	}
       
  1783 
       
  1784 void COomContactChangeNotifier::COomNotificationRec::Wait(TBool aUnknownErrAllowed)
       
  1785 	{
       
  1786 	iWaiting=ETrue;
       
  1787 	iGotMessage=EFalse;
       
  1788 	iUnknownErrAllowed=aUnknownErrAllowed;
       
  1789 	iUnknownChange=EFalse;
       
  1790 	iTimer->Cancel();
       
  1791 	iTimer->Start(500000,500000,TCallBack(TimerCallBackL,this)); // wait for 0.5 second for notification
       
  1792 	CActiveScheduler::Start();
       
  1793 	}
       
  1794 
       
  1795 TInt COomContactChangeNotifier::COomNotificationRec::TimerCallBackL(TAny* aSelf)
       
  1796 	{ // static
       
  1797 	// if this gets called, notification hasn't happened
       
  1798 	if (((COomNotificationRec *)aSelf)->iGotMessage)
       
  1799 		CActiveScheduler::Stop();
       
  1800 	else
       
  1801 		User::Leave(KErrGeneral);
       
  1802 	return 0;
       
  1803 	}
       
  1804 
       
  1805 void COomContactChangeNotifier::COomNotificationRec::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
       
  1806 	{
       
  1807 	if (aEvent.iType==EContactDbObserverEventContactChanged || (iUnknownErrAllowed && aEvent.iType==EContactDbObserverEventUnknownChanges))
       
  1808 		{
       
  1809 		iGotMessage=ETrue;
       
  1810 		iTimer->Cancel();
       
  1811 		if (!iWaiting)
       
  1812 			return;
       
  1813 		if (aEvent.iType==EContactDbObserverEventUnknownChanges)
       
  1814 			iUnknownChange=ETrue;
       
  1815 		CActiveScheduler::Stop();
       
  1816 		delete HBufC::NewL(10);	// Dummy alloc so we can fail inside here
       
  1817 		}
       
  1818 	}
       
  1819 
       
  1820 COomContactChangeNotifier::~COomContactChangeNotifier()
       
  1821 	{
       
  1822 	delete iRec;
       
  1823 	}
       
  1824 
       
  1825 void COomContactChangeNotifier::ConstructL()
       
  1826 	{
       
  1827 	COomFailBase::ConstructL();
       
  1828 	iRec=COomContactChangeNotifier::COomNotificationRec::NewL();
       
  1829 	}
       
  1830 
       
  1831 void COomContactChangeNotifier::PreFailL()
       
  1832 	{
       
  1833 	iItem1=iDb->OpenContactL((*IdList)[0]);
       
  1834 	iItem2=iDb->OpenContactL((*IdList)[1]);
       
  1835 	iItem3=iDb->OpenContactL((*IdList)[2]);
       
  1836 	}
       
  1837 
       
  1838 void COomContactChangeNotifier::FailL()
       
  1839 	{
       
  1840 	CContactChangeNotifier *notify1=CContactChangeNotifier::NewL(*iDb,iRec);
       
  1841 	CleanupStack::PushL(notify1);
       
  1842 	iDb->CommitContactL(*iItem1);
       
  1843 	iDb->CommitContactL(*iItem2);
       
  1844 	iDb->CommitContactL(*iItem3);
       
  1845 	for(TInt loop=0;loop<3;loop++)
       
  1846 		{
       
  1847 		iRec->Wait(ETrue);
       
  1848 		if (iRec->UnknownChange())
       
  1849 			User::Leave(KErrNoMemory);
       
  1850 		}
       
  1851 	CleanupStack::PopAndDestroy(); // notify1
       
  1852 	}
       
  1853 
       
  1854 void COomContactChangeNotifier::ClearUpL()
       
  1855 	{
       
  1856 	RecoverL();
       
  1857 	iDb->CloseContactL(iItem1->Id());
       
  1858 	iDb->CloseContactL(iItem2->Id());
       
  1859 	iDb->CloseContactL(iItem3->Id());
       
  1860 	delete iItem1;
       
  1861 	delete iItem2;
       
  1862 	delete iItem3;
       
  1863 //
       
  1864 	CContactChangeNotifier *notify=CContactChangeNotifier::NewL(*iDb,iRec);
       
  1865 	CleanupStack::PushL(notify);
       
  1866 	CContactItem *item=iDb->OpenContactLX((*IdList)[0]);
       
  1867 	CleanupStack::PushL(item);
       
  1868 	iDb->CommitContactL(*item);
       
  1869 	iRec->Wait(EFalse);	// Check q working again
       
  1870 	CleanupStack::PopAndDestroy(3);	// item, close record, notify
       
  1871 	}
       
  1872 
       
  1873 TBool COomContactChangeNotifier::Skip(TInt aCount, TOomFailureModes aMode) const
       
  1874 	{
       
  1875 	// KErrCorrupt:
       
  1876 	if (aMode==KOomFailFileServerGeneral) return aCount == 5 || aCount == 11 || aCount == 17;
       
  1877 	if (aMode==KOomFailFileServerOom) return aCount == 5 || aCount == 11 || aCount == 17;
       
  1878 	return EFalse;
       
  1879 	}
       
  1880 
       
  1881 //
       
  1882 // COomPhoneNumberLookup
       
  1883 //
       
  1884 
       
  1885 COomPhoneNumberLookup::~COomPhoneNumberLookup()
       
  1886 	{
       
  1887 	delete iAddCard;
       
  1888 	}
       
  1889 
       
  1890 void COomPhoneNumberLookup::ConstructL()
       
  1891 	{
       
  1892 	iAddId=KNullContactId;
       
  1893 	iDb=CContactDatabase::ReplaceL(KDatabaseCreateFileName);
       
  1894 	iDbEventQueue = CContactDbEventQueue::NewL(iDb);
       
  1895 	iAddCard=CContactCard::NewL();
       
  1896 	SetNameL(*iAddCard,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,_L("11223344"),ETrue);
       
  1897 	SetNameL(*iAddCard,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,_L("22334455"),ETrue);
       
  1898 	}
       
  1899 
       
  1900 void COomPhoneNumberLookup::PreFailL()
       
  1901 	{
       
  1902 	iAddId=KNullContactId;
       
  1903 	iAddId=iDb->AddNewContactL(*iAddCard);
       
  1904 	}
       
  1905 
       
  1906 void COomPhoneNumberLookup::FailL()
       
  1907 	{
       
  1908 /*	CContactIdArray *matchArray=iDb->PhoneMatchListL(_L("11223344"));
       
  1909 	CleanupStack::PushL(matchArray);
       
  1910 	test(matchArray->Count()==1);
       
  1911 	test((*matchArray)[0]==iAddId);
       
  1912 	CleanupStack::PopAndDestroy();	// matchArray
       
  1913 	matchArray=iDb->PhoneMatchListL(_L("22334455"));
       
  1914 	CleanupStack::PushL(matchArray);
       
  1915 	test(matchArray->Count()==1);
       
  1916 	test((*matchArray)[0]==iAddId);
       
  1917 	CleanupStack::PopAndDestroy();	// matchArray*/
       
  1918 	}
       
  1919 
       
  1920 void COomPhoneNumberLookup::ClearUpL()
       
  1921 	{
       
  1922 	RecoverL();
       
  1923 	if (iAddId!=KNullContactId)
       
  1924 		iDb->DeleteContactL(iAddId);
       
  1925 	iAddId = KNullContactId;
       
  1926 	iDb->CompactL();
       
  1927 	}
       
  1928 
       
  1929 // 
       
  1930 // COomContactsChangedSince
       
  1931 //
       
  1932 
       
  1933 COomContactsChangedSince::~COomContactsChangedSince()
       
  1934 	{
       
  1935 	TRAP_IGNORE(iDb->DeleteContactL(iNewContactId1));
       
  1936 	TRAP_IGNORE(iDb->DeleteContactL(iNewContactId2));
       
  1937 	}
       
  1938 
       
  1939 void COomContactsChangedSince::ConstructL()
       
  1940 	{
       
  1941 	COomFailBase::ConstructL();
       
  1942 	iBeforeTime.UniversalTime();
       
  1943 	CContactCard* card=CContactCard::NewL();
       
  1944 	CleanupStack::PushL(card);
       
  1945 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("add1"),EFalse);
       
  1946 	iNewContactId1=iDb->AddNewContactL(*card);
       
  1947 	SetNameL(*card,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("add2"),EFalse);
       
  1948 	iNewContactId2=iDb->AddNewContactL(*card);
       
  1949 	CleanupStack::PopAndDestroy(); // card
       
  1950 	}
       
  1951 
       
  1952 void COomContactsChangedSince::FailL()
       
  1953 	{
       
  1954 	CContactIdArray* ids=iDb->ContactsChangedSinceL(iBeforeTime);
       
  1955 	test(ids->Count()==2);
       
  1956 	delete ids;
       
  1957 	}
       
  1958 
       
  1959 // 
       
  1960 // COomGroups
       
  1961 //
       
  1962 
       
  1963 COomGroups::~COomGroups()
       
  1964 	{
       
  1965 	delete iItem1;
       
  1966 	}
       
  1967 
       
  1968 void COomGroups::ConstructL()
       
  1969 	{
       
  1970 	COomFailBase::ConstructL();
       
  1971 	iItem1=(CContactCard *)iDb->ReadContactL((*IdList)[0]);
       
  1972 	}
       
  1973 
       
  1974 void COomGroups::FailL()
       
  1975 	{
       
  1976 	iGroupId=KNullContactId;
       
  1977 	CContactGroup* oomGroup=(CContactGroup*)iDb->CreateContactGroupLC(_L("Oom Group"));
       
  1978 	iGroupId=oomGroup->Id();
       
  1979 //
       
  1980 	iDb->AddContactToGroupL((*IdList)[1],iGroupId);
       
  1981 	iDb->AddContactToGroupL(*iItem1,*oomGroup);
       
  1982 //
       
  1983 	iDb->RemoveContactFromGroupL((*IdList)[0],iGroupId);
       
  1984 	iDb->RemoveContactFromGroupL((*IdList)[1],iGroupId);
       
  1985 //
       
  1986 	CleanupStack::PopAndDestroy(oomGroup);
       
  1987 	}
       
  1988 
       
  1989 void COomGroups::ClearUpL()
       
  1990 	{
       
  1991 	RecoverL();
       
  1992 	if (iGroupId!=KNullContactId)
       
  1993 		{
       
  1994 		TRAP_IGNORE(iDb->DeleteContactL(iGroupId));
       
  1995 		}
       
  1996 //	test(TestGroupStateL(iDb,-1,-1));
       
  1997 	CContactIdArray* grpList=iDb->GetGroupIdListL(); // This is introduced from 9.3 onwards as deletion of GroupIds was not happening properly.
       
  1998 	TInt count = grpList->Count();					 // during a leave (in COomGroups::FailL() at CContactGroup* oomGroup=(CContactGroup*)iDb->CreateContactGroupLC(_L("Oom Group")); 
       
  1999 													 // a  group is created in db but the ccontactdatabase doesnt append to its list and so it is not cleaned by COomGroups::ClearUpL properly
       
  2000 	if( count > 0 )
       
  2001 	{
       
  2002 		TContactItemId id = (*grpList)[0];
       
  2003 		TRAP_IGNORE(iDb->DeleteContactL(id)); 
       
  2004 	}
       
  2005 	delete grpList;
       
  2006 	}
       
  2007 
       
  2008 TBool COomGroups::Skip(TInt, TOomFailureModes aMode) const
       
  2009 	{
       
  2010 	// KErrCorrupt
       
  2011 	// Another one of those moving targets. The value of count at which failure occurs
       
  2012 	// varies between executions.
       
  2013 	if (aMode==KOomFailFileServerGeneral) return ETrue;
       
  2014 	if (aMode==KOomFailFileServerOom) return ETrue;
       
  2015 	return(EFalse);
       
  2016 	}
       
  2017 
       
  2018 // 
       
  2019 // COomGroups
       
  2020 //
       
  2021 
       
  2022 COomGroups2::~COomGroups2()
       
  2023 	{
       
  2024 	TRAP_IGNORE(iDb->DeleteContactL(iGroupId1));
       
  2025 	TRAP_IGNORE(iDb->DeleteContactL(iGroupId2));
       
  2026 	}
       
  2027 
       
  2028 void COomGroups2::ConstructL()
       
  2029 	{
       
  2030 	COomFailBase::ConstructL();
       
  2031 	CContactGroup* oomGroup=(CContactGroup*)iDb->CreateContactGroupLC(_L("Oom Group"));
       
  2032 	iGroupId1=oomGroup->Id();
       
  2033 	CleanupStack::PopAndDestroy(oomGroup);
       
  2034 	iDb->AddContactToGroupL((*IdList)[0],iGroupId1);
       
  2035 	oomGroup=(CContactGroup*)iDb->CreateContactGroupLC(_L("Oom Group"));
       
  2036 	iGroupId2=oomGroup->Id();
       
  2037 	CleanupStack::PopAndDestroy(oomGroup);
       
  2038 	iDb->AddContactToGroupL((*IdList)[0],iGroupId2);
       
  2039 	iDb->AddContactToGroupL((*IdList)[1],iGroupId2);
       
  2040 	}
       
  2041 
       
  2042 void COomGroups2::FailL()
       
  2043 	{
       
  2044 	CContactCard *card=(CContactCard *)iDb->ReadContactLC((*IdList)[0]);
       
  2045 //
       
  2046 	CContactIdArray* idArray=card->GroupsJoinedLC();
       
  2047 	test(idArray->Count()==2);
       
  2048 	test((*idArray)[0]==iGroupId1);
       
  2049 	test((*idArray)[1]==iGroupId2);
       
  2050 	CleanupStack::PopAndDestroy(idArray);
       
  2051 	CleanupStack::PopAndDestroy(card);
       
  2052 //
       
  2053 	CContactGroup *group=(CContactGroup *)iDb->ReadContactLC(iGroupId2);
       
  2054 	const CContactIdArray* itemsContained=group->ItemsContained();
       
  2055 	test(itemsContained->Count()==2);
       
  2056 	test((*itemsContained)[0]==(*IdList)[0]);
       
  2057 	test((*itemsContained)[1]==(*IdList)[1]);
       
  2058 	CleanupStack::PopAndDestroy(group);
       
  2059 //
       
  2060 	CContactIdArray* groupIdList=iDb->GetGroupIdListL();
       
  2061 	test(groupIdList->Count()==2);
       
  2062 	test((*groupIdList)[0]==iGroupId1);
       
  2063 	test((*groupIdList)[1]==iGroupId2);
       
  2064 	delete groupIdList;
       
  2065 	}
       
  2066 
       
  2067 void COomGroups2::ClearUpL()
       
  2068 	{
       
  2069 	RecoverL();
       
  2070 	test(TestGroupStateL(iDb,-1,-1));
       
  2071 	}
       
  2072 
       
  2073 //
       
  2074 // COomTest
       
  2075 //
       
  2076 
       
  2077 COomTest::COomTest(TDriveUnit aMmcDrive) : iMmcDrive(aMmcDrive)
       
  2078 	{}
       
  2079 
       
  2080 void COomTest::Test(TBool aMustBeTrue)
       
  2081 	{
       
  2082 	test(aMustBeTrue);
       
  2083 	}
       
  2084 
       
  2085 TInt COomTest::GetRecordCountL()
       
  2086 	{
       
  2087 	CContactDatabase *db=CContactDatabase::OpenL(KDatabaseFileName);
       
  2088 	CleanupStack::PushL(db);
       
  2089 	TInt recordCount=db->CountL();
       
  2090 	CleanupStack::PopAndDestroy();	// db
       
  2091 	return(recordCount);
       
  2092 	}
       
  2093 
       
  2094 
       
  2095 void COomTest::DoOomTestL(COomFailBase *aOomTest, TOomFailureModes aMode)
       
  2096 	{
       
  2097 	test(aOomTest!=NULL);
       
  2098 	test.Next(_L(" "));
       
  2099 
       
  2100 	__UHEAP_MARK;
       
  2101 	TInt oldDbCount=iDbs.ResourceCount();
       
  2102 	TInt oldFsCount=TheFs.ResourceCount();
       
  2103 //
       
  2104 	CleanupStack::PushL(aOomTest);
       
  2105 	TRAPD(ret1,aOomTest->ConstructL());
       
  2106 	test(ret1==KErrNone);
       
  2107 	CContactDatabase *lockDb=NULL;
       
  2108 	if (aMode==KOomFailContactServer)	// contact server failure tests
       
  2109 		{
       
  2110 		lockDb=CContactDatabase::OpenL(KDatabaseFileName);
       
  2111 		CleanupStack::PushL(lockDb);
       
  2112 		}
       
  2113 	TInt successCount=0;
       
  2114 	TInt skipCount=0;
       
  2115 	for(TInt count=0;;count++)
       
  2116 		{
       
  2117 		TInt ret=KErrNone;
       
  2118 		if (aOomTest->Skip(count,aMode))
       
  2119 			{
       
  2120 			skipCount++;
       
  2121 			}
       
  2122 		else
       
  2123 			{		
       
  2124 			// PREFAILL - Prepare for the test:
       
  2125 			TRAPD(preFailErr,aOomTest->PreFailL());
       
  2126 			test(preFailErr==KErrNone);
       
  2127 			// Set failure condition:
       
  2128 			switch(aMode)
       
  2129 				{
       
  2130 				case KOomFailNormal:
       
  2131 					__UHEAP_SETFAIL(RHeap::EDeterministic,count);
       
  2132 					break;
       
  2133 				case KOomFailDbs:
       
  2134 					iDbs.SetHeapFailure(RHeap::EDeterministic,count);
       
  2135 					break;
       
  2136 				case KOomFailContactServer:
       
  2137 					lockDb->SetCntServerHeapFailure(RHeap::EDeterministic,count);
       
  2138 					break;
       
  2139 				case KOomFailFileServerOom:
       
  2140 					TheFs.SetErrorCondition(KErrNoMemory,count);
       
  2141 					break;
       
  2142 				case KOomFailFileServerGeneral:
       
  2143 					TheFs.SetErrorCondition(KErrGeneral,count);
       
  2144 					break;
       
  2145 				default:;
       
  2146 				}	
       
  2147 				
       
  2148 			// FAILL - Perform test:
       
  2149 			TRAP(ret,aOomTest->FailL());
       
  2150 
       
  2151 			// Remove failure condition:
       
  2152 			switch(aMode)
       
  2153 				{
       
  2154 				case KOomFailNormal:
       
  2155 					__UHEAP_RESET;
       
  2156 					break;
       
  2157 				case KOomFailDbs:
       
  2158 					iDbs.SetHeapFailure(RHeap::ENone,0);
       
  2159 					break;
       
  2160 				case KOomFailContactServer:
       
  2161 					lockDb->SetCntServerHeapFailure(RHeap::ENone,0);
       
  2162 					break;
       
  2163 				case KOomFailFileServerOom:
       
  2164 				case KOomFailFileServerGeneral:
       
  2165 					TheFs.SetErrorCondition(KErrNone);
       
  2166 					break;
       
  2167 				default:;
       
  2168 				}
       
  2169 
       
  2170 			// CLEARUPL - tidy up after the test:
       
  2171 			TRAPD(ClearUpErr,aOomTest->ClearUpL());
       
  2172 			test(ClearUpErr==KErrNone);
       
  2173 			}
       
  2174 
       
  2175 		// Verify results of test:
       
  2176 		if (ret==KErrNone)
       
  2177 			{
       
  2178 			if (successCount==8)
       
  2179 				{
       
  2180 				test.Printf(_L("Count=%d"),count);
       
  2181 				if (skipCount>0)
       
  2182 					test.Printf(_L(", skipped=%d"),skipCount);
       
  2183 				test.Printf(_L("\n"));
       
  2184 				break;
       
  2185 				}
       
  2186 			successCount++;
       
  2187 			}
       
  2188 		else
       
  2189 			{
       
  2190 			successCount=0;
       
  2191 			test(aOomTest->ErrorOk(aMode, count, ret));
       
  2192 			}
       
  2193 		}
       
  2194 	if (aMode==KOomFailContactServer)
       
  2195 		CleanupStack::PopAndDestroy();	// lockDb
       
  2196 	CleanupStack::PopAndDestroy();	// aOomTest
       
  2197 	test(oldFsCount==TheFs.ResourceCount());
       
  2198 	test(oldDbCount==iDbs.ResourceCount());
       
  2199 	__UHEAP_MARKEND;
       
  2200 	}
       
  2201 
       
  2202 COomTest::~COomTest()
       
  2203 	{
       
  2204 	iDbs.Close();
       
  2205 	}
       
  2206 
       
  2207 /**
       
  2208 
       
  2209 @SYMTestCaseID     PIM-T-ERROR-0001
       
  2210 
       
  2211 */
       
  2212 
       
  2213 TBool COomTest::TestsL()
       
  2214 	{
       
  2215 	iDbs.Connect();
       
  2216     __UHEAP_MARK;
       
  2217 	TInt oldDbCount=iDbs.ResourceCount();
       
  2218 	for(TInt loop=0;loop<KOomNumFailModes;loop++)
       
  2219 		{
       
  2220 		if (loop > 0)
       
  2221 			{ // increment the RTest number XXX
       
  2222 			test.Next(_L("--- Next Error case ---"));
       
  2223 
       
  2224 			}
       
  2225 
       
  2226 		TOomFailureModes mode=(TOomFailureModes)loop;
       
  2227 		switch(mode)
       
  2228 			{
       
  2229 			case KOomFailNormal: // RTest 001.01
       
  2230 				test.Start(_L("@SYMTESTCaseID:PIM-T-ERROR-0001 ===Test Out Of Memory==="));
       
  2231 
       
  2232 				break;
       
  2233 			case KOomFailFileServerGeneral: // RTest 002.01
       
  2234 				test.Start(_L("===Test File server general failure==="));
       
  2235 
       
  2236 				break;
       
  2237 			case KOomFailFileServerOom: // RTest 003.01
       
  2238 				test.Start(_L("===Test File server Oom failure==="));
       
  2239 
       
  2240 				break;
       
  2241 			case KOomFailContactServer: // RTest 004.01
       
  2242 				test.Start(_L("===Test Contact Server Oom failure==="));
       
  2243 
       
  2244 				break;
       
  2245 			case KOomFailDbs: // RTest 005.01
       
  2246 				test.Start(_L("===Test DBS Oom failure==="));
       
  2247 
       
  2248 				break;
       
  2249 			default:;
       
  2250 			}
       
  2251 		// RTest X.01
       
  2252 		test.Next(_L("Create Database for OOM test"));
       
  2253 
       
  2254 		TRAPD(ret,CreateDatabaseL());
       
  2255 		test(ret==KErrNone);
       
  2256 		IdList=CContactIdArray::NewLC();
       
  2257 		test.Next(_L("Create Contacts for OOM test"));
       
  2258 
       
  2259 		TRAP(ret,AddNewContactsL());
       
  2260 		test(ret==KErrNone);
       
  2261 
       
  2262 		DoOomTestL(new(ELeave) COomOpen(this),mode);
       
  2263 		DoOomTestL(new(ELeave) COomCreate(this),mode);	
       
  2264 		DoOomTestL(new(ELeave) COomFind(this),mode);
       
  2265 		DoOomTestL(new(ELeave) COomFindAsync(this),mode);
       
  2266 		DoOomTestL(new(ELeave) COomFindInTextDef(this),mode);
       
  2267 		DoOomTestL(new(ELeave) COomFindAsyncInTextDef(this),mode);
       
  2268 		DoOomTestL(new(ELeave) COomSort(this),mode);
       
  2269 		DoOomTestL(new(ELeave) COomSortArray(this),mode);  
       
  2270 		DoOomTestL(new(ELeave) COomSetDatabaseDrive(this, iMmcDrive),mode);	
       
  2271 		DoOomTestL(new(ELeave) COomGetDefaultName(this),mode);
       
  2272 		DoOomTestL(new(ELeave) COomViewDefinition(this),mode);
       
  2273 		DoOomTestL(new(ELeave) COomTextDefinition(this),mode);
       
  2274 		DoOomTestL(new(ELeave) COomReadContact(this),mode);
       
  2275 		DoOomTestL(new(ELeave) COomAddNewContact(this),mode);
       
  2276 		DoOomTestL(new(ELeave) COomReadContactTextDef(this),mode);
       
  2277 		DoOomTestL(new(ELeave) COomOpenAndCloseContactX(this),mode);
       
  2278 		DoOomTestL(new(ELeave) COomOpenAndCloseContact(this),mode);
       
  2279 		DoOomTestL(new(ELeave) COomOpenModifyAndCommitContact(this),mode);
       
  2280 		DoOomTestL(new(ELeave) COomDeleteContact(this),mode);
       
  2281 		DoOomTestL(new(ELeave) COomDeleteContacts(this),mode);
       
  2282 		DoOomTestL(new(ELeave) COomCompact(this),mode);
       
  2283 		DoOomTestL(new(ELeave) COomImportContacts(this),mode);
       
  2284 		DoOomTestL(new(ELeave) COomExportSelectedContacts(this),mode);
       
  2285 		DoOomTestL(new(ELeave) COomCompress(this),mode);
       
  2286 		// This test damages the database and attempts to recover it which
       
  2287 		// is not possible in the UREL build.		
       
  2288 #ifdef _DEBUG
       
  2289 		DoOomTestL(new(ELeave) COomRecover(this),mode);
       
  2290 #endif
       
  2291 		DoOomTestL(new(ELeave) COomCloseOpenTables(this),mode);
       
  2292 		DoOomTestL(new(ELeave) COomViewDefInternalize(this),mode);
       
  2293 		DoOomTestL(new(ELeave) COomViewDefExternalize(this),mode);
       
  2294 		DoOomTestL(new(ELeave) COomFieldSetStore(this),mode);
       
  2295 		DoOomTestL(new(ELeave) COomFieldSetRestore(this),mode);
       
  2296 		DoOomTestL(new(ELeave) COomContactCardClone(this),mode);
       
  2297 		DoOomTestL(new(ELeave) COomContactChangeNotifier(this),mode);  
       
  2298 		DoOomTestL(new(ELeave) COomPhoneNumberLookup(this),mode);
       
  2299 		User::After(1000000);	//	fixes defect DEF039417
       
  2300 		DoOomTestL(new(ELeave) COomContactsChangedSince(this),mode);
       
  2301 		DoOomTestL(new(ELeave) COomGroups2(this),mode);
       
  2302 		DoOomTestL(new(ELeave) COomGroups(this),mode);
       
  2303 		CleanupStack::PopAndDestroy(); // IdList
       
  2304 		test.End();
       
  2305 		}
       
  2306 
       
  2307 	test(oldDbCount==iDbs.ResourceCount());
       
  2308     __UHEAP_MARKEND;
       
  2309 	return(ETrue);
       
  2310 	}
       
  2311 
       
  2312 //
       
  2313 
       
  2314 // Code for DrivesOfMediaTypeL() and MMCDriveL() adapted from T_Sec_CntDbase
       
  2315 
       
  2316 LOCAL_C TBool FirstDriveOfMediaTypeL(TMediaType aMedia, TInt& aDriveNumber)
       
  2317 	{
       
  2318 	TDriveInfo info;
       
  2319 	TInt error(KErrNone);
       
  2320 	TBool result(EFalse);
       
  2321 
       
  2322 	TDriveList driveList;
       
  2323 	error = TheFs.DriveList(driveList);
       
  2324 	User::LeaveIfError(error);
       
  2325 
       
  2326 	for(TInt drive=EDriveA; drive<=EDriveZ; drive++)
       
  2327 		{
       
  2328 		if( driveList[drive] )
       
  2329 			{
       
  2330 			error = TheFs.Drive(info, drive);
       
  2331 			if	(error != KErrNone)
       
  2332 				{
       
  2333 				continue;
       
  2334 				}
       
  2335 				
       
  2336 			if	(info.iType == aMedia)
       
  2337 				{
       
  2338 				aDriveNumber = drive;
       
  2339 				result = ETrue;
       
  2340 				
       
  2341 				// return if only the first drive of the required type.
       
  2342 				break;
       
  2343 				}
       
  2344 			}
       
  2345 		}
       
  2346 
       
  2347 	return result;
       
  2348 	}
       
  2349 
       
  2350 /**
       
  2351 	MMCDriveL
       
  2352 	
       
  2353 	Determines a list of drives of type EMediaHardDisk.
       
  2354 	The first drive in this list is returned and used
       
  2355 	by the rest of the test.
       
  2356 
       
  2357         NOTE: if this test is running on ARMv5, an MMC card
       
  2358         must be present otherwise the test fails.
       
  2359 
       
  2360 */
       
  2361 LOCAL_C TDriveUnit MMCDriveL()
       
  2362 	{
       
  2363 	TInt driveNumber = 0;
       
  2364 	
       
  2365 	if( !FirstDriveOfMediaTypeL(EMediaHardDisk, driveNumber) )
       
  2366 		{
       
  2367 		test.Printf( _L("No drives found of type EMediaHardDisk\n"));
       
  2368 		User::LeaveIfError(KErrHardwareNotAvailable);
       
  2369 		}
       
  2370 
       
  2371 	TDriveUnit mmcDrive(driveNumber);
       
  2372 	TPtrC drvPtr(mmcDrive.Name());
       
  2373 	test.Printf(_L("Selected drive of type EMediaHardDisk for test use is %S\n"), &drvPtr);
       
  2374 
       
  2375 	// drive selected fortest to use
       
  2376 	return mmcDrive;
       
  2377 	}
       
  2378 
       
  2379 
       
  2380 LOCAL_C void OomTestsL()
       
  2381 	{
       
  2382 	// usable drive for SetDatabaseDriveL test
       
  2383 	TDriveUnit mmcDrive = MMCDriveL();
       
  2384 
       
  2385 	COomTest *oomTest=new(ELeave) COomTest(mmcDrive);
       
  2386 	CleanupStack::PushL(oomTest);
       
  2387 //
       
  2388 	oomTest->TestsL();
       
  2389 //
       
  2390 	CleanupStack::PopAndDestroy(oomTest);
       
  2391 	}
       
  2392 
       
  2393 
       
  2394 void DoTests()
       
  2395     {
       
  2396 	test.Start(_L("Error tests"));
       
  2397 
       
  2398 	User::LeaveIfError(TheFs.Connect());
       
  2399 
       
  2400 	TRAPD(ret,OomTestsL());
       
  2401 	test(ret==KErrNone);
       
  2402 	test.End();
       
  2403 	
       
  2404 	// cleanup disk space
       
  2405    	TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDatabaseFileName));
       
  2406     TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDatabaseCreateFileName));
       
  2407 	TRAP_IGNORE(CContactDatabase::DeleteDefaultFileL());
       
  2408 
       
  2409 	test(TheFs.ResourceCount()==0);
       
  2410 	TheFs.Close();
       
  2411 
       
  2412 	// propagate error
       
  2413 	User::LeaveIfError(ret);
       
  2414     }
       
  2415 
       
  2416 GLDEF_C TInt E32Main()
       
  2417 	{
       
  2418     __UHEAP_MARK;
       
  2419 	CActiveScheduler::Install(new(ELeave) CActiveScheduler);
       
  2420     CTrapCleanup* cleanup=CTrapCleanup::New();
       
  2421 	test.Title();
       
  2422     DoTests();
       
  2423     test.Close();
       
  2424     delete cleanup;
       
  2425 	delete CActiveScheduler::Current();
       
  2426     __UHEAP_MARKEND;
       
  2427 	return KErrNone;
       
  2428     }