os/persistentdata/persistentstorage/dbms/tdbms/t_dbfail2.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Secure shared databases failures test
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <d32dbms.h>
sl@0
    19
#include <s32file.h>
sl@0
    20
#include <e32test.h>
sl@0
    21
#include "t_dbfail.h"
sl@0
    22
sl@0
    23
LOCAL_D TBuf<64> TheFormat2;
sl@0
    24
_LIT(KTestDatabase2,"C:t_fail.db");
sl@0
    25
_LIT(KTestDatabase3,"C:t_fail2.db");
sl@0
    26
const TUid KPolicyUid = {0x11335579};
sl@0
    27
sl@0
    28
GLDEF_C void PrepareDbFmtString()
sl@0
    29
	{
sl@0
    30
	TheFormat2.Copy(_L("SECURE"));
sl@0
    31
	TheFormat2.Append(KPolicyUid.Name());
sl@0
    32
	}
sl@0
    33
sl@0
    34
LOCAL_C void DbCreate2L()
sl@0
    35
	{
sl@0
    36
	User::LeaveIfError(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2));
sl@0
    37
	RDebug::Print(_L("Secure shared database created.\n"));
sl@0
    38
	}
sl@0
    39
sl@0
    40
LOCAL_C void DbDatabaseNamesL()
sl@0
    41
	{
sl@0
    42
	CDbDatabaseNames* dbNames = TheDbs.DatabaseNamesL(EDriveC, KPolicyUid);
sl@0
    43
	test(dbNames != NULL);
sl@0
    44
	TInt cnt = dbNames->Count();
sl@0
    45
	TInt i;
sl@0
    46
	for(i=0;i<cnt;++i)
sl@0
    47
		{
sl@0
    48
		const TDesC& name = (*dbNames)[i];
sl@0
    49
		RDebug::Print(_L("%02d. %S\n"), i + 1, &name);
sl@0
    50
		}
sl@0
    51
	delete dbNames;
sl@0
    52
	RDebug::Print(_L("Secure shared database - DatabaseNamesL().\n"));
sl@0
    53
	}
sl@0
    54
sl@0
    55
LOCAL_C void DbCopyDatabaseL()
sl@0
    56
	{
sl@0
    57
	User::LeaveIfError(TheDbs.CopyDatabase(KTestDatabase2, KTestDatabase3, KPolicyUid));
sl@0
    58
	RDebug::Print(_L("Secure shared database - CopyDatabase().\n"));
sl@0
    59
	}
sl@0
    60
sl@0
    61
LOCAL_C void DbDeleteDatabaseL()
sl@0
    62
	{
sl@0
    63
	User::LeaveIfError(TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid));
sl@0
    64
	RDebug::Print(_L("Secure shared database - DeleteDatabase().\n"));
sl@0
    65
	}
sl@0
    66
sl@0
    67
LOCAL_C void DbOpen2L()
sl@0
    68
	{
sl@0
    69
	User::LeaveIfError(TheDatabase.Open(TheDbs, KTestDatabase2, TheFormat2));
sl@0
    70
	CleanupClosePushL(TheDatabase);
sl@0
    71
	delete TheDatabase.TableNamesL();	// force a schema load
sl@0
    72
	CleanupStack::Pop();
sl@0
    73
	RDebug::Print(_L("Secure shared database - Open().\n"));
sl@0
    74
	}
sl@0
    75
sl@0
    76
GLDEF_C void TestOpen2()
sl@0
    77
	{
sl@0
    78
	_LIT(KFileNotFound2, "C:not a database");
sl@0
    79
	Connect();
sl@0
    80
	TInt r=TheDatabase.Open(TheDbs, KFileNotFound2, TheFormat2);
sl@0
    81
	Disconnect();
sl@0
    82
	test (r==KErrPathNotFound || r==KErrNotFound);//There is no secure shared database with name KFileNotFound2
sl@0
    83
//
sl@0
    84
	_LIT(KPathNotFound2, "Z:ddd.db");
sl@0
    85
	Connect();
sl@0
    86
	r=TheDatabase.Open(TheDbs, KPathNotFound2, TheFormat2);
sl@0
    87
	Disconnect();
sl@0
    88
	test (r==KErrPathNotFound || r==KErrNotFound);//There is no secure shared database with name KPathNotFound2
sl@0
    89
//
sl@0
    90
	_LIT(KDbName, "C:dddqweuqwe.db");
sl@0
    91
	_LIT(KDbInvalidFmt, "SECURE");
sl@0
    92
	Connect();
sl@0
    93
	r=TheDatabase.Open(TheDbs, KDbName, KDbInvalidFmt);
sl@0
    94
	Disconnect();
sl@0
    95
	test (r==KErrArgument);//The format string is invalid, if there is "SECURE" keyword, then a uid has to follw it.
sl@0
    96
//
sl@0
    97
	_LIT(KSecureSharedDbName, "C:xfgbdrgui.db");
sl@0
    98
	_LIT(KDbNonSecureValidFmt, "[123456768]");
sl@0
    99
	Connect();
sl@0
   100
	r=TheDatabase.Open(TheDbs, KSecureSharedDbName, KDbNonSecureValidFmt);
sl@0
   101
	Disconnect();
sl@0
   102
	test (r==KErrNotFound);//Non-secure, non-existent database
sl@0
   103
	}
