| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 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 """Unittest for c_format.py. |
| 7 """ |
| 8 |
| 9 import unittest |
| 10 import StringIO |
| 11 |
| 12 from grit import grd_reader |
| 13 from grit import util |
| 14 from grit.tool import build |
| 15 |
| 16 |
| 17 class CFormatUnittest(unittest.TestCase): |
| 18 |
| 19 def testMessages(self): |
| 20 root = grd_reader.Parse(StringIO.StringIO(""" |
| 21 <messages> |
| 22 <message name="IDS_QUESTIONS">Do you want to play questions?</message> |
| 23 <message name="IDS_QUOTES"> |
| 24 "What's in a name, <ph name="NAME">%s<ex>Brandon</ex></ph>?" |
| 25 </message> |
| 26 <message name="IDS_LINE_BREAKS"> |
| 27 Was that rhetoric? |
| 28 No. |
| 29 Statement. Two all. Game point. |
| 30 </message> |
| 31 <message name="IDS_NON_ASCII"> |
| 32 \xc3\xb5\\xc2\\xa4\\\xc2\xa4\\\\xc3\\xb5\xe4\xa4\xa4 |
| 33 </message> |
| 34 </messages> |
| 35 """), flexible_root=True) |
| 36 util.FixRootForUnittest(root) |
| 37 |
| 38 buf = StringIO.StringIO() |
| 39 build.RcBuilder.ProcessNode(root, DummyOutput('c_format', 'en'), buf) |
| 40 output = buf.getvalue() |
| 41 test = u""" |
| 42 const char* GetString(int id) { |
| 43 switch (id) { |
| 44 case IDS_QUESTIONS: |
| 45 return "Do you want to play questions?"; |
| 46 case IDS_QUOTES: |
| 47 return "\\"What\\'s in a name, %s?\\""; |
| 48 case IDS_LINE_BREAKS: |
| 49 return "Was that rhetoric?\\nNo.\\nStatement. Two all. Game point."; |
| 50 case IDS_NON_ASCII: |
| 51 return "\\303\\265\\xc2\\xa4\\\\302\\244\\\\xc3\\xb5\\344\\244\\244"; |
| 52 default: |
| 53 return 0; |
| 54 } |
| 55 }""" |
| 56 self.failUnless(output.strip() == test.strip()) |
| 57 |
| 58 |
| 59 class DummyOutput(object): |
| 60 |
| 61 def __init__(self, type, language): |
| 62 self.type = type |
| 63 self.language = language |
| 64 |
| 65 def GetType(self): |
| 66 return self.type |
| 67 |
| 68 def GetLanguage(self): |
| 69 return self.language |
| 70 |
| 71 def GetOutputFilename(self): |
| 72 return 'hello.gif' |
| 73 |
| 74 if __name__ == '__main__': |
| 75 unittest.main() |
| OLD | NEW |