os/persistentdata/persistentstorage/dbms/tdbms/t_dbplatsectbl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// DBMS security policy - testing new APIs - table level.
sl@0
    15
// All tests assume that drive C is presented in the system and is not a ROM drive.
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "t_dbplatsecutl.h"
sl@0
    20
#include "t_dbplatsecdef.h"
sl@0
    21
#include "t_dbplatsectbl.h"
sl@0
    22
sl@0
    23
static TColDef const KColumns[]=
sl@0
    24
	{
sl@0
    25
	{_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement},
sl@0
    26
	{_S("DATA1"), EDbColInt32, TDbCol::ENotNull},
sl@0
    27
	{_S("DATA2"), EDbColInt32, TDbCol::ENotNull},
sl@0
    28
	{0}
sl@0
    29
	};
sl@0
    30
sl@0
    31
static TColDef const KColumns2[]=
sl@0
    32
	{
sl@0
    33
	{_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement},
sl@0
    34
	{_S("DATA1"), EDbColLongBinary},
sl@0
    35
	{0}
sl@0
    36
	};
sl@0
    37
sl@0
    38
static void TblCallTestL()
sl@0
    39
	{
sl@0
    40
	TheTest.Next(_L("Open()"));	
sl@0
    41
	TInt err = TheTbl1.Open(TheDb1, KTableName1);
sl@0
    42
	TEST2(err, KErrNone);
sl@0
    43
	
sl@0
    44
	TheTest.Next(_L("ColSetL()"));	
sl@0
    45
	CDbColSet* colset = TheTbl1.ColSetL();
sl@0
    46
	TInt cnt = colset->Count();
sl@0
    47
	TInt i;
sl@0
    48
	for(i=0;i<cnt;++i)
sl@0
    49
		{
sl@0
    50
		const TDbCol& dbc = (*colset)[i + 1];
sl@0
    51
		TheTest.Printf(_L("%02d, %S\n"), i + 1, &dbc.iName);
sl@0
    52
		}
sl@0
    53
	delete colset;
sl@0
    54
	
sl@0
    55
	TheTest.Next(_L("ColDef()"));	
sl@0
    56
	TDbCol dbcol = TheTbl1.ColDef(1);
sl@0
    57
	TheTest.Printf(_L("%S\n"), &dbcol.iName);
sl@0
    58
sl@0
    59
	TheTest.Next(_L("InsertL()/SetColL()/PutL()"));	
sl@0
    60
	TheTbl1.InsertL();
sl@0
    61
	TheTbl1.SetColL(2, 1);
sl@0
    62
	TheTbl1.SetColL(3, 2);
sl@0
    63
	TheTbl1.PutL();
sl@0
    64
	TheTbl1.InsertL();
sl@0
    65
	TheTbl1.SetColL(2, 3);
sl@0
    66
	TheTbl1.SetColL(3, 4);
sl@0
    67
	TheTbl1.PutL();
sl@0
    68
	
sl@0
    69
	TheTest.Next(_L("AtRow()/AtBeginning()/AtEnd()"));	
sl@0
    70
	(void)TheTbl1.AtRow();
sl@0
    71
	(void)TheTbl1.AtBeginning();
sl@0
    72
	(void)TheTbl1.AtEnd();
sl@0
    73
sl@0
    74
	TheTest.Next(_L("BeginningL()/EndL()"));	
sl@0
    75
	TheTbl1.BeginningL();
sl@0
    76
	TheTbl1.EndL();
sl@0
    77
sl@0
    78
	TheTest.Next(_L("FirstL()/LastL()/PreviousL()/PreviousL()"));	
sl@0
    79
	TBool res = TheTbl1.FirstL();
sl@0
    80
	TEST(res);
sl@0
    81
	TheTbl1.GetL();
sl@0
    82
	TInt32 val1 = TheTbl1.ColInt32(1);
sl@0
    83
	TInt32 val2 = TheTbl1.ColInt32(2);
sl@0
    84
	TInt32 val3 = TheTbl1.ColInt32(3);
sl@0
    85
	TEST(val1 == 0);
sl@0
    86
	TEST(val2 == 1);
sl@0
    87
	TEST(val3 == 2);
sl@0
    88
	
sl@0
    89
	res = TheTbl1.LastL();
sl@0
    90
	TEST(res);
sl@0
    91
	TheTbl1.GetL();
sl@0
    92
	val1 = TheTbl1.ColInt32(1);
sl@0
    93
	val2 = TheTbl1.ColInt32(2);
sl@0
    94
	val3 = TheTbl1.ColInt32(3);
sl@0
    95
	TEST(val1 == 1);
sl@0
    96
	TEST(val2 == 3);
sl@0
    97
	TEST(val3 == 4);
sl@0
    98
sl@0
    99
	res = TheTbl1.PreviousL();
sl@0
   100
	TEST(res);
sl@0
   101
	TheTbl1.GetL();
sl@0
   102
	val1 = TheTbl1.ColInt32(1);
sl@0
   103
	val2 = TheTbl1.ColInt32(2);
sl@0
   104
	val3 = TheTbl1.ColInt32(3);
sl@0
   105
	TEST(val1 == 0);
sl@0
   106
	TEST(val2 == 1);
sl@0
   107
	TEST(val3 == 2);
sl@0
   108
	
sl@0
   109
	res = TheTbl1.NextL();
sl@0
   110
	TEST(res);
sl@0
   111
	TheTbl1.GetL();
sl@0
   112
	val1 = TheTbl1.ColInt32(1);
sl@0
   113
	val2 = TheTbl1.ColInt32(2);
sl@0
   114
	val3 = TheTbl1.ColInt32(3);
sl@0
   115
	TEST(val1 == 1);
sl@0
   116
	TEST(val2 == 3);
sl@0
   117
	TEST(val3 == 4);
sl@0
   118
sl@0
   119
	TheTest.Next(_L("UpdateL()"));	
sl@0
   120
	TheTbl1.UpdateL();
sl@0
   121
	TheTbl1.SetColL(2, 33);
sl@0
   122
	TheTbl1.SetColL(3, 44);
sl@0
   123
	TheTbl1.PutL();
sl@0
   124
sl@0
   125
	TheTest.Next(_L("Cancel()"));	
sl@0
   126
	TheTbl1.UpdateL();
sl@0
   127
	TheTbl1.SetColL(2, 36);
sl@0
   128
	TheTbl1.SetColL(3, 47);
sl@0
   129
	TheTbl1.Cancel();
sl@0
   130
sl@0
   131
	TheTest.Next(_L("DeleteL()"));	
sl@0
   132
	TheTbl1.DeleteL();
sl@0
   133
sl@0
   134
	TheTest.Next(_L("IsColNull()"));	
sl@0
   135
	CDbColSet* colset2 = TDBSCUtils::CreateColSetLC(KColumns2);
sl@0
   136
	_LIT(KTempTblName, "TempTbl");
sl@0
   137
	err = TheDb1.CreateTable(KTempTblName, *colset2);
sl@0
   138
	TEST2(err, KErrNone);
sl@0
   139
	CleanupStack::PopAndDestroy(colset2);
sl@0
   140
sl@0
   141
	err = TheTbl2.Open(TheDb1, KTempTblName);
sl@0
   142
	TEST2(err, KErrNone);
sl@0
   143
sl@0
   144
	TheTbl2.InsertL();
sl@0
   145
	_LIT8(KTestData, "");
sl@0
   146
	TheTbl2.SetColL(2, KTestData);
sl@0
   147
	TheTbl2.PutL();
sl@0
   148
	
sl@0
   149
	TheTbl2.Close();
sl@0
   150
	err = TheTbl2.Open(TheDb1, KTempTblName);
sl@0
   151
	TEST2(err, KErrNone);
sl@0
   152
	res = TheTbl2.FirstL();
sl@0
   153
	TEST(res);
sl@0
   154
	TheTbl2.GetL();
sl@0
   155
	res = TheTbl2.IsColNull(2);
sl@0
   156
	TEST(res);
sl@0
   157
	TheTbl2.Close();
sl@0
   158
	
sl@0
   159
	TheTest.Next(_L("ColSize()"));	
sl@0
   160
	res = TheTbl1.FirstL();
sl@0
   161
	TEST(res);
sl@0
   162
	TheTbl1.GetL();
sl@0
   163
	res = TheTbl1.ColSize(1);
sl@0
   164
	TEST(res);
sl@0
   165
		
sl@0
   166
	TheTest.Next(_L("ColLength()"));	
sl@0
   167
	TInt len = TheTbl1.ColLength(1);
sl@0
   168
	TEST(len > 0);
sl@0
   169
sl@0
   170
	TheTbl1.InsertL();
sl@0
   171
	TheTbl1.SetColL(2, 3);
sl@0
   172
	TheTbl1.SetColL(3, 4);
sl@0
   173
	TheTbl1.PutL();
sl@0
   174
sl@0
   175
	TheTest.Next(_L("GotoL(TPosition)"));	
sl@0
   176
	res = TheTbl1.GotoL(RDbRowSet::EFirst);
sl@0
   177
	TEST(res);
sl@0
   178
	
sl@0
   179
	TheTest.Next(_L("Bookmark()/GotoL(TDbBookmark)"));	
sl@0
   180
	TDbBookmark bkmk = TheTbl1.Bookmark();
sl@0
   181
	res = TheTbl1.NextL();
sl@0
   182
	TEST(res);
sl@0
   183
	TheTbl1.GotoL(bkmk);
sl@0
   184
	TheTbl1.GetL();
sl@0
   185
	val1 = TheTbl1.ColInt32(1);
sl@0
   186
	TEST(val1 == 0);
sl@0
   187
	
sl@0
   188
	TheTest.Next(_L("CountL()/IsEmptyL()"));	
sl@0
   189
	cnt = TheTbl1.CountL();
sl@0
   190
	TEST(cnt == 2);
sl@0
   191
	res = TheTbl1.IsEmptyL();
sl@0
   192
	TEST(!res);
sl@0
   193
	
sl@0
   194
	TheTest.Next(_L("MatchL()"));	
sl@0
   195
	RDbRowConstraint match;
sl@0
   196
	CleanupClosePushL(match);
sl@0
   197
	err = match.Open(TheTbl1, TDbQuery(_L("ID > 0")));
sl@0
   198
	TEST2(err, KErrNone);
sl@0
   199
	res = EFalse;
sl@0
   200
	TheTbl1.BeginningL();
sl@0
   201
	while(TheTbl1.NextL())
sl@0
   202
		{
sl@0
   203
		if(TheTbl1.MatchL(match))
sl@0
   204
			{
sl@0
   205
			res = ETrue;
sl@0
   206
			}
sl@0
   207
		}
sl@0
   208
	CleanupStack::PopAndDestroy(&match);
sl@0
   209
	TEST(res);
sl@0
   210
sl@0
   211
	TheTest.Next(_L("FindL()"));	
sl@0
   212
	res = TheTbl1.FirstL();
sl@0
   213
	TEST(res);
sl@0
   214
	err = TheTbl1.FindL(RDbRowSet::EForwards, TDbQuery(_L("ID <> 0")));
sl@0
   215
	TEST(err >= 0);
sl@0
   216
	TheTbl1.GetL();
sl@0
   217
	val1 = TheTbl1.ColInt32(1);
sl@0
   218
	TEST(val1 > 0);
sl@0
   219
sl@0
   220
	_LIT8(KTestData2, "0123456789");
sl@0
   221
	HBufC8* buf = HBufC8::NewLC(10000);
sl@0
   222
	TPtr8 ptr = buf->Des(); 
sl@0
   223
	for(i=0;i<1000;++i)
sl@0
   224
		{
sl@0
   225
		ptr += KTestData2();
sl@0
   226
		}
sl@0
   227
	
sl@0
   228
	TheTest.Next(_L("RDbColReadStream"));	
sl@0
   229
	err = TheTbl2.Open(TheDb1, KTempTblName);
sl@0
   230
	TEST2(err, KErrNone);
sl@0
   231
sl@0
   232
	TheTbl2.InsertL();
sl@0
   233
	TheTbl2.SetColL(2, *buf);
sl@0
   234
	TheTbl2.PutL();
sl@0
   235
	
sl@0
   236
	TheTbl2.InsertL();
sl@0
   237
	TheTbl2.SetColL(2, KTestData2);
sl@0
   238
	TheTbl2.PutL();
sl@0
   239
	
sl@0
   240
	res = TheTbl2.PreviousL();
sl@0
   241
	TEST(res);
sl@0
   242
	TheTbl2.GetL();
sl@0
   243
	RDbColReadStream rstream;
sl@0
   244
	rstream.OpenLC(TheTbl2, 2);
sl@0
   245
	ptr.Zero();
sl@0
   246
	rstream.ReadL(ptr, ptr.MaxLength());
sl@0
   247
	CleanupStack::PopAndDestroy(&rstream);
sl@0
   248
	TEST(ptr.Length() == ptr.MaxLength());
sl@0
   249
sl@0
   250
	TheTest.Next(_L("RDbColWriteStream"));	
sl@0
   251
	TheTbl2.InsertL();
sl@0
   252
	RDbColWriteStream wstream;
sl@0
   253
	wstream.OpenLC(TheTbl2, 2);
sl@0
   254
	wstream.WriteL(ptr, ptr.Length());
sl@0
   255
	wstream.CommitL();
sl@0
   256
	CleanupStack::PopAndDestroy(&wstream);
sl@0
   257
	TheTbl2.PutL();
sl@0
   258
	
sl@0
   259
	TheTbl2.Close();
sl@0
   260
	CleanupStack::PopAndDestroy(buf);
sl@0
   261
			
sl@0
   262
	TheTbl1.Close();
sl@0
   263
	}
