1 /* |
1 /* |
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
18 |
18 |
19 #include "TSTCLIPB.H" |
19 #include "TSTCLIPB.H" |
20 #include <txtglobl.h> |
20 #include <txtglobl.h> |
21 #include <s32mem.h> |
21 #include <s32mem.h> |
22 #include <s32file.h> |
22 #include <s32file.h> |
23 #include "T_CUTPST.h" |
23 #include <e32test.h> |
24 |
|
25 LOCAL_D CTestStep *pTestStep = NULL; |
|
26 #define test(cond) \ |
|
27 { \ |
|
28 TBool __bb = (cond); \ |
|
29 pTestStep->TEST(__bb); \ |
|
30 if (!__bb) \ |
|
31 { \ |
|
32 pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \ |
|
33 User::Leave(1); \ |
|
34 } \ |
|
35 } |
|
36 #undef INFO_PRINTF1 |
|
37 #undef INFO_PRINTF2 |
|
38 // copy from tefexportconst.h |
|
39 #define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) |
|
40 #define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) |
|
41 |
24 |
42 #define UNUSED_VAR(a) a = a |
25 #define UNUSED_VAR(a) a = a |
43 |
26 |
44 const TInt KTestCleanupStack=0x40; |
27 const TInt KTestCleanupStack=0x40; |
45 |
28 |
46 |
29 |
|
30 LOCAL_D RTest test(_L("Cut & Paste")); |
47 LOCAL_D CTrapCleanup* TheTrapCleanup=NULL; |
31 LOCAL_D CTrapCleanup* TheTrapCleanup=NULL; |
48 LOCAL_D CPlainText* TheTextObject=NULL; |
32 LOCAL_D CPlainText* TheTextObject=NULL; |
49 LOCAL_D CClipboard* TheWriteBoard=NULL; |
33 LOCAL_D CClipboard* TheWriteBoard=NULL; |
50 LOCAL_D CClipboard* TheReadBoard=NULL; |
34 LOCAL_D CClipboard* TheReadBoard=NULL; |
51 LOCAL_D RFs TheSession; |
35 LOCAL_D RFs TheSession; |
89 TheTextObject=CPlainText::NewL(); |
73 TheTextObject=CPlainText::NewL(); |
90 CleanupStack::PushL(TheTextObject); |
74 CleanupStack::PushL(TheTextObject); |
91 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
75 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
92 |
76 |
93 // Copy zero-length text to the clipboard. |
77 // Copy zero-length text to the clipboard. |
94 INFO_PRINTF1(_L("Copy zero-length text to the clipboard")); |
78 test.Next(_L("Copy zero-length text to the clipboard")); |
95 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,0); |
79 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,0); |
96 |
80 |
97 OpenReadClipboardLC(); |
81 OpenReadClipboardLC(); |
98 test(TheTextObject->DocumentLength()==0); |
82 test(TheTextObject->DocumentLength()==0); |
99 |
83 |
100 // Paste zero-length text from the clipboard. |
84 // Paste zero-length text from the clipboard. |
101 INFO_PRINTF1(_L("Paste zero-length text from the clipboard")); |
85 test.Next(_L("Paste zero-length text from the clipboard")); |
102 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
86 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
103 |
87 |
104 // Copy multiple paragraphs to the clipboard |
88 // Copy multiple paragraphs to the clipboard |
105 INFO_PRINTF1(_L("PasteFromStoreL(aPos,aMaxPasteLength)")); |
89 test.Next(_L("PasteFromStoreL(aPos,aMaxPasteLength)")); |
106 TBuf<512> buf(_L("Here is para one.")); |
90 TBuf<512> buf(_L("Here is para one.")); |
107 buf.Append(CEditableText::EParagraphDelimiter); |
91 buf.Append(CEditableText::EParagraphDelimiter); |
108 buf.Append(_L("This is paragraph two.")); |
92 buf.Append(_L("This is paragraph two.")); |
109 buf.Append(CEditableText::EParagraphDelimiter); |
93 buf.Append(CEditableText::EParagraphDelimiter); |
110 TheTextObject->InsertL(0,buf); |
94 TheTextObject->InsertL(0,buf); |
130 |
114 |
131 LOCAL_C void testPlainTextCutPaste() |
115 LOCAL_C void testPlainTextCutPaste() |
132 // |
116 // |
133 // |
117 // |
134 { |
118 { |
135 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-CPLAIN-0001 Cut&Paste - with plainText ")); |
119 test.Start(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-CPLAIN-0001 Cut&Paste - with plainText ")); |
136 TheTextObject=CPlainText::NewL(); |
120 TheTextObject=CPlainText::NewL(); |
137 CleanupStack::PushL(TheTextObject); |
121 CleanupStack::PushL(TheTextObject); |
138 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
122 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
139 test(TheTextObject->DocumentLength()==0); |
123 test(TheTextObject->DocumentLength()==0); |
140 // |
124 // |
141 INFO_PRINTF1(_L("Paste from empty store")); |
125 test.Next(_L("Paste from empty store")); |
142 OpenReadClipboardLC(); |
126 OpenReadClipboardLC(); |
143 TInt charCount=0; |
127 TInt charCount=0; |
144 TRAPD(ret, |
128 TRAPD(ret, |
145 charCount=TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength())); |
129 charCount=TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength())); |
146 UNUSED_VAR(ret); |
130 UNUSED_VAR(ret); |
147 if (charCount<=0) |
131 if (charCount<=0) |
148 INFO_PRINTF1(_L(" No recognised data to paste or clipboard empty\n\r")); |
132 test.Printf(_L(" No recognised data to paste or clipboard empty\n\r")); |
149 TInt fieldCount=TheTextObject->FieldCount(); |
133 TInt fieldCount=TheTextObject->FieldCount(); |
150 test(fieldCount==0); |
134 test(fieldCount==0); |
151 // |
135 // |
152 // INFO_PRINTF1(_L("Paste from clipboard with no recognised types")); |
136 // test.Next(_L("Paste from clipboard with no recognised types")); |
153 // WriteForeignDataToClipboardL(); |
137 // WriteForeignDataToClipboardL(); |
154 // |
138 // |
155 INFO_PRINTF1(_L("Paste into empty PlainText")); |
139 test.Next(_L("Paste into empty PlainText")); |
156 TheTextObject->InsertL(TheTextObject->DocumentLength(),_L("SomeData")); |
140 TheTextObject->InsertL(TheTextObject->DocumentLength(),_L("SomeData")); |
157 OpenWriteClipboardLC(); |
141 OpenWriteClipboardLC(); |
158 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,TheTextObject->DocumentLength()); |
142 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,TheTextObject->DocumentLength()); |
159 TheTextObject->Reset(); |
143 TheTextObject->Reset(); |
160 test(TheTextObject->DocumentLength()==0); |
144 test(TheTextObject->DocumentLength()==0); |
162 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
146 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
163 test(TheTextObject->DocumentLength()==_L("SomeData").Length()); |
147 test(TheTextObject->DocumentLength()==_L("SomeData").Length()); |
164 fieldCount=TheTextObject->FieldCount(); |
148 fieldCount=TheTextObject->FieldCount(); |
165 test(fieldCount==0); |
149 test(fieldCount==0); |
166 // |
150 // |
167 INFO_PRINTF1(_L("Paste @ start (pos=0)")); |
151 test.Next(_L("Paste @ start (pos=0)")); |
168 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
152 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
169 test(TheTextObject->DocumentLength()==_L("SomeDataSomeData").Length()); |
153 test(TheTextObject->DocumentLength()==_L("SomeDataSomeData").Length()); |
170 fieldCount=TheTextObject->FieldCount(); |
154 fieldCount=TheTextObject->FieldCount(); |
171 test(fieldCount==0); |
155 test(fieldCount==0); |
172 // |
156 // |
173 INFO_PRINTF1(_L("Paste @ end (DocumentLength())")); |
157 test.Next(_L("Paste @ end (DocumentLength())")); |
174 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
158 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
175 test(TheTextObject->DocumentLength()==_L("SomeDataSomeDataSomeData").Length()); |
159 test(TheTextObject->DocumentLength()==_L("SomeDataSomeDataSomeData").Length()); |
176 fieldCount=TheTextObject->FieldCount(); |
160 fieldCount=TheTextObject->FieldCount(); |
177 test(fieldCount==0); |
161 test(fieldCount==0); |
178 // |
162 // |
179 INFO_PRINTF1(_L("Paste @ middle")); |
163 test.Next(_L("Paste @ middle")); |
180 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),4); |
164 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),4); |
181 fieldCount=TheTextObject->FieldCount(); |
165 fieldCount=TheTextObject->FieldCount(); |
182 test(fieldCount==0); |
166 test(fieldCount==0); |
183 TBuf<33> buf(_L("SomeSomeDataDataSomeDataSomeData")); |
167 TBuf<33> buf(_L("SomeSomeDataDataSomeDataSomeData")); |
184 test(TheTextObject->DocumentLength()==buf.Length()); |
168 test(TheTextObject->DocumentLength()==buf.Length()); |
206 test(r==KErrNone);\ |
190 test(r==KErrNone);\ |
207 CleanupStack::Pop(KTestCleanupStack);\ |
191 CleanupStack::Pop(KTestCleanupStack);\ |
208 }); |
192 }); |
209 } |
193 } |
210 |
194 |
211 CT_CUTPST::CT_CUTPST() |
195 |
|
196 GLDEF_C TInt E32Main() |
|
197 // |
|
198 // Test the streaming framework. |
|
199 // |
212 { |
200 { |
213 SetTestStepName(KTestStep_T_CUTPST); |
201 |
214 pTestStep = this; |
202 test.Title(); |
|
203 __UHEAP_MARK; |
|
204 setupCleanup(); |
|
205 TRAPD(r,testPlainTextCutPaste()); |
|
206 test(r == KErrNone); |
|
207 TRAP(r,testPlainTextCutPaste2()); |
|
208 test(r == KErrNone); |
|
209 |
|
210 delete TheTrapCleanup; |
|
211 |
|
212 __UHEAP_MARKEND; |
|
213 test.End(); |
|
214 test.Close(); |
|
215 return 0; |
215 } |
216 } |
216 |
|
217 TVerdict CT_CUTPST::doTestStepL() |
|
218 { |
|
219 SetTestStepResult(EFail); |
|
220 |
|
221 INFO_PRINTF1(_L("Cut & Paste")); |
|
222 __UHEAP_MARK; |
|
223 setupCleanup(); |
|
224 TRAPD(r1,testPlainTextCutPaste()); |
|
225 TRAPD(r2,testPlainTextCutPaste2()); |
|
226 |
|
227 delete TheTrapCleanup; |
|
228 |
|
229 __UHEAP_MARKEND; |
|
230 |
|
231 if (r1 == KErrNone && r2 == KErrNone) |
|
232 { |
|
233 SetTestStepResult(EPass); |
|
234 } |
|
235 |
|
236 return TestStepResult(); |
|
237 } |
|