|
1 // Copyright (c) 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 /** |
|
17 Instructions: |
|
18 |
|
19 This is a manual test created to verify DEFXXXXX, 2 executables needs to be run to do this test |
|
20 1) t_sqlfilesrvcrash1.exe - Generate a corrupted journal file, this will cause the device to reset. |
|
21 2) t_sqlfilesrvcrash2.exe - After the reboot, tests if SQL can handle the courrpted journal file. |
|
22 |
|
23 This test requires a non-rugged drive to store the database file and therefore will only work in hardware mode |
|
24 */ |
|
25 |
|
26 #include <e32test.h> |
|
27 #include <f32file.h> |
|
28 #include <Sqldb.h> |
|
29 |
|
30 RTest TheTest(_L("t_sqlfilesrvcrash2 test")); |
|
31 |
|
32 #if !defined __WINS__ && !defined __WINSCW__ |
|
33 |
|
34 RFs TheFs; |
|
35 RSqlDatabase TheDb; |
|
36 |
|
37 _LIT(KDbName, "E:\\test\\t_sqlfilesrvcrash.db"); |
|
38 _LIT(KJournalName, "E:\\test\t_sqlfilesrvcrash.db-journal"); |
|
39 /////////////////////////////////////////////////////////////////////////////////////// |
|
40 //Deletes all created test files. |
|
41 void DeleteTestFiles() |
|
42 { |
|
43 TheDb.Close(); |
|
44 (void)RSqlDatabase::Delete(KDbName); |
|
45 } |
|
46 |
|
47 /////////////////////////////////////////////////////////////////////////////////////// |
|
48 //Test macros and functions |
|
49 void Check(TInt aValue, TInt aLine) |
|
50 { |
|
51 if(!aValue) |
|
52 { |
|
53 RDebug::Print(_L("*** Line %d\r\n"), aLine); |
|
54 TheTest(EFalse, aLine); |
|
55 } |
|
56 } |
|
57 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
58 { |
|
59 if(aValue != aExpected) |
|
60 { |
|
61 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
62 TheTest(EFalse, aLine); |
|
63 } |
|
64 } |
|
65 |
|
66 #define TEST(arg) ::Check((arg), __LINE__) |
|
67 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
68 /////////////////////////////////////////////////////////////////////////////////////// |
|
69 //Creates file session instance and the test directory |
|
70 void CreateTestEnv() |
|
71 { |
|
72 TInt err = TheFs.Connect(); |
|
73 TEST2(err, KErrNone); |
|
74 |
|
75 RFile file; |
|
76 err = file.Open(TheFs, KJournalName, EFileRead); |
|
77 TEST2(err, KErrNone); |
|
78 |
|
79 TInt size; |
|
80 err = file.Size(size); |
|
81 TEST2(err, KErrNone); |
|
82 TEST(size > SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT); |
|
83 file.Close(); |
|
84 } |
|
85 /////////////////////////////////////////////////////////////////////////////////////// |
|
86 /** |
|
87 @SYMTestCaseID PDS-SQL-CT-4165 |
|
88 @SYMTestCaseDesc Tests for DEF144027: SQL Open returns error if the reported and actual file size are different |
|
89 Requires a corrupted journal file to be created using t_sqlfilesrvcrash1.exe before running |
|
90 this test. If a corrupted journal file exists then check that the opening the database does not |
|
91 return an error. |
|
92 @SYMTestActions DEF144027: SQL Open returns error if the reported and actual file size are different |
|
93 @SYMTestExpectedResults The RSqlDatabase::Open operation should not fail |
|
94 @SYMTestPriority Medium |
|
95 @SYMDEF DEF144027 |
|
96 DEF144238 |
|
97 */ |
|
98 void DEF144027() |
|
99 { |
|
100 TInt err = TheDb.Open(KDbName); |
|
101 TEST2(err, KErrNone); |
|
102 |
|
103 //Lets perform a simple operation to make sure it works |
|
104 err = TheDb.Exec(_L("BEGIN")); |
|
105 TEST(err >= 0); |
|
106 |
|
107 err = TheDb.Exec(_L("INSERT INTO t1(NUM) VALUES (55)")); |
|
108 TEST2(err, 1); |
|
109 |
|
110 err = TheDb.Exec(_L("INSERT INTO t2(NUM) VALUES (55)")); |
|
111 TEST2(err, 1); |
|
112 |
|
113 err = TheDb.Exec(_L("COMMIT")); |
|
114 TEST(err >= 0); |
|
115 |
|
116 TheDb.Close(); |
|
117 } |
|
118 |
|
119 void DoTests() |
|
120 { |
|
121 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-CT-4165 DEF144027: SQL Open returns error if the reported and actual file size are different")); |
|
122 DEF144027(); |
|
123 } |
|
124 #endif //#if !defined __WINS__ && !defined __WINSCW__ |
|
125 |
|
126 TInt E32Main() |
|
127 { |
|
128 TheTest.Title(); |
|
129 |
|
130 CTrapCleanup* tc = CTrapCleanup::New(); |
|
131 |
|
132 __UHEAP_MARK; |
|
133 |
|
134 #if !defined __WINS__ && !defined __WINSCW__ |
|
135 DoTests(); |
|
136 DeleteTestFiles(); |
|
137 TheFs.Close(); |
|
138 TheTest.End(); |
|
139 #else |
|
140 TheTest.Start(_L("This test works only works on hardware!")); |
|
141 TheTest.End(); |
|
142 #endif |
|
143 |
|
144 __UHEAP_MARKEND; |
|
145 |
|
146 TheTest.Close(); |
|
147 |
|
148 delete tc; |
|
149 |
|
150 User::Heap().Check(); |
|
151 return KErrNone; |
|
152 } |