PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Marathon/TestCases/EditOperations.py

#
Python | 64 lines | 59 code | 3 blank | 2 comment | 2 complexity | f3eed51a3917e93d5b480ef662771b86 MD5 | raw file
 1#{{{ Marathon Fixture

 2from default import *
 3from util import *
 4from java.lang import *
 5from javax.swing import SwingUtilities
 6from java.awt.datatransfer import *
 7from org.gjt.sp.jedit.textarea import Selection
 8#}}} Marathon Fixture

 9
10def enterKeystroke(key, count):
11	for i in range(1, count + 1):
12		keystroke('JEditTextArea', key)
13
14def test():
15	java_recorded_version = '1.6.0_11'
16	clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard()
17
18	class ClipboardAccess(java.lang.Runnable):
19		def get(self):
20			self.setString = ''
21			SwingUtilities.invokeAndWait(self)
22			return self.text
23
24		def setText(self, st):
25			self.setString = st
26			SwingUtilities.invokeAndWait(self)
27
28		def run(self):
29			if (self.setString != ''):
30				clipboard.setContents(StringSelection(self.setString), None)
31			else:
32				self.text = clipboard.getContents(None).getTransferData(DataFlavor.stringFlavor)
33	
34	if window('jEdit - TestPlan.txt'):
35		selection = Selection.Range(284, 327)
36		get_component('JEditTextArea').setSelection(selection)
37		select_menu('Edit>>Cut')
38		clipObj = ClipboardAccess()
39		s = clipObj.get()
40		assert s.startswith('test plan of the open source software jEdit'), 'Cut failure'
41	close()
42
43	if window('jEdit - TestPlan.txt (modified)'):
44		select_menu('Edit>>Undo')
45	close()
46
47	if window('jEdit - TestPlan.txt'):
48		selection = Selection.Range(1565, 1590)
49		get_component('JEditTextArea').setSelection(selection)
50		select_menu('Edit>>Copy')
51		clipObj = ClipboardAccess()
52		s = clipObj.get()
53		assert s.startswith('Basic features of the GUI'), 'Copy failure'
54
55		selection = Selection.Range(1583, 1590)
56		get_component('JEditTextArea').setSelection(selection)
57		clipObj = ClipboardAccess()
58		s = clipObj.setText('jEdit')
59		select_menu('Edit>>Paste')
60		selection = Selection.Range(1565, 1590)
61		get_component('JEditTextArea').setSelection(selection)
62		s = get_component('JEditTextArea').getSelectedText()
63		assert s.startswith('Basic features of jEdit'), 'Paste failure'
64	close()