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 <structure> nodes. |
| 7 ''' |
| 8 |
| 9 import os |
| 10 import sys |
| 11 if __name__ == '__main__': |
| 12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 13 |
| 14 import unittest |
| 15 import StringIO |
| 16 |
| 17 from grit.node import structure |
| 18 from grit import grd_reader |
| 19 from grit import util |
| 20 |
| 21 |
| 22 class StructureUnittest(unittest.TestCase): |
| 23 def testSkeleton(self): |
| 24 grd = grd_reader.Parse(StringIO.StringIO( |
| 25 '''<?xml version="1.0" encoding="UTF-8"?> |
| 26 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
| 27 <release seq="3"> |
| 28 <structures> |
| 29 <structure type="dialog" name="IDD_ABOUTBOX" file="klonk.rc" encodin
g="utf-16-le"> |
| 30 <skeleton expr="lang == 'fr'" variant_of_revision="1" file="klonk-
alternate-skeleton.rc" /> |
| 31 </structure> |
| 32 </structures> |
| 33 </release> |
| 34 </grit>'''), dir=util.PathFromRoot('grit\\test\\data')) |
| 35 grd.RunGatherers(recursive=True) |
| 36 grd.output_language = 'fr' |
| 37 |
| 38 node = grd.GetNodeById('IDD_ABOUTBOX') |
| 39 formatter = node.ItemFormatter('rc_all') |
| 40 self.failUnless(formatter) |
| 41 transl = formatter.Format(node, 'fr') |
| 42 |
| 43 self.failUnless(transl.count('040704') and transl.count('110978')) |
| 44 self.failUnless(transl.count('2005",IDC_STATIC')) |
| 45 |
| 46 def testOutputEncoding(self): |
| 47 grd = grd_reader.Parse(StringIO.StringIO( |
| 48 '''<?xml version="1.0" encoding="UTF-8"?> |
| 49 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
| 50 <release seq="3"> |
| 51 <structures> |
| 52 <structure type="dialog" name="IDD_ABOUTBOX" file="klonk.rc" encodin
g="utf-16-le" output_encoding="utf-8-sig" /> |
| 53 </structures> |
| 54 </release> |
| 55 </grit>'''), dir=util.PathFromRoot('grit\\test\\data')) |
| 56 node = grd.GetNodeById('IDD_ABOUTBOX') |
| 57 self.failUnless(node._GetOutputEncoding() == 'utf-8') |
| 58 self.failUnless(node._ShouldAddBom()) |
| 59 |
| 60 if __name__ == '__main__': |
| 61 unittest.main() |
| 62 |
OLD | NEW |