1 // Copyright (c) 2001-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 // This contains CommDb Unit Test Cases 0064.XX |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <commdb.h> |
|
21 |
|
22 |
|
23 // Test system includes |
|
24 #include <networking/log.h> |
|
25 #include <networking/teststep.h> |
|
26 #include "Teststepcommdb.h" |
|
27 #include "TestSuiteCommdb.h" |
|
28 #include "Step_064_xx.h" |
|
29 |
|
30 #include <commsdattypeinfov1_1.h> |
|
31 #include <commsdattypesv1_1.h> |
|
32 #include <commsdat_partner.h> |
|
33 |
|
34 |
|
35 // table name |
|
36 _LIT(KCDTypeNameTestTable, "Test"); |
|
37 |
|
38 #define KCDTypeNameBinaryFieldTest _S("BinaryTest") |
|
39 |
|
40 // record type id |
|
41 const TMDBElementId KCDTIdTestRecord = 0x5F800000; |
|
42 // field type ids |
|
43 const TMDBElementId KCDTIdTestBinaryField = 0x00150000; |
|
44 |
|
45 |
|
46 static const SGenericRecordTypeInfo TestGenRecordInfoBinary[] = |
|
47 { |
|
48 MDB_GENERIC_TYPE_INFO(KCDTIdRecordTag, EUint32, ENoAttrs, KCDTypeNameRecordTag), |
|
49 MDB_GENERIC_TYPE_INFO(KCDTIdRecordName, EText, ENotNull, KCDTypeNameRecordName), |
|
50 MDB_GENERIC_TYPE_INFO(KCDTIdTestBinaryField, EDesC8, ENoAttrs, KCDTypeNameBinaryFieldTest), |
|
51 MDB_GENERIC_TYPE_INFO(0, 0, ENoAttrs, KCDNull) |
|
52 }; |
|
53 |
|
54 |
|
55 |
|
56 NONSHARABLE_CLASS(CCDTestBinaryRecord) : public CCDRecordBase |
|
57 { |
|
58 public : |
|
59 |
|
60 // Constructor |
|
61 CCDTestBinaryRecord(TMDBElementId aElementId) |
|
62 : CCDRecordBase(aElementId), |
|
63 iBinaryField((aElementId & KCDMaskShowRecordType) | KCDTIdTestBinaryField), |
|
64 iRecordTag((aElementId & KCDMaskShowRecordType) | KCDTIdRecordTag), |
|
65 iRecordName((aElementId & KCDMaskShowRecordType) | KCDTIdRecordName) |
|
66 {} |
|
67 |
|
68 const SRecordTypeInfo* GetRecordInfo(){return iRecordInfo;} |
|
69 |
|
70 DATA_VTABLE |
|
71 |
|
72 public : |
|
73 |
|
74 CMDBField<TDesC8> iBinaryField; |
|
75 CMDBField<TInt> iRecordTag; |
|
76 CMDBField<TDesC> iRecordName; |
|
77 |
|
78 private: |
|
79 |
|
80 static const SRecordTypeInfo iRecordInfo[]; |
|
81 }; |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 const SRecordTypeInfo CCDTestBinaryRecord::iRecordInfo[]= |
|
87 { |
|
88 { KCDTIdRecordTag, EInt, ENoAttrs, KCDTypeNameRecordTag }, |
|
89 { KCDTIdRecordName, EText, ENotNull, KCDTypeNameRecordName }, |
|
90 { KCDTIdTestBinaryField, EDesC8, ENotNull, KCDTypeNameBinaryFieldTest }, |
|
91 { 0, 0, ENoAttrs, KCDNull } |
|
92 }; |
|
93 |
|
94 |
|
95 START_ATTRIBUTE_TABLE(CCDTestBinaryRecord, KCDTIdTestRecord, KCDTIdTestRecord ) |
|
96 X_REGISTER_ATTRIBUTE(CCDTestBinaryRecord, iBinaryField, TMDBBin) |
|
97 X_REGISTER_ATTRIBUTE(CCDTestBinaryRecord, iRecordTag, TMDBNum ) |
|
98 X_REGISTER_ATTRIBUTE(CCDTestBinaryRecord, iRecordName, TMDBText ) |
|
99 END_ATTRIBUTE_TABLE() |
|
100 |
|
101 |
|
102 _LIT8(KTestBinary, "a long binary string,a long binary string,a long binary string,a long binary string,a long binary string,a long binary string,a long binary string,end"); |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 // |
|
109 // Test step 064.001 |
|
110 // |
|
111 |
|
112 // constructor |
|
113 CCommDbTest064_01::CCommDbTest064_01() |
|
114 { |
|
115 // store the name of this test case |
|
116 iTestStepName = _L("step_064_01"); |
|
117 } |
|
118 |
|
119 // destructor |
|
120 CCommDbTest064_01::~CCommDbTest064_01() |
|
121 { |
|
122 } |
|
123 |
|
124 |
|
125 TInt CCommDbTest064_01::executeStepL() |
|
126 { |
|
127 TInt ret=KErrGeneral; |
|
128 |
|
129 //set up a generic record with a binary field |
|
130 INFO_PRINTF1(_L("Creating a user defined table")); |
|
131 |
|
132 CMDBSession *cmdbSession = CMDBSession::NewL(KCDVersion1_1); |
|
133 |
|
134 CleanupStack::PushL(cmdbSession); |
|
135 |
|
136 CMDBGenericRecord* testRecord = static_cast<CMDBGenericRecord*>(CCDRecordBase::RecordFactoryL(KCDNewTableRequest)); |
|
137 CleanupStack::PushL(testRecord); |
|
138 testRecord->InitializeL(KCDTypeNameTestTable(), TestGenRecordInfoBinary); |
|
139 |
|
140 testRecord->StoreL(*cmdbSession); |
|
141 CleanupStack::PopAndDestroy(testRecord); |
|
142 CleanupStack::PopAndDestroy(cmdbSession); |
|
143 |
|
144 |
|
145 //now use commdbshim api to read and write to the binary field |
|
146 CCommsDatabase* theDb; |
|
147 CCommsDbTableView* theView; |
|
148 TUint32 recordId; |
|
149 |
|
150 //CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
151 theDb = CCommsDatabase::NewL(); |
|
152 theView = theDb->OpenTableLC( KCDTypeNameTestTable ); |
|
153 CleanupStack::Pop(); |
|
154 |
|
155 TBuf8<KMaxLongTextLength> value(KTestBinary); |
|
156 CDBLEAVE(theView->InsertRecord(recordId), KErrNone ); |
|
157 theView->WriteTextL(TPtrC(KCDTypeNameBinaryFieldTest), value ); |
|
158 CDBLEAVE(theView->PutRecordChanges(), KErrNone ); |
|
159 CDBLEAVE(theView->GotoFirstRecord(), KErrNone ); |
|
160 |
|
161 TBuf8<KMaxLongTextLength> value2; |
|
162 theView->ReadTextL( TPtrC(KCDTypeNameBinaryFieldTest), value2 ); |
|
163 |
|
164 if( value2.Compare( value ) == 0) |
|
165 { |
|
166 ret = KErrNone; |
|
167 } |
|
168 |
|
169 delete theView; |
|
170 delete theDb; |
|
171 |
|
172 return ret; |
|
173 } |
|
174 |
|
175 |
|
176 TVerdict CCommDbTest064_01::doTestStepL( ) |
|
177 { |
|
178 Log(_L("Step 064.01 called ")); |
|
179 |
|
180 |
|
181 if ( executeStepL() == KErrNone ) |
|
182 iTestStepResult = EPass; |
|
183 else |
|
184 iTestStepResult = EFail; |
|
185 |
|
186 |
|
187 return iTestStepResult; |
|
188 } |
|
189 |
|
190 |
|