| 1 |
# WinDictator: |
|---|
| 2 |
# Dictate in Windows, have the text typed in Linux via X faked keystroke events |
|---|
| 3 |
# |
|---|
| 4 |
# Copyright (C) 2005-2006 by Edwin A. Suominen, http://www.eepatents.com |
|---|
| 5 |
# |
|---|
| 6 |
# This program is free software; you can redistribute it and/or modify it under |
|---|
| 7 |
# the terms of the GNU General Public License as published by the Free Software |
|---|
| 8 |
# Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 9 |
# version. |
|---|
| 10 |
# |
|---|
| 11 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 13 |
# FOR A PARTICULAR PURPOSE. See the file COPYING for more details. |
|---|
| 14 |
# |
|---|
| 15 |
# You should have received a copy of the GNU General Public License along with |
|---|
| 16 |
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|---|
| 17 |
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
""" |
|---|
| 21 |
Unit tests for windicator.windows.dictate |
|---|
| 22 |
""" |
|---|
| 23 |
|
|---|
| 24 |
import time |
|---|
| 25 |
from twisted.internet import defer, reactor |
|---|
| 26 |
from twisted.trial.unittest import TestCase |
|---|
| 27 |
|
|---|
| 28 |
import mock |
|---|
| 29 |
import windictator.windows.dictate as dictate |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
WINDOW_OPEN_TIME = 3 |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
class TestTextWindow(TestCase): |
|---|
| 36 |
def setUp(self): |
|---|
| 37 |
self.updater = mock.MockUpdater(None) |
|---|
| 38 |
self.tw = dictate.TextWindow() |
|---|
| 39 |
|
|---|
| 40 |
def testShutdown(self): |
|---|
| 41 |
mutable = [] |
|---|
| 42 |
|
|---|
| 43 |
def shutdown(null): |
|---|
| 44 |
self.tw.shutdown() |
|---|
| 45 |
|
|---|
| 46 |
def cancel(null): |
|---|
| 47 |
if mutable: |
|---|
| 48 |
callID = mutable[0] |
|---|
| 49 |
if callID.active(): |
|---|
| 50 |
callID.cancel() |
|---|
| 51 |
|
|---|
| 52 |
# Fires after a while |
|---|
| 53 |
d1 = defer.Deferred() |
|---|
| 54 |
d1.addCallback(shutdown) |
|---|
| 55 |
mutable.append(reactor.callLater(WINDOW_OPEN_TIME, d1.callback, None)) |
|---|
| 56 |
# Fires when the application is shutdown, manually or via d1 |
|---|
| 57 |
d2 = self.tw.run(self.updater) |
|---|
| 58 |
d2.addCallback(cancel) |
|---|
| 59 |
return d2 |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
class TestTextUpdater(TestCase): |
|---|
| 63 |
def setUp(self): |
|---|
| 64 |
self.clientRoot = mock.MockClientRoot() |
|---|
| 65 |
self.updater = dictate.TextUpdater(self.clientRoot) |
|---|
| 66 |
|
|---|
| 67 |
def testNewChars(self): |
|---|
| 68 |
self.updater.update('foo') |
|---|
| 69 |
self.updater.update('foo bar') |
|---|
| 70 |
self.failUnlessEqual( |
|---|
| 71 |
self.clientRoot.operations, |
|---|
| 72 |
[('insert', 'foo'), ('insert', ' bar')]) |
|---|
| 73 |
self.updater.update("foo bar whatever") |
|---|
| 74 |
self.failUnlessEqual( |
|---|
| 75 |
self.clientRoot.operations[-1], |
|---|
| 76 |
('insert', ' whatever')) |
|---|
| 77 |
|
|---|
| 78 |
def testDeleteChars(self): |
|---|
| 79 |
self.updater.update('foo bar') |
|---|
| 80 |
self.updater.update('foo') |
|---|
| 81 |
self.failUnlessEqual( |
|---|
| 82 |
self.clientRoot.operations[-1], ('backspace', 4)) |
|---|
| 83 |
|
|---|
| 84 |
def testReplaceChars(self): |
|---|
| 85 |
self.updater.update('foo bar zzz') |
|---|
| 86 |
self.updater.update('foo boo zzz') |
|---|
| 87 |
self.failUnlessEqual( |
|---|
| 88 |
self.clientRoot.operations, |
|---|
| 89 |
[('insert', 'foo bar zzz'), |
|---|
| 90 |
('backspace', 6), |
|---|
| 91 |
('insert', 'oo zzz')]) |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|