Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''Unit tests for grit.format.resource_map''' | 6 '''Unit tests for grit.format.resource_map''' |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 if __name__ == '__main__': | 10 if __name__ == '__main__': |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 const GritResourceMap kTheRcHeader[] = { | 87 const GritResourceMap kTheRcHeader[] = { |
| 88 {"grit/testdata/klonk.rc", IDC_KLONKMENU}, | 88 {"grit/testdata/klonk.rc", IDC_KLONKMENU}, |
| 89 {"abc", IDS_FIRSTPRESENT}, | 89 {"abc", IDS_FIRSTPRESENT}, |
| 90 {"def", IDS_MISSING}, | 90 {"def", IDS_MISSING}, |
| 91 {"ghi", IDS_LANGUAGESPECIFIC}, | 91 {"ghi", IDS_LANGUAGESPECIFIC}, |
| 92 {"jkl", IDS_LANGUAGESPECIFIC}, | 92 {"jkl", IDS_LANGUAGESPECIFIC}, |
| 93 {"mno", IDS_THIRDPRESENT}, | 93 {"mno", IDS_THIRDPRESENT}, |
| 94 }; | 94 }; |
| 95 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) | 95 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) |
| 96 | 96 |
| 97 def testFormatStringResourceMap(self): | |
| 98 grd = grd_reader.Parse(StringIO.StringIO( | |
| 99 '''<?xml version="1.0" encoding="UTF-8"?> | |
| 100 <grit latest_public_release="2" source_lang_id="en" current_release="3" | |
| 101 base_dir="."> | |
| 102 <outputs> | |
| 103 <output type="rc_header" filename="the_rc_header" /> | |
|
tony
2013/08/13 17:21:22
Nit: Please change the filename to have a .h exten
| |
| 104 <output type="resource_map_header" filename="the_rc_map_header.h" /> | |
| 105 <output type="resource_map_source" filename="the_rc_map_source.h" /> | |
|
tony
2013/08/13 17:21:22
Nit: Please change the map source to have a .cc ex
| |
| 106 </outputs> | |
| 107 <release seq="1" allow_pseudo="false"> | |
| 108 <messages fallback_to_english="true"> | |
| 109 <message name="IDS_PRODUCT_NAME" desc="The application name"> | |
| 110 Application | |
| 111 </message> | |
| 112 <if expr="1"> | |
| 113 <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE" | |
| 114 desc="In Title Case: The default title in a tab."> | |
| 115 New Tab | |
| 116 </message> | |
| 117 </if> | |
| 118 <if expr="0"> | |
| 119 <message name="IDS_DEFAULT_TAB_TITLE" | |
| 120 desc="The default title in a tab."> | |
| 121 New tab | |
| 122 </message> | |
| 123 </if> | |
| 124 </messages> | |
| 125 </release> | |
| 126 </grit>'''), util.PathFromRoot('.')) | |
| 127 grd.SetOutputLanguage('en') | |
| 128 grd.RunGatherers() | |
| 129 output = util.StripBlankLinesAndComments(''.join( | |
| 130 resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) | |
| 131 self.assertEqual('''\ | |
| 132 #include <stddef.h> | |
| 133 #ifndef GRIT_RESOURCE_MAP_STRUCT_ | |
| 134 #define GRIT_RESOURCE_MAP_STRUCT_ | |
| 135 struct GritResourceMap { | |
| 136 const char* const name; | |
| 137 int value; | |
| 138 }; | |
| 139 #endif // GRIT_RESOURCE_MAP_STRUCT_ | |
| 140 extern const GritResourceMap kTheRcHeader[]; | |
| 141 extern const size_t kTheRcHeaderSize;''', output) | |
| 142 output = util.StripBlankLinesAndComments(''.join( | |
| 143 resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) | |
| 144 self.assertEqual('''\ | |
| 145 #include "the_rc_map_header.h" | |
| 146 #include "base/basictypes.h" | |
| 147 #include "the_rc_header" | |
| 148 const GritResourceMap kTheRcHeader[] = { | |
| 149 {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME}, | |
| 150 {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE}, | |
| 151 }; | |
| 152 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) | |
| 153 | |
| 97 | 154 |
| 98 if __name__ == '__main__': | 155 if __name__ == '__main__': |
| 99 unittest.main() | 156 unittest.main() |
| OLD | NEW |