commsconfig/commsdatabaseshim/TE_commdb/src/Db_7_create.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     1 //
       
     2 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 //
       
    17 //
       
    18 
       
    19 // Create a totaly empty database
       
    20 
       
    21 #include <e32test.h>
       
    22 #include <f32file.h>
       
    23 #include <commdb.h>
       
    24 #include <cdblen.h>
       
    25 #include <cdbpreftable.h>
       
    26 #include <faxdefn.h>
       
    27 #include <d32comm.h>
       
    28 #include <cdbtemp.h>
       
    29 
       
    30 
       
    31 _LIT(KEditorMess,"Database Editor");
       
    32 LOCAL_C RTest test(KEditorMess);
       
    33 LOCAL_C CCommsDatabase* theDb;
       
    34 
       
    35 
       
    36 
       
    37 LOCAL_C void MainL() 
       
    38     {
       
    39 	RFs fs;
       
    40 	test(fs.Connect()==KErrNone);
       
    41 	
       
    42 	TUint dummy;
       
    43 	
       
    44 	test.Printf(_L("Creating CommDb Unit test database  #7") );
       
    45 
       
    46 	_LIT(KSvDbFileName,"C:\\private\\100012a5\\DBS[10004e1d]CDBV3.DAT");
       
    47 	if(fs.Att(KSvDbFileName,dummy)==KErrNone)
       
    48 		{
       
    49 		_LIT(KDbaseMess,"\nExisting Database File detected\n - Overwrite? [y/n]\n\n");
       
    50 		test.Printf(KDbaseMess);
       
    51 		TKeyCode key;
       
    52 		key=test.Getch();
       
    53 		if((key=='y')||(key=='Y'))
       
    54 			{
       
    55 			// Instantiate Database Server
       
    56 			RDbs rDbs;
       
    57 			User::LeaveIfError(rDbs.Connect());
       
    58 			CleanupClosePushL(rDbs);
       
    59 			_LIT(KCommDb,"c:cdbv3.dat"); 
       
    60 			const TUid KCommsDbFileUid = {0x10004e1d};
       
    61 			test(rDbs.DeleteDatabase(KCommDb, KCommsDbFileUid)==KErrNone);
       
    62 			CleanupStack::PopAndDestroy(&rDbs);
       
    63 			}
       
    64 		else
       
    65 			User::Leave(KErrNone);
       
    66 		}
       
    67 	fs.Close();
       
    68 
       
    69 	//Create a blank database
       
    70 	theDb=CCommsDatabase::NewL(EFalse);
       
    71 	//and close it
       
    72 	delete theDb;
       
    73 
       
    74 	}
       
    75 
       
    76 GLDEF_C TInt E32Main()
       
    77     {
       
    78 	__UHEAP_MARK;
       
    79 
       
    80 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    81 	
       
    82 	test.Title();
       
    83 	TRAPD(error,MainL());
       
    84 
       
    85 	if (error)
       
    86 		{
       
    87 		_LIT(KFailMess,"DbApp failed with error = %d");
       
    88 		test.Printf(KFailMess, error);
       
    89 		_LIT(KAnyKeyMess," [Press any key]");
       
    90 		test.Printf(KAnyKeyMess);
       
    91 		test.Getch();
       
    92 		}
       
    93 	else
       
    94 		{
       
    95 		_LIT(KCompleteMess,"DbApp Complete OK");
       
    96 		test.Printf(KCompleteMess);
       
    97 		}
       
    98 	_LIT(KPanicMess,"DbApp");
       
    99 	__ASSERT_ALWAYS(!error,test.Panic(KPanicMess,error));
       
   100 	test.Close();
       
   101 	delete cleanup;
       
   102 	__UHEAP_MARKEND;
       
   103 	return KErrNone;
       
   104     }