|
1 // Copyright (c) 2007-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 #include <f32file.h> |
|
17 #include <e32test.h> |
|
18 #include <e32math.h> |
|
19 #include <sqlite3.h> |
|
20 #include "t_sqlitewsd.h" |
|
21 |
|
22 /////////////////////////////////////////////////////////////////////////////////////// |
|
23 static RTest TheTest(_L("t_sqlitewsd2 test")); |
|
24 |
|
25 const char* KTestDb = "c:\\test\\t_sqlitewsd.db"; |
|
26 |
|
27 sqlite3* TheDb = 0; |
|
28 |
|
29 _LIT(KPanicCategory, "t_sqlitewsd2"); |
|
30 |
|
31 const TInt KExprEvalFailed1 = -1001; |
|
32 const TInt KExprEvalFailed2 = -1002; |
|
33 |
|
34 /////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
36 static void DestroyTestEnv() |
|
37 { |
|
38 if(TheDb) |
|
39 { |
|
40 (void)sqlite3_close(TheDb); |
|
41 TheDb = 0; |
|
42 } |
|
43 } |
|
44 |
|
45 /////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
47 static void Panic(TInt aLine, TInt aPanicCode) |
|
48 { |
|
49 TBuf<64> buf; |
|
50 _LIT(KFormat,"*** Panic %d, at line t_sqlitewsd2.cpp(%d)\r\n"); |
|
51 buf.Format(KFormat, aPanicCode, aLine); |
|
52 RDebug::Print(buf); |
|
53 User::Panic(KPanicCategory, aPanicCode); |
|
54 } |
|
55 |
|
56 //Test macros and functions |
|
57 void Check(TInt aValue, TInt aLine) |
|
58 { |
|
59 if(!aValue) |
|
60 { |
|
61 DestroyTestEnv(); |
|
62 RDebug::Print(_L("*** Expression evaluates to false.\r\n")); |
|
63 Panic(aLine, KExprEvalFailed1); |
|
64 } |
|
65 } |
|
66 |
|
67 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
68 { |
|
69 if(aValue != aExpected) |
|
70 { |
|
71 RDebug::Print(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue); |
|
72 const char* errMsg = sqlite3_errmsg(TheDb); |
|
73 if(errMsg) |
|
74 { |
|
75 TBuf<200> msgBuf; |
|
76 msgBuf.Copy(TPtrC8((const TUint8*)errMsg)); |
|
77 RDebug::Print(_L("*** SQLITE error msg: \"%S\".\r\n"), &msgBuf); |
|
78 } |
|
79 DestroyTestEnv(); |
|
80 Panic(aLine, KExprEvalFailed2); |
|
81 } |
|
82 } |
|
83 |
|
84 /////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
86 static void CreateTestEnv() |
|
87 { |
|
88 TInt err = sqlite3_open(KTestDb, &TheDb); |
|
89 TEST2(err, SQLITE_OK); |
|
90 TEST(TheDb != 0); |
|
91 } |
|
92 |
|
93 /////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
95 TInt E32Main() |
|
96 { |
|
97 CTrapCleanup* tc = CTrapCleanup::New(); |
|
98 if(!tc) |
|
99 { |
|
100 User::Panic(KPanicCategory, KErrNoMemory) ; |
|
101 } |
|
102 |
|
103 __UHEAP_MARK; |
|
104 |
|
105 TheTest.Title(); |
|
106 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLITEWSD2-0001 ")); |
|
107 CreateTestEnv(); |
|
108 DoInserts(KWsdProc2Id, KWsdProc2RecId1, KWsdProc2RecId2); |
|
109 DestroyTestEnv(); |
|
110 TheTest.End(); |
|
111 TheTest.Close(); |
|
112 |
|
113 __UHEAP_MARKEND; |
|
114 |
|
115 delete tc; |
|
116 |
|
117 User::Heap().Check(); |
|
118 return KErrNone; |
|
119 } |