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 testFormatResourceMapOutputAllEqualsFalse(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="." output_all_resource_defines="false"> |
| 102 <outputs> |
| 103 <output type="rc_header" filename="the_rc_header.h" /> |
| 104 <output type="resource_map_header" |
| 105 filename="the_resource_map_header.h" /> |
| 106 <output type="resource_map_source" |
| 107 filename="the_resource_map_header.cc" /> |
| 108 </outputs> |
| 109 <release seq="3"> |
| 110 <structures first_id="300"> |
| 111 <structure type="chrome_scaled_image" name="IDR_KLONKMENU" |
| 112 file="foo.png" /> |
| 113 <if expr="False"> |
| 114 <structure type="chrome_scaled_image" name="IDR_MISSING" |
| 115 file="bar.png" /> |
| 116 </if> |
| 117 </structures> |
| 118 </release> |
| 119 </grit>'''), util.PathFromRoot('.')) |
| 120 grd.SetOutputLanguage('en') |
| 121 grd.RunGatherers() |
| 122 output = util.StripBlankLinesAndComments(''.join( |
| 123 resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) |
| 124 self.assertEqual('''\ |
| 125 #include <stddef.h> |
| 126 #ifndef GRIT_RESOURCE_MAP_STRUCT_ |
| 127 #define GRIT_RESOURCE_MAP_STRUCT_ |
| 128 struct GritResourceMap { |
| 129 const char* const name; |
| 130 int value; |
| 131 }; |
| 132 #endif // GRIT_RESOURCE_MAP_STRUCT_ |
| 133 extern const GritResourceMap kTheRcHeader[]; |
| 134 extern const size_t kTheRcHeaderSize;''', output) |
| 135 output = util.StripBlankLinesAndComments(''.join( |
| 136 resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) |
| 137 self.assertEqual('''\ |
| 138 #include "the_resource_map_header.h" |
| 139 #include "base/basictypes.h" |
| 140 #include "the_rc_header.h" |
| 141 const GritResourceMap kTheRcHeader[] = { |
| 142 {"IDR_KLONKMENU", IDR_KLONKMENU}, |
| 143 }; |
| 144 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) |
| 145 output = util.StripBlankLinesAndComments(''.join( |
| 146 resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) |
| 147 self.assertEqual('''\ |
| 148 #include "the_resource_map_header.h" |
| 149 #include "base/basictypes.h" |
| 150 #include "the_rc_header.h" |
| 151 const GritResourceMap kTheRcHeader[] = { |
| 152 {"IDR_KLONKMENU", IDR_KLONKMENU}, |
| 153 }; |
| 154 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) |
| 155 |
97 def testFormatStringResourceMap(self): | 156 def testFormatStringResourceMap(self): |
98 grd = grd_reader.Parse(StringIO.StringIO( | 157 grd = grd_reader.Parse(StringIO.StringIO( |
99 '''<?xml version="1.0" encoding="UTF-8"?> | 158 '''<?xml version="1.0" encoding="UTF-8"?> |
100 <grit latest_public_release="2" source_lang_id="en" current_release="3" | 159 <grit latest_public_release="2" source_lang_id="en" current_release="3" |
101 base_dir="."> | 160 base_dir="."> |
102 <outputs> | 161 <outputs> |
103 <output type="rc_header" filename="the_rc_header.h" /> | 162 <output type="rc_header" filename="the_rc_header.h" /> |
104 <output type="resource_map_header" filename="the_rc_map_header.h" /> | 163 <output type="resource_map_header" filename="the_rc_map_header.h" /> |
105 <output type="resource_map_source" filename="the_rc_map_source.cc" /> | 164 <output type="resource_map_source" filename="the_rc_map_source.cc" /> |
106 </outputs> | 165 </outputs> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 #include "the_rc_header.h" | 206 #include "the_rc_header.h" |
148 const GritResourceMap kTheRcHeader[] = { | 207 const GritResourceMap kTheRcHeader[] = { |
149 {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME}, | 208 {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME}, |
150 {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE}, | 209 {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE}, |
151 }; | 210 }; |
152 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) | 211 const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output) |
153 | 212 |
154 | 213 |
155 if __name__ == '__main__': | 214 if __name__ == '__main__': |
156 unittest.main() | 215 unittest.main() |
OLD | NEW |