Esempio n. 1
0
  def testFormatResourceMapWithOutputAllEqualsFalseForStructures(self):
    grd = grd_reader.Parse(StringIO.StringIO(
      '''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en" current_release="3"
            base_dir="." output_all_resource_defines="false">
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
          <output type="resource_map_source"
                  filename="the_resource_map_header.cc" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="chrome_scaled_image" name="IDR_KLONKMENU"
                       file="foo.png" />
            <if expr="False">
              <structure type="chrome_scaled_image" name="IDR_MISSING"
                         file="bar.png" />
            </if>
         </structures>
        </release>
      </grit>'''), util.PathFromRoot('.'))
    grd.SetOutputLanguage('en')
    grd.RunGatherers()
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
    self.assertEqual('''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
    self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDR_KLONKMENU", IDR_KLONKMENU},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
    self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDR_KLONKMENU", IDR_KLONKMENU},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
    def testFormatStringResourceMap(self):
        grd = grd_reader.Parse(
            StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en" current_release="3"
            base_dir=".">
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header" filename="the_rc_map_header.h" />
          <output type="resource_map_source" filename="the_rc_map_source.cc" />
        </outputs>
        <release seq="1" allow_pseudo="false">
          <messages fallback_to_english="true">
            <message name="IDS_PRODUCT_NAME" desc="The application name">
              Application
            </message>
            <if expr="True">
              <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE"
                  desc="In Title Case: The default title in a tab.">
                New Tab
              </message>
            </if>
            <if expr="False">
              <message name="IDS_DEFAULT_TAB_TITLE"
                  desc="The default title in a tab.">
                New tab
              </message>
            </if>
          </messages>
        </release>
      </grit>'''), util.PathFromRoot('.'))
        grd.SetOutputLanguage('en')
        grd.RunGatherers()
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_rc_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME},
  {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
Esempio n. 3
0
    def testFormatStringResourceMap(self):
        grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header" filename="the_rc_map_header.h" />
          <output type="resource_map_source" filename="the_rc_map_source.cc" />
        </outputs>
        <release seq="1" allow_pseudo="false">
          <messages fallback_to_english="true">
            <message name="IDS_PRODUCT_NAME" desc="The application name">
              Application
            </message>
            <if expr="True">
              <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE"
                  desc="In Title Case: The default title in a tab.">
                New Tab
              </message>
            </if>
            <if expr="False">
              <message name="IDS_DEFAULT_TAB_TITLE"
                  desc="The default title in a tab.">
                New tab
              </message>
            </if>
          </messages>
        </release>''',
                                       run_gatherers=True)
        grd.InitializeIds()
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_rc_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME},
  {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
Esempio n. 4
0
    def testGzippedMapHeaderAndFileSource(self):
        grd = util.ParseGrdForUnittest('''\
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="gzipped_resource_map_header"
                  filename="gzipped_resource_map_header.h" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="menu" name="IDC_KLONKMENU" compress="gzip"
                       file="grit\\testdata\\klonk.rc" encoding="utf-16" />
          </structures>
          <includes first_id="10000">
            <include type="foo" file="abc" name="IDS_FIRSTPRESENT"
                     compress="" />
            <if expr="False">
              <include type="foo" file="def" name="IDS_MISSING"
                       compress="garbage" />
            </if>
         </includes>
        </release>''',
                                       run_gatherers=True)
        formatter = resource_map.GetFormatter('gzipped_resource_map_header')
        output = util.StripBlankLinesAndComments(''.join(
            formatter(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GZIPPED_GRIT_RESOURCE_MAP_STRUCT_
#define GZIPPED_GRIT_RESOURCE_MAP_STRUCT_
struct GzippedGritResourceMap {
  const char* name;
  int value;
  bool gzipped;
};
#endif // GZIPPED_GRIT_RESOURCE_MAP_STRUCT_
extern const GzippedGritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        formatter = resource_map.GetFormatter(
            'gzipped_resource_file_map_source')
        output = util.StripBlankLinesAndComments(''.join(
            formatter(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "gzipped_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GzippedGritResourceMap kTheRcHeader[] = {
  {"grit/testdata/klonk.rc", IDC_KLONKMENU, true},
  {"abc", IDS_FIRSTPRESENT, false},
  {"def", IDS_MISSING, false},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
Esempio n. 5
0
  def testFormatStringResourceMap(self):
    grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header" filename="the_rc_map_header.h" />
          <output type="resource_map_source" filename="the_rc_map_source.cc" />
        </outputs>
        <release seq="1" allow_pseudo="false">
          <messages fallback_to_english="true">
            <message name="IDS_PRODUCT_NAME" desc="The application name">
              Application
            </message>
            <if expr="True">
              <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE"
                  desc="In Title Case: The default title in a tab.">
                New Tab
              </message>
            </if>
            <if expr="False">
              <message name="IDS_DEFAULT_TAB_TITLE"
                  desc="The default title in a tab.">
                New tab
              </message>
            </if>
          </messages>
        </release>''', run_gatherers=True)
    grd.InitializeIds()
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
    self.assertEqual(
        '''\
#include <stddef.h>
#include "ui/base/webui/resource_path.h"
extern const webui::ResourcePath kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
    self.assertEqual(
        '''\
#include "the_rc_map_header.h"
#include <stddef.h>
#include <iterator>
#include "the_rc_header.h"
const webui::ResourcePath kTheRcHeader[] = {
  {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME},
  {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE},
};
const size_t kTheRcHeaderSize = std::size(kTheRcHeader);''', output)
Esempio n. 6
0
    def testChromeHtmlNodeOutputfile(self):
        input_file = util.PathFromRoot('grit/testdata/chrome_html.html')
        output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir()
        root = util.ParseGrdForUnittest('''\
        <structures>
          <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" />
        </structures>''' % input_file)
        struct, = root.GetChildrenOfType(structure.StructureNode)
        struct.gatherer.SetDefines({'scale_factors': '2x'})
        # We must run the gatherers since we'll be wanting the chrome_html output.
        # The file exists in the location pointed to.
        root.SetOutputLanguage('en')
        root.RunGatherers()

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root,
                                    DummyOutput('rc_all', 'en', output_file),
                                    buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        expected = (
            _PREAMBLE +
            u'HTML_FILE1         BINDATA            "HTML_FILE1_chrome_html.html"'
        )
        # hackety hack to work on win32&lin
        output = re.sub('"[c-zC-Z]:', '"', output)
        self.assertEqual(expected, output)

        file_contents = util.ReadFile(output_file, util.RAW_TEXT)

        # Check for the content added by the <include> tag.
        self.failUnless(file_contents.find('Hello Include!') != -1)
        # Check for inserted -webkit-image-set.
        self.failUnless(file_contents.find('content: -webkit-image-set') != -1)
Esempio n. 7
0
    def testFallbackToEnglish(self):
        root = util.ParseGrdForUnittest('''\
        <structures fallback_to_english="True">
          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
        </structures>''',
                                        base_dir=util.PathFromRoot('.'))
        root.SetOutputLanguage('en')
        root.RunGatherers()

        buf = StringIO.StringIO()
        formatter = build.RcBuilder.ProcessNode(
            root, DummyOutput('rc_all', 'bingobongo'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        self.assertEqual(
            _PREAMBLE + '''\
IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75
STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System", 0, 0, 0x0
BEGIN
    ICON            IDI_KLONK,IDC_MYICON,14,9,20,20
    LTEXT           "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8,
                    SS_NOPREFIX
    LTEXT           "Copyright (C) 2005",IDC_STATIC,49,20,119,8
    DEFPUSHBUTTON   "OK",IDOK,195,6,30,11,WS_GROUP
    CONTROL         "Jack ""Black"" Daniels",IDC_RADIO1,"Button",
                    BS_AUTORADIOBUTTON,46,51,84,10
END''', output)
Esempio n. 8
0
    def testMessages(self):
        root = util.ParseGrdForUnittest('''
      <messages>
          <message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message>
          <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">
            Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
          </message>
          <message name="BONGO" desc="Flippo nippo">
            Howdie "Mr. Elephant", how are you doing?   \'\'\'
          </message>
          <message name="IDS_WITH_LINEBREAKS">
Good day sir,
I am a bee
Sting sting
          </message>
      </messages>
      ''')

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        self.assertEqual(
            _PREAMBLE + u'''\
STRINGTABLE
BEGIN
  IDS_BTN_GO      "Go!"
  IDS_GREETING    "Hello %s, how are you doing today?"
  BONGO           "Howdie ""Mr. Elephant"", how are you doing?   "
  IDS_WITH_LINEBREAKS "Good day sir,\\nI am a bee\\nSting sting"
END''', output)
Esempio n. 9
0
    def testFormatResourceMapWithGeneratedFile(self):
        os.environ["root_gen_dir"] = "gen"

        grd = util.ParseGrdForUnittest('''\
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="resource_map_header.h" />
        </outputs>
        <release seq="3">
          <includes first_id="10000">
            <include type="BINDATA"
                     file="${root_gen_dir}/foo/bar/baz.js"
                     name="IDR_FOO_BAR_BAZ_JS"
                     use_base_dir="false"
                     compress="gzip" />
         </includes>
        </release>''',
                                       run_gatherers=True)

        with self.assertRaises(AssertionError) as assertion_error:
            formatter = resource_map.GetFormatter('resource_file_map_source')
            util.StripBlankLinesAndComments(''.join(formatter(grd, 'en', '.')))
        self.assertTrue(str(assertion_error.exception). \
            startswith('resource_path attribute missing for IDR_FOO_BAR_BAZ_JS'))
Esempio n. 10
0
    def testFormatResourceMapWithGeneratedFile(self):
        os.environ["root_gen_dir"] = "gen"

        grd = util.ParseGrdForUnittest('''\
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="resource_map_header.h" />
        </outputs>
        <release seq="3">
          <includes first_id="10000">
            <include type="BINDATA"
                     file="${root_gen_dir}/foo/bar/baz.js"
                     name="IDR_FOO_BAR_BAZ_JS"
                     use_base_dir="false"
                     compress="gzip" />
         </includes>
        </release>''',
                                       run_gatherers=True)

        formatter = resource_map.GetFormatter('resource_file_map_source')
        output = util.StripBlankLinesAndComments(''.join(
            formatter(grd, 'en', '.')))
        expected = '''\
#include "resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"@out_folder@/gen/foo/bar/baz.js", IDR_FOO_BAR_BAZ_JS},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);'''
        self.assertEqual(expected, output)
Esempio n. 11
0
    def testRcIncludeFile(self):
        root = util.ParseGrdForUnittest('''
      <includes>
        <include type="TXT" name="TEXT_ONE" file="bingo.txt"/>
        <include type="TXT" name="TEXT_TWO" file="bingo2.txt"  filenameonly="true" />
      </includes>''',
                                        base_dir='/temp')

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        expected = (_PREAMBLE + u'TEXT_ONE           TXT                "%s"\n'
                    u'TEXT_TWO           TXT                "%s"' %
                    (util.normpath('/temp/bingo.txt').replace(
                        '\\', '\\\\'), 'bingo2.txt'))
        # hackety hack to work on win32&lin
        output = re.sub('"[c-zC-Z]:', '"', output)
        self.assertEqual(expected, output)
Esempio n. 12
0
    def testTranslations(self):
        root = util.ParseGrdForUnittest("""
    <messages>
        <message name="ID_HELLO">Hello!</message>
        <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>
          Joi</ex></ph></message>
      </messages>
    """)

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'fr'),
                                    buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        self.assertEqual(
            u"""\
localizedStrings["Hello!"] = "H\xe9P\xe9ll\xf4P\xf4!";
localizedStrings["Hello %s"] = "H\xe9P\xe9ll\xf4P\xf4 %s";\
""", output)
Esempio n. 13
0
    def testRcIncludeStructure(self):
        root = util.ParseGrdForUnittest('''
      <structures>
        <structure type="tr_html" name="IDR_HTML" file="bingo.html"/>
        <structure type="tr_html" name="IDR_HTML2" file="bingo2.html"/>
      </structures>''',
                                        base_dir='/temp')
        # We do not run gatherers as it is not needed and wouldn't find the file

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        expected = (_PREAMBLE + u'IDR_HTML           HTML               "%s"\n'
                    u'IDR_HTML2          HTML               "%s"' %
                    (util.normpath('/temp/bingo.html').replace('\\', '\\\\'),
                     util.normpath('/temp/bingo2.html').replace('\\', '\\\\')))
        # hackety hack to work on win32&lin
        output = re.sub('"[c-zC-Z]:', '"', output)
        self.assertEqual(expected, output)
 def testEmit(self):
   grd = util.ParseGrdForUnittest('''
       <outputs>
         <output type="rc_all" filename="dummy">
           <emit emit_type="prepend">Wrong</emit>
         </output>
         <if expr="False">
           <output type="rc_header" filename="dummy">
             <emit emit_type="prepend">No</emit>
           </output>
         </if>
         <output type="rc_header" filename="dummy">
           <emit emit_type="append">Error</emit>
         </output>
         <output type="rc_header" filename="dummy">
           <emit emit_type="prepend">Bingo</emit>
         </output>
       </outputs>''')
   output = ''.join(rc_header.Format(grd, 'en', '.'))
   output = util.StripBlankLinesAndComments(output)
   self.assertEqual('#pragma once\nBingo', output)
