This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathclipboard.livecodescript
More file actions
282 lines (244 loc) · 12.8 KB
/
Copy pathclipboard.livecodescript
File metadata and controls
282 lines (244 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
script "CoreEngineClipboard"
/*
Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
-- Clipboard access requires system interaction so, generally, cannot
-- be run in no-UI mode or on server
on TestSetup
if the platform is "Linux" then
TestSkipIf "environment", "server"
TestSkipIfNot "ui"
end if
TestSkipIfNot "desktop"
end TestSetup
-- Utility function that returns the folder containing this test
private function _TestPath
set the itemDelimiter to slash
return item 1 to -2 of the filename of me
end _TestPath
-- Utility function that returns the smallest possible valid PNG image
local sTinyPNG
private function _TinyPNG
if sTinyPNG is empty then
put url ("binfile:" & TestGetInputFile("tiny.png")) into sTinyPNG
end if
return sTinyPNG
end _TinyPNG
-- Utility function that returns the smallest possible valid GIF image
local sTinyGIF
private function _TinyGIF
if sTinyGIF is empty then
put url ("binfile:" & TestGetInputFile("tiny.gif")) into sTinyGIF
end if
return sTinyGIF
end _TinyGIF
-- Utility function that returns the smallest possible valid JPEG image
local sTinyJPEG
private function _TinyJPEG
if sTinyJPEG is empty then
put url ("binfile:" & TestGetInputFile("tiny.jpg")) into sTinyJPEG
end if
return sTinyJPEG
end _TinyJPEG
on TestClipboardLocking
-- Simply test that locking and unlocking the clipboard doesn't throw any errors
lock the clipboard
TestAssert "Clipboard locked", true
unlock the clipboard
TestAssert "Clipboard unlocked", true
end TestClipboardLocking
on TestClipboardClearing
-- Test that clearing the clipboard actually clears it
lock the clipboard
set the fullClipboardData to empty
TestAssert "Clipboard is clear", the keys of the fullClipboardData is empty
unlock the clipboard
end TestClipboardClearing
-- Utility function that ensures all auto-generated formats are present
private command _EnsureAutoGeneratedFormats
TestAssert "Plain text autogenerated", "text" is among the lines of the keys of the fullClipboardData
TestAssert "HTML-text autogenerated", "htmltext" is among the lines of the keys of the fullClipboardData
TestAssert "RTF-text autogenerated", "rtftext" is among the lines of the keys of the fullClipboardData
TestAssert "Serialised styled text autogenerated", "styles" is among the lines of the keys of the fullClipboardData
TestAssert "Styled text array autogenerated", "styledtext" is among the lines of the keys of the fullClipboardData
end _EnsureAutoGeneratedFormats
on TestClipboardFullClipboardDataAutogeneration
-- Place some text on the clipboard and ensure that all the correct types are generated
lock the clipboard
set the fullClipboardData["text"] to "LCS test clipboard contents"
# updated for Bug 19206 fix
TestAssert "Plain text autogenerated", "text" is among the lines of the keys of the fullClipboardData
TestAssert "HTML-text not autogenerated", "htmltext" is not among the lines of the keys of the fullClipboardData
TestAssert "HTML-text is available", the fullClipboardData["htmltext"] is "<p>LCS test clipboard contents</p>"
set the fullClipboardData to empty
set the fullclipboardData["htmltext"] to "<p>LCS test clipboard contents</p>"
_EnsureAutoGeneratedFormats
set the fullClipboardData to empty
set the fullClipboardData["rtftext"] to "{\rtf1\ansi\f0\pard" & return & "LCS test clipboard contents" & return & "\par}"
_EnsureAutoGeneratedFormats
set the fullClipboardData to empty
-- The "styles" and "styledtext" formats are not tested as an autogeneration source because they are quite difficult to synthesize
unlock the clipboard
end TestClipboardFullClipboardDataAutogeneration
on TestClipboardFullClipboardCoordination
-- Ensure that writing to the fullClipboardData updates the clipboardData property and vice-versa
lock the clipboard
local tTestContents
put "LCS clipboard test: TestClipboardFullClipboardCoordination" into tTestContents
set the fullClipboardData to empty
set the fullClipboardData["text"] to tTestContents
TestAssert "Getting clipboardData[text]", "text" is among the lines of the keys of the clipboardData and the clipboardData["text"] is tTestContents
set the fullClipboardData to empty
TestAssert "clipboardData is empty", the keys of the clipboardData is empty
set the clipboardData["text"] to tTestContents
TestAssert "Setting clipboardData[text]", "text" is among the lines of the keys of the fullClipboardData and the fullClipboardData["text"] is tTestContents
set the fullClipboardData to empty
unlock the clipboard
end TestClipboardFullClipboardCoordination
on TestClipboardTypeSelection
-- This ensures that the types presented by the clipboardData property are 'correct'
-- (where 'correct' is 'how they've always worked')
lock the clipboard
-- The priority order is: objects, files, text, images, private
set the fullClipboardData to empty
set the fullClipboardData["private"] to "private"
TestAssert "Private data only", "private" is among the lines of the keys of the clipboardData
TestAssert "clipboard returns private", clipboard() is "private"
set the fullClipboardData["image"] to _TinyPNG()
TestAssert "image > private", "image" is among the lines of the keys of the clipboardData and "private" is not among the lines of the keys of the clipboardData
TestAssert "clipboard returns image", clipboard() is "image"
set the fullClipboardData["text"] to "text"
TestAssert "text > image", "text" is among the lines of the keys of the clipboardData and "image" is not among the lines of the keys of the clipboardData
TestAssert "clipboard returns text", clipboard() is "text"
set the fullClipboardData["files"] to "files"
-- Files and text will appear together, but files takes priority
TestAssert "files > text", "files" is among the lines of the keys of the clipboardData
TestAssert "files > text but text is present", "text" is among the lines of the keys of the clipboardData
TestAssert "text is converted from the files key", the clipboardData["files"] is the clipboardData["text"]
TestAssert "clipboard returns files", clipboard() is "files"
set the fullClipboardData["objects"] to 0
TestAssert "objects > files", "objects" is among the lines of the keys of the clipboardData and "files" is not among the lines of the keys of the clipboardData
TestAssert "clipboard returns objects", clipboard() is "objects"
set the fullClipboardData to empty
unlock the clipboard
end TestClipboardTypeSelection
on TestClipboardMultipleTypes
-- Tests whether the fullClipboardData can successfully hold multiple types of data simultaneously
lock the clipboard
set the fullClipboardData to empty
set the fullClipboardData["text"] to "text"
set the fullClipboardData["image"] to _TinyPNG()
set the fullClipboardData["files"] to "/file/path"
set the fullClipboardData["private"] to "private"
TestAssert "Multiple types: text", "text" is among the lines of the keys of the fullClipboardData and fullClipboardData["text"] is "text"
TestAssert "Multiple types: image", "image" is among the lines of the keys of the fullClipboardData and fullClipboardData["image"] is _TinyPNG()
TestAssert "Multiple types: files", "files" is among the lines of the keys of the fullClipboardData and line 1 of fullClipboardData["files"] is "/file/path"
TestAssert "Multiple types: private", "private" is among the lines of the keys of the fullClipboardData and fullClipboardData["private"] is "private"
set the fullClipboardData to empty
unlock the clipboard
end TestClipboardMultipleTypes
on TestClipboardImageTypes
-- Tests whether adding an image to the clipboard generates the appropriate other keys
lock the clipboard
set the fullClipboardData["png"] to _TinyPNG()
TestAssert "PNG is image", "image" is among the lines of the keys of the fullClipboardData and fullClipboardData["image"] is _TinyPNG()
set the fullClipboardData to empty
set the fullClipboardData["gif"] to _TinyGIF()
TestAssert "GIF is image", "image" is among the lines of the keys of the fullClipboardData and fullClipboardData["image"] is _TinyGIF()
set the fullClipboardData to empty
set the fullClipboardData["jpeg"] to _TinyJPEG()
TestAssert "JPEG is image", "image" is among the lines of the keys of the fullClipboardData and fullClipboardData["image"] is _TinyJPEG()
set the fullClipboardData to empty
set the fullClipboardData["image"] to _TinyPNG()
TestAssert "PNG image is detected", "png" is among the lines of the keys of the fullClipboardData and fullClipboardData["png"] is _TinyPNG()
set the fullClipboardData["image"] to _TinyGIF()
TestAssert "GIF image is detected", "gif" is among the lines of the keys of the fullClipboardData and fullClipboardData["gif"] is _TinyGIF()
set the fullClipboardData["image"] to _TinyJPEG()
TestAssert "JPEG image is detected", "jpeg" is among the lines of the keys of the fullClipboardData and fullClipboardData["jpeg"] is _TinyJPEG()
set the fullClipboardData to empty
unlock the clipboard
end TestClipboardImageTypes
on TestClipboardPrivateKey
set the clipboardData["private"] to "Hello World!"
TestAssert "private key is present before external change", \
"private" is among the keys of the clipboardData
local tHelperFilename, tHelperExtension
if the environment is "server" then
put "lc" into tHelperExtension
else
put "livecodescript" into tHelperExtension
end if
set the itemDelimiter to slash
put format("%s/_clipboard_private_setter." & tHelperExtension, \
_TestPath()) into tHelperFilename
if the environment is "command line" then
TestRunStack "-ui", tHelperFilename
else
TestRunStack "", tHelperFilename
end if
TestAssert "helper changed clipboard externally", the result is 0
if the platform is "Linux" then
TestAssertBroken "private key not present after external change", \
"private" is not among the keys of the clipboardData, \
"Bug 19117"
else
TestAssert "private key not present after external change", \
"private" is not among the keys of the clipboardData
end if
end TestClipboardPrivateKey
# This is a regression test for Bug 19084
on TestClipboardTextToStyled
set the clipboardData["text"] to "Hello World"
TestDiagnostic the clipboardData["html"]
TestAssert "plain text should remain plain in htmltext", \
the clipboardData["html"] is "<p>Hello World</p>"
end TestClipboardTextToStyled
on _SetToEmpty
set clipboardData["image"] to empty
end _SetToEmpty
# This is a test for Bug 17416
on TestCanSetClipboardImageToEmpty
TestAssertDoesNotThrow "Can set clipboardData image to empty", "_SetToEmpty", the long id of me
end TestCanSetClipboardImageToEmpty
# This is a test for Bug 19206
on TestClipboardTextOnlyOnRawClipboard
# Ensure that when text is placed on the clipboard, that HTMLText is not
# pushed to the system clipboard.
lock the clipboard
local tTestContents, tRawKeys
put "LCS clipboard test: TestClipboardTextOnly" into tTestContents
set the fullClipboardData to empty
set the fullClipboardData["text"] to tTestContents
put the keys of the rawClipboardData into tRawKeys
filter tRawKeys with "*html*"
TestAssert "Raw clipboard does not contain HTML", tRawKeys is empty
set the fullClipboardData to empty
unlock the clipboard
end TestClipboardTextOnlyOnRawClipboard
on TestClipboardSettingTextDoesntClearPrivateData
lock clipboard
set the fullclipboarddata to empty
set the fullclipboarddata["private"] to "foo"
set the fullclipboardData["htmltext"] to "<p>foo</p>"
set the fullclipboarddata["text"] to "bar"
unlock clipboard
TestAssert "Setting fullclipboard text does not clear private data", the fullclipboarddata["private"] is "foo"
end TestClipboardSettingTextDoesntClearPrivateData
on TestClipboardSettingTextOnlyClearsWhenCurrentlyHasStyled
lock clipboard
set the fullclipboarddata to empty
set the fullClipboardData["png"] to _TinyPNG()
set the fullclipboarddata["text"] to "bar"
unlock clipboard
TestAssert "Setting fullclipboard text does not clear unless it is currently styled", \
"png" is among the lines of the keys of the fullClipboardData and fullClipboardData["png"] is _TinyPNG()
end TestClipboardSettingTextOnlyClearsWhenCurrentlyHasStyled