sl@0
   264
sl@0
   265
static void ViewTestL()
sl@0
   266
	{
sl@0
   267
	RDbView view;
sl@0
   268
	CleanupClosePushL(view);
sl@0
   269
	
sl@0
   270
	TheTest.Next(_L("Prepare()"));	
sl@0
   271
	TInt err = view.Prepare(TheDb1, TDbQuery(_L("SELECT * FROM ATbl")));
sl@0
   272
	TEST2(err, KErrNone);
sl@0
   273
	
sl@0
   274
	TheTest.Next(_L("Update()"));	
sl@0
   275
	TBool res = view.FirstL();
sl@0
   276
	TEST(res);
sl@0
   277
	view.GetL();
sl@0
   278
	view.UpdateL();
sl@0
   279
	view.SetColL(2, 100);
sl@0
   280
	view.SetColL(3, 200);
sl@0
   281
	view.PutL();
sl@0
   282
	
sl@0
   283
	CleanupStack::PopAndDestroy(&view);
sl@0
   284
sl@0
   285
	TheTest.Next(_L("Prepare() with an update sql"));	
sl@0
   286
	CleanupClosePushL(view);
sl@0
   287
	err = view.Prepare(TheDb1, TDbQuery(_L("UPDATE ATbl SET DATA1 = 400 WHERE ID = 0")));
sl@0
   288
	TEST2(err, KErrArgument);
sl@0
   289
	CleanupStack::PopAndDestroy(&view);
sl@0
   290
	}