Esempio n. 15
0
    def testRcIncludeFlattenedHtmlFile(self):
        input_file = util.PathFromRoot('grit/testdata/include_test.html')
        output_file = '%s/HTML_FILE1_include_test.html' % tempfile.gettempdir()
        root = util.ParseGrdForUnittest('''
      <includes>
        <include name="HTML_FILE1" flattenhtml="true" file="%s" type="BINDATA" />
      </includes>''' % input_file)

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root,
                                    DummyOutput('rc_all', 'en', output_file),
                                    buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())

        expected = (
            _PREAMBLE +
            u'HTML_FILE1         BINDATA            "HTML_FILE1_include_test.html"'
        )
        # hackety hack to work on win32&lin
        output = re.sub('"[c-zC-Z]:', '"', output)
        self.assertEqual(expected, output)

        file_contents = util.ReadFile(output_file, util.RAW_TEXT)

        # Check for the content added by the <include> tag.
        self.failUnless(file_contents.find('Hello Include!') != -1)
        # Check for the content that was removed by if tag.
        self.failUnless(file_contents.find('should be removed') == -1)
        # Check for the content that was kept in place by if.
        self.failUnless(file_contents.find('should be kept') != -1)
        self.failUnless(file_contents.find('in the middle...') != -1)
        self.failUnless(file_contents.find('at the end...') != -1)
        # Check for nested content that was kept
        self.failUnless(file_contents.find('nested true should be kept') != -1)
        self.failUnless(
            file_contents.find('silbing true should be kept') != -1)
        # Check for removed "<if>" and "</if>" tags.
        self.failUnless(file_contents.find('<if expr=') == -1)
        self.failUnless(file_contents.find('</if>') == -1)
        os.remove(output_file)
    def testMessages(self):
        root = util.ParseGrdForUnittest("""
    <messages>
      <message name="IDS_QUESTIONS">Do you want to play questions?</message>
      <message name="IDS_QUOTES">
      "What's in a name, <ph name="NAME">%s<ex>Brandon</ex></ph>?"
      </message>
      <message name="IDS_LINE_BREAKS">
          Was that rhetoric?
No.
Statement.  Two all.  Game point.
</message>
      <message name="IDS_NON_ASCII">
         \xc3\xb5\\xc2\\xa4\\\xc2\xa4\\\\xc3\\xb5\xe4\xa4\xa4
      </message>
    </messages>
      """)

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('c_format', 'en'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        self.assertEqual(
            u"""\
#include "resource.h"
const char* GetString(int id) {
  switch (id) {
    case IDS_QUESTIONS:
      return "Do you want to play questions?";
    case IDS_QUOTES:
      return "\\"What\\'s in a name, %s?\\"";
    case IDS_LINE_BREAKS:
      return "Was that rhetoric?\\nNo.\\nStatement.  Two all.  Game point.";
    case IDS_NON_ASCII:
      return "\\303\\265\\xc2\\xa4\\\\302\\244\\\\xc3\\xb5\\344\\244\\244";
    default:
      return 0;
  }
}""", output)
Esempio n. 17
0
 def testEmit(self):
   grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
     <grit latest_public_release="2" source_lang_id="en" current_release="3" base_dir=".">
       <outputs>
         <output type="rc_all" filename="dummy">
           <emit emit_type="prepend">Wrong</emit>
         </output>
         <if expr="False">
           <output type="rc_header" filename="dummy">
             <emit emit_type="prepend">No</emit>
           </output>
         </if>
         <output type="rc_header" filename="dummy">
           <emit emit_type="append">Error</emit>
         </output>
         <output type="rc_header" filename="dummy">
           <emit emit_type="prepend">Bingo</emit>
         </output>
       </outputs>
     </grit>'''), '.')
   output = ''.join(rc_header.Format(grd, 'en', '.'))
   output = util.StripBlankLinesAndComments(output)
   self.assertEqual('#pragma once\nBingo', output)
Esempio n. 18
0
    def testMessages(self):
        root = util.ParseGrdForUnittest(u"""
    <messages>
      <message name="IDS_SIMPLE_MESSAGE">
              Simple message.
      </message>
      <message name="IDS_QUOTES">
              element\u2019s \u201c<ph name="NAME">%s<ex>name</ex></ph>\u201d attribute
      </message>
      <message name="IDS_PLACEHOLDERS">
              <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNING_COUNT">%2$d<ex>1</ex></ph> warning
      </message>
      <message name="IDS_STARTS_WITH_SPACE">
              ''' (<ph name="COUNT">%d<ex>2</ex></ph>)
      </message>
      <message name="IDS_DOUBLE_QUOTES">
              A "double quoted" message.
      </message>
      <message name="IDS_BACKSLASH">
              \\
      </message>
    </messages>
    """)

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'en'),
                                    buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        self.assertEqual(
            u"""\
localizedStrings["Simple message."] = "Simple message.";
localizedStrings["element\u2019s \u201c%s\u201d attribute"] = "element\u2019s \u201c%s\u201d attribute";
localizedStrings["%d error, %d warning"] = "%1$d error, %2$d warning";
localizedStrings[" (%d)"] = " (%d)";
localizedStrings["A \\\"double quoted\\\" message."] = "A \\\"double quoted\\\" message.";
localizedStrings["\\\\"] = "\\\\";""", output)
Esempio n. 19
0
  def testFormatResourceMap(self):
    grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="menu" name="IDC_KLONKMENU"
                       file="grit\\testdata\\klonk.rc" encoding="utf-16" />
          </structures>
          <includes first_id="10000">
            <include type="foo" file="abc" name="IDS_FIRSTPRESENT" />
            <include type="foo" file="rst" resource_path="new_path/rst_resource"
                     name="IDS_WITHRESOURCEPATH" />
            <if expr="False">
              <include type="foo" file="def" name="IDS_MISSING" />
            </if>
            <if expr="lang != 'es'">
              <include type="foo" file="ghi" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <if expr="lang == 'es'">
              <include type="foo" file="jkl" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <include type="foo" file="mno" name="IDS_THIRDPRESENT" />
            <include type="foo" file="opq" name="IDS_FOURTHPRESENT"
                     skip_in_resource_map="true" />
         </includes>
       </release>''', run_gatherers=True)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
    self.assertEqual(
        '''\
#include <stddef.h>
#include "ui/base/webui/resource_path.h"
extern const webui::ResourcePath kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
    self.assertEqual(
        '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include <iterator>
#include "the_rc_header.h"
const webui::ResourcePath kTheRcHeader[] = {
  {"IDC_KLONKMENU", IDC_KLONKMENU},
  {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT},
  {"IDS_WITHRESOURCEPATH", IDS_WITHRESOURCEPATH},
  {"IDS_LANGUAGESPECIFIC", IDS_LANGUAGESPECIFIC},
  {"IDS_THIRDPRESENT", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = std::size(kTheRcHeader);''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.')))
    self.assertEqual(
        '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include <iterator>
#include "the_rc_header.h"
const webui::ResourcePath kTheRcHeader[] = {
  {"grit/testdata/klonk.rc", IDC_KLONKMENU},
  {"abc", IDS_FIRSTPRESENT},
  {"new_path/rst_resource", IDS_WITHRESOURCEPATH},
  {"ghi", IDS_LANGUAGESPECIFIC},
  {"mno", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = std::size(kTheRcHeader);''', output)
Esempio n. 20
0
    def testFormatResourceMapWithOutputAllEqualsFalseForIncludes(self):
        grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="menu" name="IDC_KLONKMENU"
                       file="grit\\testdata\\klonk.rc" encoding="utf-16" />
          </structures>
          <includes first_id="10000">
            <include type="foo" file="abc" name="IDS_FIRSTPRESENT" />
            <if expr="False">
              <include type="foo" file="def" name="IDS_MISSING" />
            </if>
            <include type="foo" file="mno" name="IDS_THIRDPRESENT" />
            <if expr="True">
              <include type="foo" file="blob" name="IDS_BLOB" />
            </if>
            <if expr="True">
              <then>
                <include type="foo" file="meteor" name="IDS_METEOR" />
              </then>
              <else>
                <include type="foo" file="roetem" name="IDS_METEOR" />
              </else>
            </if>
            <if expr="False">
              <include type="foo" file="zyx" name="IDS_LAST" />
            </if>
            <if expr="True">
              <include type="foo" file="xyz" name="IDS_LAST" />
            </if>
         </includes>
        </release>''',
                                       run_gatherers=True)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDC_KLONKMENU", IDC_KLONKMENU},
  {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT},
  {"IDS_THIRDPRESENT", IDS_THIRDPRESENT},
  {"IDS_BLOB", IDS_BLOB},
  {"IDS_METEOR", IDS_METEOR},
  {"IDS_LAST", IDS_LAST},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_file_map_source')(grd, 'en',
                                                                  '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"grit/testdata/klonk.rc", IDC_KLONKMENU},
  {"abc", IDS_FIRSTPRESENT},
  {"mno", IDS_THIRDPRESENT},
  {"blob", IDS_BLOB},
  {"meteor", IDS_METEOR},
  {"xyz", IDS_LAST},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
Esempio n. 21
0
    def testFormatResourceMap(self):
        grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="menu" name="IDC_KLONKMENU"
                       file="grit\\testdata\\klonk.rc" encoding="utf-16" />
          </structures>
          <includes first_id="10000">
            <include type="foo" file="abc" name="IDS_FIRSTPRESENT" />
            <if expr="False">
              <include type="foo" file="def" name="IDS_MISSING" />
            </if>
            <if expr="lang != 'es'">
              <include type="foo" file="ghi" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <if expr="lang == 'es'">
              <include type="foo" file="jkl" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <include type="foo" file="mno" name="IDS_THIRDPRESENT" />
            <include type="foo" file="opq" name="IDS_FOURTHPRESENT"
                                   skip_in_resource_map="true" />
         </includes>
       </release>''',
                                       run_gatherers=True)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDC_KLONKMENU", IDC_KLONKMENU},
  {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT},
  {"IDS_LANGUAGESPECIFIC", IDS_LANGUAGESPECIFIC},
  {"IDS_THIRDPRESENT", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_file_map_source')(grd, 'en',
                                                                  '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"grit/testdata/klonk.rc", IDC_KLONKMENU},
  {"abc", IDS_FIRSTPRESENT},
  {"ghi", IDS_LANGUAGESPECIFIC},
  {"mno", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
Esempio n. 22
0
    def testFormatResourceMapWithOutputAllEqualsFalseForStructures(self):
        grd = util.ParseGrdForUnittest('''
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
          <output type="resource_map_source"
                  filename="the_resource_map_header.cc" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="chrome_scaled_image" name="IDR_KLONKMENU"
                       file="foo.png" />
            <if expr="False">
              <structure type="chrome_scaled_image" name="IDR_MISSING"
                         file="bar.png" />
            </if>
            <if expr="True">
              <structure type="chrome_scaled_image" name="IDR_BLOB"
                         file="blob.png" />
            </if>
            <if expr="True">
              <then>
                <structure type="chrome_scaled_image" name="IDR_METEOR"
                           file="meteor.png" />
              </then>
              <else>
                <structure type="chrome_scaled_image" name="IDR_METEOR"
                           file="roetem.png" />
              </else>
            </if>
            <if expr="False">
              <structure type="chrome_scaled_image" name="IDR_LAST"
                         file="zyx.png" />
            </if>
            <if expr="True">
              <structure type="chrome_scaled_image" name="IDR_LAST"
                         file="xyz.png" />
            </if>
         </structures>
        </release>''',
                                       run_gatherers=True)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDR_KLONKMENU", IDR_KLONKMENU},
  {"IDR_BLOB", IDR_BLOB},
  {"IDR_METEOR", IDR_METEOR},
  {"IDR_LAST", IDR_LAST},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
        output = util.StripBlankLinesAndComments(''.join(
            resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
        self.assertEqual(
            '''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDR_KLONKMENU", IDR_KLONKMENU},
  {"IDR_BLOB", IDR_BLOB},
  {"IDR_METEOR", IDR_METEOR},
  {"IDR_LAST", IDR_LAST},
};
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
Esempio n. 23
0
    def testRcSection(self):
        root = util.ParseGrdForUnittest('''
      <structures>
          <structure type="menu" name="IDC_KLONKMENU" file="grit\\testdata\klonk.rc" encoding="utf-16" />
          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
          <structure type="version" name="VS_VERSION_INFO" file="grit\\testdata\klonk.rc" encoding="utf-16" />
      </structures>''')
        root.SetOutputLanguage('en')
        root.RunGatherers()

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
        output = util.StripBlankLinesAndComments(buf.getvalue())
        expected = _PREAMBLE + u'''\
IDC_KLONKMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit",                       IDM_EXIT
        MENUITEM "This be ""Klonk"" me like",   ID_FILE_THISBE
        POPUP "gonk"
        BEGIN
            MENUITEM "Klonk && is [good]",           ID_GONK_KLONKIS
        END
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About ...",                  IDM_ABOUT
    END
END

IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75
STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System", 0, 0, 0x0
BEGIN
    ICON            IDI_KLONK,IDC_MYICON,14,9,20,20
    LTEXT           "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8,
                    SS_NOPREFIX
    LTEXT           "Copyright (C) 2005",IDC_STATIC,49,20,119,8
    DEFPUSHBUTTON   "OK",IDOK,195,6,30,11,WS_GROUP
    CONTROL         "Jack ""Black"" Daniels",IDC_RADIO1,"Button",
                    BS_AUTORADIOBUTTON,46,51,84,10
END

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x17L
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription", "klonk Application"
            VALUE "FileVersion", "1, 0, 0, 1"
            VALUE "InternalName", "klonk"
            VALUE "LegalCopyright", "Copyright (C) 2005"
            VALUE "OriginalFilename", "klonk.exe"
            VALUE "ProductName", " klonk Application"
            VALUE "ProductVersion", "1, 0, 0, 1"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END'''.strip()
        for expected_line, output_line in zip(expected.split(),
                                              output.split()):
            self.assertEqual(expected_line, output_line)
Esempio n. 24
0
  def testFormatResourceMap(self):
    grd = grd_reader.Parse(StringIO.StringIO(
      '''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en" current_release="3"
            base_dir=".">
        <outputs>
          <output type="rc_header" filename="the_rc_header.h" />
          <output type="resource_map_header"
                  filename="the_resource_map_header.h" />
        </outputs>
        <release seq="3">
          <structures first_id="300">
            <structure type="menu" name="IDC_KLONKMENU"
                       file="grit\\testdata\\klonk.rc" encoding="utf-16" />
          </structures>
          <includes first_id="10000">
            <include type="foo" file="abc" name="IDS_FIRSTPRESENT" />
            <if expr="False">
              <include type="foo" file="def" name="IDS_MISSING" />
            </if>
            <if expr="lang != 'es'">
              <include type="foo" file="ghi" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <if expr="lang == 'es'">
              <include type="foo" file="jkl" name="IDS_LANGUAGESPECIFIC" />
            </if>
            <include type="foo" file="mno" name="IDS_THIRDPRESENT" />
         </includes>
        </release>
      </grit>'''), util.PathFromRoot('.'))
    grd.SetOutputLanguage('en')
    grd.RunGatherers()
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_header')(grd, 'en', '.')))
    self.assertEqual('''\
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
  const char* const name;
  int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap kTheRcHeader[];
extern const size_t kTheRcHeaderSize;''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
    self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"IDC_KLONKMENU", IDC_KLONKMENU},
  {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT},
  {"IDS_MISSING", IDS_MISSING},
  {"IDS_LANGUAGESPECIFIC", IDS_LANGUAGESPECIFIC},
  {"IDS_THIRDPRESENT", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
    output = util.StripBlankLinesAndComments(''.join(
        resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.')))
    self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
  {"grit/testdata/klonk.rc", IDC_KLONKMENU},
  {"abc", IDS_FIRSTPRESENT},
  {"def", IDS_MISSING},
  {"ghi", IDS_LANGUAGESPECIFIC},
  {"jkl", IDS_LANGUAGESPECIFIC},
  {"mno", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)