persistentstorage/dbms/tdbms/t_dbnewcap1.cpp
changeset 0 08ec8eefde2f
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 //
       
    15 
       
    16 //The test uses C:TESTDB.DB secure shared database, which creates tables A, B and C.
       
    17 #include <e32test.h>
       
    18 #include <d32dbms.h>
       
    19 #include "t_dbplatsecutl.h"
       
    20 
       
    21 //The .spd file has the following capabilities:
       
    22 //	Schema	None
       
    23 //	Read	SurroundingsDD
       
    24 //	Write	UserEnvironment
       
    25 const TUid KSecureDbUid = {0x12344321};
       
    26 
       
    27 _LIT(KSecure,	"SECURE");
       
    28 _LIT(KDbName,	"C:TestDB.DB");
       
    29 _LIT(KTblNameA,	"A");
       
    30 _LIT(KTblNameB,	"B");
       
    31 _LIT(KTblNameC,	"C");
       
    32 
       
    33 static RTest 				TheTest(_L("t_dbnewcap1"));
       
    34 static RDbs 				TheDbs;
       
    35 static RDbNamedDatabase 	TheDb;
       
    36 static RDbTable 			TheTbl;
       
    37 
       
    38 TDBSCUtils 	TheDbscUtils(TheTest, NULL);
       
    39 
       
    40 static TColDef const KColumns[]=
       
    41 	{
       
    42 	{_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement},
       
    43 	{_S("DATA1"), EDbColInt32, TDbCol::ENotNull},
       
    44 	{_S("DATA2"), EDbColInt32, TDbCol::ENotNull},
       
    45 	{0}
       
    46 	};
       
    47 
       
    48 /**
       
    49 @SYMTestCaseID SYSLIB-DBMS-CT-1361
       
    50 @SYMTestCaseDesc Checking to make sure the .spd file used in this test has been created correctly and
       
    51 functions as it should.
       
    52 @SYMTestPriority Medium
       
    53 @SYMTestActions Creating a database and 3 tables (A, B & C), running 3 actions on it and then deleting
       
    54 the database (5 actions in total). Whether the actions are allowed or not is decided on the capabilities
       
    55 that the database has (stated in the MMP file) relative to the capabilities that are needed to perform
       
    56 certain actions (stated in the .spd file).
       
    57 @SYMTestExpectedResults The test must not fail.
       
    58 @SYMDEF DEF065282
       
    59 */
       
    60 static void DefectTestL()
       
    61 	{
       
    62 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1361 An app with \"UserEnvironment\" capabilities set\n "));
       
    63 
       
    64 	TheTest.Printf(_L("Test 1: Create tables\n"));
       
    65 	//The tests must pass, because the test app has "SCHEMA" capability
       
    66 	CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns);
       
    67 	TInt err = TheDb.CreateTable(KTblNameA, *colset);
       
    68 	TEST2(err, KErrNone);
       
    69 	err = TheDb.CreateTable(KTblNameB, *colset);
       
    70 	TEST2(err, KErrNone);
       
    71 	err = TheDb.CreateTable(KTblNameC, *colset);
       
    72 	TEST2(err, KErrNone);
       
    73 	CleanupStack::PopAndDestroy(colset);
       
    74 
       
    75 	TheTest.Printf(_L("Test 2: Opening the tables in insert-only mode\n"));
       
    76 	//The tests must pass because the test app has "WRITE" capability
       
    77 	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EInsertOnly);
       
    78 	TEST2(err, KErrNone);
       
    79 	TheTbl.Close();
       
    80 	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EInsertOnly);
       
    81 	TEST2(err, KErrNone);
       
    82 	TheTbl.Close();
       
    83 	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EInsertOnly);
       
    84 	TEST2(err, KErrNone);
       
    85 	TheTbl.Close();
       
    86 
       
    87 	TheTest.Printf(_L("Test 3: An attempt to open tables in read-only mode\n"));
       
    88 	//The tests must not pass because the test app does not have "READ" capability.
       
    89 	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
       
    90 	TEST2(err, KErrPermissionDenied);
       
    91 	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
       
    92 	TEST2(err, KErrPermissionDenied);
       
    93 	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
       
    94 	TEST2(err, KErrPermissionDenied);
       
    95 	TheTbl.Close();
       
    96 	}
       
    97 
       
    98 TInt E32Main()
       
    99     {
       
   100 	__UHEAP_MARK;
       
   101 	CTrapCleanup* tc = CTrapCleanup::New();
       
   102 	TEST(tc != NULL);
       
   103 
       
   104 	TInt err = TheDbs.Connect();
       
   105 	TEST2(err, KErrNone);
       
   106 
       
   107 	TBuf<32> format;
       
   108 	format.Copy(KSecure);
       
   109 	format.Append(KSecureDbUid.Name());
       
   110 
       
   111 	//Make sure there is no previous instance of the database.
       
   112 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
       
   113 	TheTest.Printf(_L("Create a database\n"));
       
   114 	err = TheDb.Create(TheDbs, KDbName, format);
       
   115 	TEST2(err, KErrNone);
       
   116 
       
   117 	TRAP(err, ::DefectTestL());
       
   118 	TEST2(err, KErrNone);
       
   119 
       
   120 	TheTbl.Close();
       
   121 	TheDb.Close();
       
   122 	// Remove the database that was created during the tests
       
   123 	TheTest.Printf(_L("Delete the database\n"));
       
   124 	err = TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
       
   125 	TEST2(err, KErrNone);
       
   126 	TheDbs.Close();
       
   127 
       
   128 	TheTest.End();
       
   129 	TheTest.Close();
       
   130 
       
   131 	delete tc;
       
   132 
       
   133 	__UHEAP_MARKEND;
       
   134 	User::Heap().Check();
       
   135 	return KErrNone;
       
   136     }