sl@0
   291
sl@0
   292
/**
sl@0
   293
@SYMTestCaseID SYSLIB-DBMS-CT-0021
sl@0
   294
@SYMTestCaseDesc RDbTable method calls test for a secure shared database.
sl@0
   295
                 Every method of RDbTable class and its base class too, is called
sl@0
   296
				 and the result - asserted.
sl@0
   297
@SYMTestPriority High
sl@0
   298
@SYMTestActions  RDbTable method calls test.
sl@0
   299
@SYMTestExpectedResults The test must not fail.
sl@0
   300
@SYMREQ          REQ2429
sl@0
   301
                 DBMS shall provide an API to apply security policies to database tables.
sl@0
   302
*/
sl@0
   303
void DoTblTestL()
sl@0
   304
	{
sl@0
   305
	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-DBMS-CT-0021 "));
sl@0
   306
	
sl@0
   307
	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
sl@0
   308
	
sl@0
   309
	TheDb1.Close();
sl@0
   310
	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
sl@0
   311
sl@0
   312
	CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns);
sl@0
   313
	TInt err = TheDb1.CreateTable(KTableName1, *colset);
sl@0
   314
	TEST2(err, KErrNone);
sl@0
   315
	CleanupStack::PopAndDestroy(colset);
sl@0
   316
sl@0
   317
	TheTest.Next(_L("Table calls test"));	
sl@0
   318
	::TblCallTestL();
sl@0
   319
	
sl@0
   320
	TheTest.Next(_L("View test"));	
sl@0
   321
	::ViewTestL();
sl@0
   322
	
sl@0
   323
	TheDb1.Close();
sl@0
   324
	}