persistentstorage/sql/TEST/t_sqlsecurity6.cpp
branchRCL_3
changeset 12 6b6fd149daa2
child 14 04ec7606545c
equal deleted inserted replaced
11:211563e4b919 12:6b6fd149daa2
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // 
       
    15 //
       
    16 #include <e32test.h>
       
    17 #include <bautils.h>
       
    18 #include <sqldb.h>
       
    19 
       
    20 ///////////////////////////////////////////////////////////////////////////////////////
       
    21 
       
    22 RSqlDatabase TheDb;
       
    23 RTest TheTest(_L("t_sqlsecurity6 test"));
       
    24 
       
    25 ///////////////////////////////////////////////////////////////////////////////////////
       
    26 
       
    27 void DestroyTestEnv()
       
    28 	{
       
    29 	TheDb.Close();
       
    30 	(void)RSqlDatabase::Delete(_L("c:[00009876]"));
       
    31 	}
       
    32 
       
    33 ///////////////////////////////////////////////////////////////////////////////////////
       
    34 //Test macros and functions
       
    35 void Check1(TInt aValue, TInt aLine)
       
    36 	{
       
    37 	if(!aValue)
       
    38 		{
       
    39 		DestroyTestEnv();
       
    40 		RDebug::Print(_L("*** Boolean expression evaluated to false. Line %d\r\n"), aLine);
       
    41 		TheTest(EFalse, aLine);
       
    42 		}
       
    43 	}
       
    44 void Check2(TInt aValue, TInt aExpected, TInt aLine)
       
    45 	{
       
    46 	if(aValue != aExpected)
       
    47 		{
       
    48 		DestroyTestEnv();
       
    49 		RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
       
    50 		TheTest(EFalse, aLine);
       
    51 		}
       
    52 	}
       
    53 #define TEST(arg) ::Check1((arg), __LINE__)
       
    54 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
       
    55 
       
    56 ///////////////////////////////////////////////////////////////////////////////////////
       
    57 
       
    58 /**
       
    59 @SYMTestCaseID          PDS-SQL-CT-4199
       
    60 @SYMTestCaseDesc        Invalid secure database UIDs test.
       
    61 @SYMTestPriority        High
       
    62 @SYMTestActions         The test attempts to create a secure database using invalid UIDs:
       
    63 						- with length less than 8 hes digits;
       
    64 						- with invalid characters in the UID;
       
    65 						- wiht database name containing the UID only;
       
    66 @SYMTestExpectedResults Test must not fail
       
    67 @SYMDEF                 DEF145236
       
    68 */  
       
    69 void InvalidSecureUidsTest()
       
    70 	{
       
    71 	RSqlSecurityPolicy policy;
       
    72 	TInt err = policy.Create(TSecurityPolicy::EAlwaysPass);
       
    73 	TEST2(err, KErrNone);
       
    74 	
       
    75 	//The UID in the database name is too short. It must be 8 hex digits UID. 
       
    76 	err = TheDb.Create(_L("c:[9876]t_sqlsecurity6.db"), policy);
       
    77 	TEST2(err, KErrArgument);
       
    78 	
       
    79 	//Short UID, used as a database name. 
       
    80 	err = TheDb.Create(_L("c:[9876]"), policy);
       
    81 	TEST2(err, KErrArgument);
       
    82 
       
    83 	//Invalid UID. 
       
    84 	err = TheDb.Create(_L("c:[KH0A0Q0J]"), policy);
       
    85 	TEST2(err, KErrArgument);
       
    86 	
       
    87 	//UID, used as a database name. 
       
    88 	err = TheDb.Create(_L("c:[00009876]"), policy);
       
    89 	TEST2(err, KErrNone);
       
    90 	err = TheDb.Exec(_L("CREATE TABLE A(I INTEGER)"));
       
    91 	TEST(err >= 0);
       
    92 	TheDb.Close();
       
    93 	err = RSqlDatabase::Delete(_L("c:[00009876]"));
       
    94 	TEST2(err, KErrNone);
       
    95 	
       
    96 	policy.Close();
       
    97 	}
       
    98 
       
    99 void DoTestsL()
       
   100 	{
       
   101 	TheTest.Start(_L("@SYMTestCaseID:PDS-SQL-CT-4199"));
       
   102 	InvalidSecureUidsTest();
       
   103 	}
       
   104 
       
   105 TInt E32Main()
       
   106 	{
       
   107 	TheTest.Title();
       
   108 	
       
   109 	CTrapCleanup* tc = CTrapCleanup::New();
       
   110 	TheTest(tc != NULL);
       
   111 	
       
   112 	__UHEAP_MARK;
       
   113 		
       
   114 	TRAPD(err, DoTestsL());
       
   115 	TEST2(err, KErrNone);
       
   116 
       
   117 	__UHEAP_MARKEND;
       
   118 	
       
   119 	TheTest.End();
       
   120 	TheTest.Close();
       
   121 	
       
   122 	delete tc;
       
   123 
       
   124 	User::Heap().Check();
       
   125 	return KErrNone;
       
   126 	}