|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "TSTCLIPB.H" |
|
20 #include <txtglobl.h> |
|
21 #include <s32mem.h> |
|
22 #include <s32file.h> |
|
23 #include <e32test.h> |
|
24 |
|
25 #define UNUSED_VAR(a) a = a |
|
26 |
|
27 const TInt KTestCleanupStack=0x40; |
|
28 |
|
29 |
|
30 LOCAL_D RTest test(_L("Cut & Paste")); |
|
31 LOCAL_D CTrapCleanup* TheTrapCleanup=NULL; |
|
32 LOCAL_D CPlainText* TheTextObject=NULL; |
|
33 LOCAL_D CClipboard* TheWriteBoard=NULL; |
|
34 LOCAL_D CClipboard* TheReadBoard=NULL; |
|
35 LOCAL_D RFs TheSession; |
|
36 |
|
37 |
|
38 LOCAL_C void OpenWriteClipboardLC() |
|
39 // Initialize a new write clipboard, after |
|
40 // deleting any existing read clipboard. |
|
41 // |
|
42 { |
|
43 if (TheReadBoard) |
|
44 { |
|
45 CleanupStack::PopAndDestroy(); |
|
46 TheReadBoard=NULL; |
|
47 TheSession.Close(); |
|
48 } |
|
49 User::LeaveIfError(TheSession.Connect()); |
|
50 TheWriteBoard=CClipboard::NewForWritingLC(TheSession); |
|
51 } |
|
52 |
|
53 |
|
54 LOCAL_C void OpenReadClipboardLC() |
|
55 // Initialize a new read clipboard, after |
|
56 // deleting any existing write clipboard. |
|
57 // |
|
58 { |
|
59 if (TheWriteBoard) |
|
60 { |
|
61 TheWriteBoard->CommitL(); |
|
62 CleanupStack::PopAndDestroy(); |
|
63 TheWriteBoard=NULL; |
|
64 TheSession.Close(); |
|
65 } |
|
66 User::LeaveIfError(TheSession.Connect()); |
|
67 TheReadBoard=CClipboard::NewForReadingLC(TheSession); |
|
68 } |
|
69 |
|
70 |
|
71 LOCAL_C void testPlainTextCutPaste2() |
|
72 { |
|
73 TheTextObject=CPlainText::NewL(); |
|
74 CleanupStack::PushL(TheTextObject); |
|
75 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
|
76 |
|
77 // Copy zero-length text to the clipboard. |
|
78 test.Next(_L("Copy zero-length text to the clipboard")); |
|
79 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,0); |
|
80 |
|
81 OpenReadClipboardLC(); |
|
82 test(TheTextObject->DocumentLength()==0); |
|
83 |
|
84 // Paste zero-length text from the clipboard. |
|
85 test.Next(_L("Paste zero-length text from the clipboard")); |
|
86 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
|
87 |
|
88 // Copy multiple paragraphs to the clipboard |
|
89 test.Next(_L("PasteFromStoreL(aPos,aMaxPasteLength)")); |
|
90 TBuf<512> buf(_L("Here is para one.")); |
|
91 buf.Append(CEditableText::EParagraphDelimiter); |
|
92 buf.Append(_L("This is paragraph two.")); |
|
93 buf.Append(CEditableText::EParagraphDelimiter); |
|
94 TheTextObject->InsertL(0,buf); |
|
95 int text_length = TheTextObject->DocumentLength(); |
|
96 |
|
97 OpenWriteClipboardLC(); |
|
98 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,TheTextObject->DocumentLength()); |
|
99 TheTextObject->Reset(); |
|
100 test(TheTextObject->DocumentLength()==0); |
|
101 |
|
102 // Now paste the text. |
|
103 OpenReadClipboardLC(); |
|
104 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
|
105 test(TheTextObject->DocumentLength()==text_length); |
|
106 TInt fieldCount=TheTextObject->FieldCount(); |
|
107 test(fieldCount==0); |
|
108 |
|
109 CleanupStack::PopAndDestroy(); // Last clipboard object |
|
110 CleanupStack::PopAndDestroy(); // TheTextObject |
|
111 TheWriteBoard=NULL; |
|
112 TheReadBoard=NULL; |
|
113 } |
|
114 |
|
115 LOCAL_C void testPlainTextCutPaste() |
|
116 // |
|
117 // |
|
118 { |
|
119 test.Start(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-CPLAIN-0001 Cut&Paste - with plainText ")); |
|
120 TheTextObject=CPlainText::NewL(); |
|
121 CleanupStack::PushL(TheTextObject); |
|
122 OpenWriteClipboardLC(); // delete the system clipboard file if it exists. |
|
123 test(TheTextObject->DocumentLength()==0); |
|
124 // |
|
125 test.Next(_L("Paste from empty store")); |
|
126 OpenReadClipboardLC(); |
|
127 TInt charCount=0; |
|
128 TRAPD(ret, |
|
129 charCount=TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength())); |
|
130 UNUSED_VAR(ret); |
|
131 if (charCount<=0) |
|
132 test.Printf(_L(" No recognised data to paste or clipboard empty\n\r")); |
|
133 TInt fieldCount=TheTextObject->FieldCount(); |
|
134 test(fieldCount==0); |
|
135 // |
|
136 // test.Next(_L("Paste from clipboard with no recognised types")); |
|
137 // WriteForeignDataToClipboardL(); |
|
138 // |
|
139 test.Next(_L("Paste into empty PlainText")); |
|
140 TheTextObject->InsertL(TheTextObject->DocumentLength(),_L("SomeData")); |
|
141 OpenWriteClipboardLC(); |
|
142 TheTextObject->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,TheTextObject->DocumentLength()); |
|
143 TheTextObject->Reset(); |
|
144 test(TheTextObject->DocumentLength()==0); |
|
145 OpenReadClipboardLC(); |
|
146 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
|
147 test(TheTextObject->DocumentLength()==_L("SomeData").Length()); |
|
148 fieldCount=TheTextObject->FieldCount(); |
|
149 test(fieldCount==0); |
|
150 // |
|
151 test.Next(_L("Paste @ start (pos=0)")); |
|
152 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),0); |
|
153 test(TheTextObject->DocumentLength()==_L("SomeDataSomeData").Length()); |
|
154 fieldCount=TheTextObject->FieldCount(); |
|
155 test(fieldCount==0); |
|
156 // |
|
157 test.Next(_L("Paste @ end (DocumentLength())")); |
|
158 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),TheTextObject->DocumentLength()); |
|
159 test(TheTextObject->DocumentLength()==_L("SomeDataSomeDataSomeData").Length()); |
|
160 fieldCount=TheTextObject->FieldCount(); |
|
161 test(fieldCount==0); |
|
162 // |
|
163 test.Next(_L("Paste @ middle")); |
|
164 TheTextObject->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),4); |
|
165 fieldCount=TheTextObject->FieldCount(); |
|
166 test(fieldCount==0); |
|
167 TBuf<33> buf(_L("SomeSomeDataDataSomeDataSomeData")); |
|
168 test(TheTextObject->DocumentLength()==buf.Length()); |
|
169 buf.Append(CEditableText::EParagraphDelimiter); |
|
170 test(TheTextObject->Read(0)==buf); |
|
171 // |
|
172 CleanupStack::PopAndDestroy(); // Last clipboard object |
|
173 CleanupStack::PopAndDestroy(); // TheTextObject |
|
174 TheWriteBoard=NULL; |
|
175 TheReadBoard=NULL; |
|
176 } |
|
177 |
|
178 |
|
179 LOCAL_C void setupCleanup() |
|
180 // |
|
181 // Initialise the cleanup stack. |
|
182 // |
|
183 { |
|
184 |
|
185 TheTrapCleanup=CTrapCleanup::New(); |
|
186 TRAPD(r,\ |
|
187 {\ |
|
188 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
189 CleanupStack::PushL((TAny*)1);\ |
|
190 test(r==KErrNone);\ |
|
191 CleanupStack::Pop(KTestCleanupStack);\ |
|
192 }); |
|
193 } |
|
194 |
|
195 |
|
196 GLDEF_C TInt E32Main() |
|
197 // |
|
198 // Test the streaming framework. |
|
199 // |
|
200 { |
|
201 |
|
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; |
|
216 } |