OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Unit tests for grit.tclib''' |
| 7 |
| 8 |
| 9 import sys |
| 10 import os.path |
| 11 if __name__ == '__main__': |
| 12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..')) |
| 13 |
| 14 import types |
| 15 import unittest |
| 16 |
| 17 from grit import tclib |
| 18 |
| 19 from grit import exception |
| 20 import grit.extern.tclib |
| 21 |
| 22 |
| 23 class TclibUnittest(unittest.TestCase): |
| 24 def testInit(self): |
| 25 msg = tclib.Message(text=u'Hello Earthlings') |
| 26 self.failUnless(msg.GetPresentableContent() == 'Hello Earthlings') |
| 27 self.failUnless(isinstance(msg.GetPresentableContent(), types.StringTypes)) |
| 28 |
| 29 def testGetAttr(self): |
| 30 msg = tclib.Message() |
| 31 msg.AppendText(u'Hello') # Tests __getattr__ |
| 32 self.failUnless(msg.GetPresentableContent() == 'Hello') |
| 33 self.failUnless(isinstance(msg.GetPresentableContent(), types.StringTypes)) |
| 34 |
| 35 def testAll(self): |
| 36 text = u'Howdie USERNAME' |
| 37 phs = [tclib.Placeholder(u'USERNAME', u'%s', 'Joi')] |
| 38 msg = tclib.Message(text=text, placeholders=phs) |
| 39 self.failUnless(msg.GetPresentableContent() == 'Howdie USERNAME') |
| 40 |
| 41 trans = tclib.Translation(text=text, placeholders=phs) |
| 42 self.failUnless(trans.GetPresentableContent() == 'Howdie USERNAME') |
| 43 self.failUnless(isinstance(trans.GetPresentableContent(), types.StringTypes)
) |
| 44 |
| 45 def testUnicodeReturn(self): |
| 46 text = u'\u00fe' |
| 47 msg = tclib.Message(text=text) |
| 48 self.failUnless(msg.GetPresentableContent() == text) |
| 49 from_list = msg.GetContent()[0] |
| 50 self.failUnless(from_list == text) |
| 51 |
| 52 def testRegressionTranslationInherited(self): |
| 53 '''Regression tests a bug that was caused by grit.tclib.Translation |
| 54 inheriting from the translation console's Translation object |
| 55 instead of only owning an instance of it. |
| 56 ''' |
| 57 msg = tclib.Message(text=u"BLA1\r\nFrom: BLA2 \u00fe BLA3", |
| 58 placeholders=[ |
| 59 tclib.Placeholder('BLA1', '%s', '%s'), |
| 60 tclib.Placeholder('BLA2', '%s', '%s'), |
| 61 tclib.Placeholder('BLA3', '%s', '%s')]) |
| 62 transl = tclib.Translation(text=msg.GetPresentableContent(), |
| 63 placeholders=msg.GetPlaceholders()) |
| 64 content = transl.GetContent() |
| 65 self.failUnless(isinstance(content[3], types.UnicodeType)) |
| 66 |
| 67 def testFingerprint(self): |
| 68 # This has Windows line endings. That is on purpose. |
| 69 id = grit.extern.tclib.GenerateMessageId( |
| 70 'Google Desktop for Enterprise\r\n' |
| 71 'Copyright (C) 2006 Google Inc.\r\n' |
| 72 'All Rights Reserved\r\n' |
| 73 '\r\n' |
| 74 '---------\r\n' |
| 75 'Contents\r\n' |
| 76 '---------\r\n' |
| 77 'This distribution contains the following files:\r\n' |
| 78 '\r\n' |
| 79 'GoogleDesktopSetup.msi - Installation and setup program\r\n' |
| 80 'GoogleDesktop.adm - Group Policy administrative template file\r\n' |
| 81 'AdminGuide.pdf - Google Desktop for Enterprise administrative guide\r\n' |
| 82 '\r\n' |
| 83 '\r\n' |
| 84 '--------------\r\n' |
| 85 'Documentation\r\n' |
| 86 '--------------\r\n' |
| 87 'Full documentation and installation instructions are in the \r\n' |
| 88 'administrative guide, and also online at \r\n' |
| 89 'http://desktop.google.com/enterprise/adminguide.html.\r\n' |
| 90 '\r\n' |
| 91 '\r\n' |
| 92 '------------------------\r\n' |
| 93 'IBM Lotus Notes Plug-In\r\n' |
| 94 '------------------------\r\n' |
| 95 'The Lotus Notes plug-in is included in the release of Google \r\n' |
| 96 'Desktop for Enterprise. The IBM Lotus Notes Plug-in for Google \r\n' |
| 97 'Desktop indexes mail, calendar, task, contact and journal \r\n' |
| 98 'documents from Notes. Discussion documents including those from \r\n' |
| 99 'the discussion and team room templates can also be indexed by \r\n' |
| 100 'selecting an option from the preferences. Once indexed, this data\r\n' |
| 101 'will be returned in Google Desktop searches. The corresponding\r\n' |
| 102 'document can be opened in Lotus Notes from the Google Desktop \r\n' |
| 103 'results page.\r\n' |
| 104 '\r\n' |
| 105 'Install: The plug-in will install automatically during the Google \r\n' |
| 106 'Desktop setup process if Lotus Notes is already installed. Lotus \r\n' |
| 107 'Notes must not be running in order for the install to occur. \r\n' |
| 108 '\r\n' |
| 109 'Preferences: Preferences and selection of databases to index are\r\n' |
| 110 'set in the \'Google Desktop for Notes\' dialog reached through the \r\n' |
| 111 '\'Actions\' menu.\r\n' |
| 112 '\r\n' |
| 113 'Reindexing: Selecting \'Reindex all databases\' will index all the \r\n' |
| 114 'documents in each database again.\r\n' |
| 115 '\r\n' |
| 116 '\r\n' |
| 117 'Notes Plug-in Known Issues\r\n' |
| 118 '---------------------------\r\n' |
| 119 '\r\n' |
| 120 'If the \'Google Desktop for Notes\' item is not available from the \r\n' |
| 121 'Lotus Notes Actions menu, then installation was not successful. \r\n' |
| 122 'Installation consists of writing one file, notesgdsplugin.dll, to \r\n' |
| 123 'the Notes application directory and a setting to the notes.ini \r\n' |
| 124 'configuration file. The most likely cause of an unsuccessful \r\n' |
| 125 'installation is that the installer was not able to locate the \r\n' |
| 126 'notes.ini file. Installation will complete if the user closes Notes\r\n' |
| 127 'and manually adds the following setting to this file on a new line:\r\n' |
| 128 'AddinMenus=notegdsplugin.dll\r\n' |
| 129 '\r\n' |
| 130 'If the notesgdsplugin.dll file is not in the application directory\r\n' |
| 131 '(e.g., C:\Program Files\Lotus\Notes) after Google Desktop \r\n' |
| 132 'installation, it is likely that Notes was not installed correctly. \r\n' |
| 133 '\r\n' |
| 134 'Only local databases can be indexed. If they can be determined, \r\n' |
| 135 'the user\'s local mail file and address book will be included in the\r\n' |
| 136 'list automatically. Mail archives and other databases must be \r\n' |
| 137 'added with the \'Add\' button.\r\n' |
| 138 '\r\n' |
| 139 'Some users may experience performance issues during the initial \r\n' |
| 140 'indexing of a database. The \'Perform the initial index of a \r\n' |
| 141 'database only when I\'m idle\' option will limit the indexing process\r\n
' |
| 142 'to times when the user is not using the machine. If this does not \r\n' |
| 143 'alleviate the problem or the user would like to continually index \r\n' |
| 144 'but just do so more slowly or quickly, the GoogleWaitTime notes.ini\r\n' |
| 145 'value can be set. Increasing the GoogleWaitTime value will slow \r\n' |
| 146 'down the indexing process, and lowering the value will speed it up.\r\n' |
| 147 'A value of zero causes the fastest possible indexing. Removing the\r\n' |
| 148 'ini parameter altogether returns it to the default (20).\r\n' |
| 149 '\r\n' |
| 150 'Crashes have been known to occur with certain types of history \r\n' |
| 151 'bookmarks. If the Notes client seems to crash randomly, try \r\n' |
| 152 'disabling the \'Index note history\' option. If it crashes before,\r\n' |
| 153 'you can get to the preferences, add the following line to your \r\n' |
| 154 'notes.ini file:\r\n' |
| 155 'GDSNoIndexHistory=1\r\n') |
| 156 self.failUnless(id == '8961534701379422820') |
| 157 |
| 158 def testPlaceholderNameChecking(self): |
| 159 try: |
| 160 ph = tclib.Placeholder('BINGO BONGO', 'bla', 'bla') |
| 161 raise Exception("We shouldn't get here") |
| 162 except exception.InvalidPlaceholderName: |
| 163 pass # Expect exception to be thrown because presentation contained space |
| 164 |
| 165 if __name__ == '__main__': |
| 166 unittest.main() |
OLD | NEW |