persistentstorage/dbms/tdbms/t_dbenvcreate.cpp
changeset 0 08ec8eefde2f
child 51 7d4490026038
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2004-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 // DBMS security policy - testing new APIs - preparation operations
       
    15 // Please, ensure that t_predbsc test is executed before t_dbsc<N> tests!
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <d32dbms.h>
       
    20 #include <e32test.h>
       
    21 
       
    22 static RTest TheTest(_L("t_dbenvcreate: DBMS platform security testing - preparation"));
       
    23 static RDbs TheDbs;
       
    24 const TUid KSecureDbUid = {0x11335578};
       
    25 const TUid KSecureDbUid2 = {0x11335579};
       
    26 _LIT(KProtDbZName, "z:z.db");
       
    27 _LIT(KProtDbCName, "C:z.Db");
       
    28 _LIT(KProtDbZName2, "z:TEstDB.dB");
       
    29 _LIT(KProtDbCName2, "c:teSTDB.db");
       
    30 _LIT(KProtDbCName3, "c:AbcD.Db");
       
    31 _LIT(KProtDbCName4, "c:A0123456789B0123456789C0123456789D0123456789E0123456789F0123.Db");
       
    32 _LIT(KProtDbCName5, "c:ZADFS.Db");
       
    33 _LIT(KProtDbFormat3, "SECURE[1133557A]");
       
    34 _LIT(KProtDbCPath, "C:\\Private\\100012a5\\Dbs_11335578_z.dB");
       
    35 _LIT(KProtDbCPath2, "C:\\Private\\100012a5\\dBS_11335579_TesTDB.db");
       
    36 
       
    37 ///////////////////////////////////////////////////////////////////////////////////////
       
    38 ///////////////////////////////////////////////////////////////////////////////////////
       
    39 //Test macros and functions
       
    40 static void Check(TInt aValue, TInt aLine)
       
    41 	{
       
    42 	if(!aValue)
       
    43 		{
       
    44 		TheTest(EFalse, aLine);
       
    45 		}
       
    46 	}
       
    47 static void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    48 	{
       
    49 	if(aValue != aExpected)
       
    50 		{
       
    51 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    52 		TheTest(EFalse, aLine);
       
    53 		}
       
    54 	}
       
    55 #define TEST(arg) 				 ::Check((arg), __LINE__)
       
    56 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    57 
       
    58 ///////////////////////////////////////////////////////////////////////////////////////
       
    59 
       
    60 /**
       
    61 @SYMTestCaseID SYSLIB-DBMS-CT-0023
       
    62 @SYMTestCaseDesc This test app must be executed before all t_dbsc<N> tests.
       
    63                  It ensures that the test data is copied and prepared for the tests executed
       
    64 				 after the current executable.
       
    65 @SYMTestPriority High
       
    66 @SYMTestActions  Copy test databases from Z: to C: drive in the DBMS server private data cage.
       
    67 @SYMTestExpectedResults The test must not fail.
       
    68 @SYMREQ          REQ2429
       
    69                  DBMS shall provide an API to apply security policies to database tables.
       
    70 */
       
    71 static void DoRun()
       
    72 	{
       
    73 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0023 Copy protected databases from Z: to C: "));
       
    74 	TInt err = TheDbs.CopyDatabase(KProtDbZName, KProtDbCName, KSecureDbUid);
       
    75 	TEST2(err, KErrNone);
       
    76 	err = TheDbs.CopyDatabase(KProtDbZName2, KProtDbCName2, KSecureDbUid2);
       
    77 	TEST2(err, KErrNone);
       
    78 
       
    79 	TheTest.Next(_L("Create protected database on C:"));
       
    80 	RDbNamedDatabase db;
       
    81 	err = db.Create(TheDbs, KProtDbCName3, KProtDbFormat3);
       
    82 	TEST2(err, KErrNone);
       
    83 	db.Close();
       
    84 
       
    85 	err = db.Create(TheDbs, KProtDbCName4, KProtDbFormat3);
       
    86 	TEST2(err, KErrNone);
       
    87 	db.Close();
       
    88 
       
    89 	err = db.Create(TheDbs, KProtDbCName5, KProtDbFormat3);
       
    90 	TEST2(err, KErrNone);
       
    91 	db.Close();
       
    92 
       
    93 	RFs fileSess;
       
    94 	err = fileSess.Connect();
       
    95 	TEST2(err, KErrNone);
       
    96 	err = fileSess.SetAtt(KProtDbCPath,  0, KEntryAttReadOnly);
       
    97 	TEST2(err, KErrNone);
       
    98 	err = fileSess.SetAtt(KProtDbCPath2,  0, KEntryAttReadOnly);
       
    99 	TEST2(err, KErrNone);
       
   100 	fileSess.Close();
       
   101 	}
       
   102 
       
   103 TInt E32Main()
       
   104     {
       
   105 	__UHEAP_MARK;
       
   106 	CTrapCleanup* tc = CTrapCleanup::New();
       
   107 	TEST(tc != NULL);
       
   108 
       
   109 	TheTest.Title();
       
   110 
       
   111 	TInt err = TheDbs.Connect();
       
   112 	TEST2(err, KErrNone);
       
   113 
       
   114 	::DoRun();
       
   115 
       
   116 	TheDbs.Close();
       
   117 
       
   118 	TheTest.End();
       
   119 	TheTest.Close();
       
   120 
       
   121 	delete tc;
       
   122 
       
   123 	__UHEAP_MARKEND;
       
   124 	User::Heap().Check();
       
   125 	return KErrNone;
       
   126     }