sl@0
   104
sl@0
   105
class TFailCreateDatabase2 : public TFail
sl@0
   106
	{
sl@0
   107
	void RunL()
sl@0
   108
		{
sl@0
   109
		DbCreate2L();
sl@0
   110
		}
sl@0
   111
	void End()
sl@0
   112
		{
sl@0
   113
		TheDatabase.Close();
sl@0
   114
		(void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid);
sl@0
   115
		}
sl@0
   116
	};
sl@0
   117
sl@0
   118
class TFailOpenDatabase2 : public TFail
sl@0
   119
	{
sl@0
   120
	void RunL()
sl@0
   121
		{
sl@0
   122
		DbOpen2L();
sl@0
   123
		}
sl@0
   124
	void End()
sl@0
   125
		{
sl@0
   126
		TheDatabase.Close();
sl@0
   127
		}
sl@0
   128
	};
sl@0
   129
sl@0
   130
class TFailDatabaseNames : public TFail
sl@0
   131
	{
sl@0
   132
	void RunL()
sl@0
   133
		{
sl@0
   134
		DbDatabaseNamesL();
sl@0
   135
		}
sl@0
   136
	void End()
sl@0
   137
		{
sl@0
   138
		}
sl@0
   139
	};
sl@0
   140
sl@0
   141
class TFailCopyDatabase : public TFail
sl@0
   142
	{
sl@0
   143
	void RunL()
sl@0
   144
		{
sl@0
   145
		DbCopyDatabaseL();
sl@0
   146
		}
sl@0
   147
	void End()
sl@0
   148
		{
sl@0
   149
		(void)TheDbs.DeleteDatabase(KTestDatabase3, KPolicyUid);
sl@0
   150
		}
sl@0
   151
	};
sl@0
   152
sl@0
   153
class TFailDeleteDatabase : public TFail
sl@0
   154
	{
sl@0
   155
	void RunL()
sl@0
   156
		{
sl@0
   157
		DbDeleteDatabaseL();
sl@0
   158
		}
sl@0
   159
	void End()
sl@0
   160
		{
sl@0
   161
		}
sl@0
   162
	};
sl@0
   163
sl@0
   164
/**
sl@0
   165
@SYMTestCaseID SYSLIB-DBMS-CT-0022
sl@0
   166
@SYMTestCaseDesc OOM test for the new "DBMS security" APIs.
sl@0
   167
@SYMTestPriority High
sl@0
   168
@SYMTestActions  Calling the new "DBMS security" APIs under OOM conditions.
sl@0
   169
@SYMTestExpectedResults The test must not fail.
sl@0
   170
@SYMREQ REQ2429
sl@0
   171
                 DBMS shall provide an API to apply security policies to database tables.
sl@0
   172
*/
sl@0
   173
GLDEF_C void Origins2()
sl@0
   174
   	{
sl@0
   175
	Connect();
sl@0
   176
	(void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid);
sl@0
   177
	Disconnect();
sl@0
   178
sl@0
   179
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0022 Allocation failures on creating a secure shared database "));
sl@0
   180
	TFailCreateDatabase2 t1;
sl@0
   181
	Connect();
sl@0
   182
	(void)TheDbs.DeleteDatabase(KTestDatabase2, KPolicyUid);
sl@0
   183
	t1.Test(KClientHeap);
sl@0
   184
	t1.Test(KServerHeap);
sl@0
   185
	Disconnect();
sl@0
   186
sl@0
   187
	Connect();
sl@0
   188
	test(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2) == KErrNone);
sl@0
   189
	(void)TheDatabase.Close();
sl@0
   190
	Disconnect();
sl@0
   191
sl@0
   192
	Connect();
sl@0
   193
sl@0
   194
	test.Next(_L("Allocation failures on opening a secure shared database"));
sl@0
   195
	TFailOpenDatabase2 t2;
sl@0
   196
	t2.Test(KClientHeap);
sl@0
   197
	t2.Test(KServerHeap);
sl@0
   198
sl@0
   199
	test.Next(_L("Allocation failures on getting secure shared databases list"));
sl@0
   200
	TFailDatabaseNames t_dbNames;
sl@0
   201
	t_dbNames.Test(KClientHeap);
sl@0
   202
	t_dbNames.Test(KServerHeap);
sl@0
   203
	TheDatabase.Close();
sl@0
   204
sl@0
   205
	test.Next(_L("Allocation failures on copying secure shared databases"));
sl@0
   206
	TFailCopyDatabase t_copyDb;
sl@0
   207
	t_copyDb.Test(KClientHeap);
sl@0
   208
	t_copyDb.Test(KServerHeap);
sl@0
   209
sl@0
   210
	test.Next(_L("Allocation failures on deleting secure shared databases"));
sl@0
   211
	TFailDeleteDatabase t_deleteDb;
sl@0
   212
	t_deleteDb.Test(KClientHeap);
sl@0
   213
	test(TheDatabase.Create(TheDbs, KTestDatabase2, TheFormat2) == KErrNone);
sl@0
   214
	(void)TheDatabase.Close();
sl@0
   215
	t_deleteDb.Test(KServerHeap);
sl@0
   216
sl@0
   217
	Disconnect();
sl@0
   218
sl@0
   219
   	test.End();
sl@0
   220
   	}
sl@0
   221