Esempio n. 1
0
 def testLoadTranslations(self):
     xml = '''<?xml version="1.0" encoding="UTF-8"?>
   <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
     <translations>
       <file path="generated_resources_fr.xtb" lang="fr" />
     </translations>
     <release seq="3">
       <messages>
         <message name="ID_HELLO">Hello!</message>
         <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message>
       </messages>
     </release>
   </grit>'''
     grd = grd_reader.Parse(StringIO(xml),
                            util.PathFromRoot('grit/testdata'))
     grd.SetOutputLanguage('en')
     grd.RunGatherers()
     self.VerifyCliquesContainEnglishAndFrenchAndNothingElse(
         _GetAllCliques(grd))
Esempio n. 2
0
    def GetFirstIdsFile(self):
        """Returns a usable path to the first_ids file, if set, otherwise
    returns None.

    The first_ids_file attribute is by default relative to the
    base_dir of the .grd file, but may be prefixed by GRIT_DIR/,
    which makes it relative to the directory of grit.py
    (e.g. GRIT_DIR/../gritsettings/resource_ids).
    """
        if not self.attrs['first_ids_file']:
            return None

        path = self.attrs['first_ids_file']
        GRIT_DIR_PREFIX = 'GRIT_DIR'
        if (path.startswith(GRIT_DIR_PREFIX)
                and path[len(GRIT_DIR_PREFIX)] in ['/', '\\']):
            return util.PathFromRoot(path[len(GRIT_DIR_PREFIX) + 1:])
        else:
            return self.ToRealPath(path)
Esempio n. 3
0
 def MakeGrd(self):
     grd = grd_reader.Parse(
         StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
   <grit latest_public_release="2" source_lang_id="en-US" current_release="3">
     <release seq="3">
       <structures>
         <structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH"
           file="GoogleDesktop.adm" exclude_from_rc="true" />
         <structure type="txt" name="BINGOBONGO"
           file="README.txt" exclude_from_rc="true" />
       </structures>
     </release>
     <outputs>
       <output filename="de_res.rc" type="rc_all" lang="de" />
     </outputs>
   </grit>'''), util.PathFromRoot('grit/testdata'))
     grd.SetOutputContext('en', {})
     grd.RunGatherers(recursive=True)
     return grd
 def testVariables(self):
   grd = util.ParseGrdForUnittest('''
       <structures>
         <structure type="chrome_html" name="hello_tmpl" file="structure_variables.html" expand_variables="true" variables="GREETING=Hello,THINGS=foo,, bar,, baz,EQUATION=2+2==4,filename=simple" flattenhtml="true"></structure>
       </structures>''', base_dir=util.PathFromRoot('grit/testdata'))
   grd.SetOutputLanguage('en')
   grd.RunGatherers()
   node, = grd.GetChildrenOfType(structure.StructureNode)
   filename = node.Process(tempfile.gettempdir())
   filepath = os.path.join(tempfile.gettempdir(), filename)
   with open(filepath) as f:
     result = f.read()
     self.failUnlessEqual(('<h1>Hello!</h1>\n'
                           'Some cool things are foo, bar, baz.\n'
                           'Did you know that 2+2==4?\n'
                           '<p>\n'
                           '  Hello!\n'
                           '</p>\n'), result)
   os.remove(filepath)
Esempio n. 5
0
    def testWhitelistResources(self):
        output_dir = util.TempDir({})
        builder = build.RcBuilder()

        class DummyOpts(object):
            def __init__(self):
                self.input = util.PathFromRoot(
                    'grit/testdata/whitelist_resources.grd')
                self.verbose = False
                self.extra_verbose = False

        whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt')
        builder.Run(DummyOpts(),
                    ['-o', output_dir.GetPath(), '-w', whitelist_file])
        header = output_dir.GetPath('whitelist_test_resources.h')
        map_cc = output_dir.GetPath('whitelist_test_resources_map.cc')
        map_h = output_dir.GetPath('whitelist_test_resources_map.h')
        pak = output_dir.GetPath('whitelist_test_resources.pak')

        # Ensure the resource map header and .pak files exist, but don't verify
        # their content.
        self.failUnless(os.path.exists(map_h))
        self.failUnless(os.path.exists(pak))

        whitelisted_ids = [
            'IDR_STRUCTURE_WHITELISTED',
            'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED',
            'IDR_INCLUDE_WHITELISTED',
        ]
        non_whitelisted_ids = [
            'IDR_STRUCTURE_NOT_WHITELISTED',
            'IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED',
            'IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED',
            'IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED',
            'IDR_INCLUDE_NOT_WHITELISTED',
        ]
        for output_file in (header, map_cc):
            self._verifyWhitelistedOutput(
                output_file,
                whitelisted_ids,
                non_whitelisted_ids,
            )
        output_dir.CleanUp()
Esempio n. 6
0
  def testIffyness(self):
    grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
        <translations>
          <if expr="lang == 'fr'">
            <file path="generated_resources_fr.xtb" lang="fr" />
          </if>
        </translations>
        <release seq="3">
          <messages>
            <message name="ID_HELLO">Hello!</message>
            <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message>
          </messages>
        </release>
      </grit>'''), util.PathFromRoot('grit/testdata'))
    grd.SetOutputLanguage('en')
    grd.RunGatherers()

    grd.SetOutputLanguage('fr')
    grd.RunGatherers()
Esempio n. 7
0
  def testStructureNodeOutputfile(self):
    input_file = util.PathFromRoot('grit/testdata/simple.html')
    root = grd_reader.Parse(StringIO.StringIO(
      '<structure type="tr_html" name="IDR_HTML" file="%s" />' %input_file),
      flexible_root = True)
    util.FixRootForUnittest(root, '.')
    # We must run the gatherers since we'll be wanting the translation of the
    # file.  The file exists in the location pointed to.
    root.RunGatherers(recursive=True)

    output_dir = tempfile.gettempdir()
    en_file = root.FileForLanguage('en', output_dir)
    self.failUnless(en_file == input_file)
    fr_file = root.FileForLanguage('fr', output_dir)
    self.failUnless(fr_file == os.path.join(output_dir, 'fr_simple.html'))

    contents = util.ReadFile(fr_file, util.RAW_TEXT)

    self.failUnless(contents.find('<p>') != -1)  # should contain the markup
    self.failUnless(contents.find('Hello!') == -1)  # should be translated
Esempio n. 8
0
    def testOutputAllResourceDefinesFalse(self):
        output_dir = tempfile.mkdtemp()
        builder = build.RcBuilder()

        class DummyOpts(object):
            def __init__(self):
                self.input = util.PathFromRoot(
                    'grit/testdata/whitelist_resources.grd')
                self.verbose = False
                self.extra_verbose = False

        whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt')
        builder.Run(DummyOpts(), [
            '-o',
            output_dir,
            '-w',
            whitelist_file,
            '--no-output-all-resource-defines',
        ])
        header = os.path.join(output_dir, 'whitelist_test_resources.h')
        map_cc = os.path.join(output_dir, 'whitelist_test_resources_map.cc')

        whitelisted_ids = [
            'IDR_STRUCTURE_WHITELISTED',
            'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED',
            'IDR_INCLUDE_WHITELISTED',
        ]
        non_whitelisted_ids = [
            'IDR_STRUCTURE_NOT_WHITELISTED',
            'IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED',
            'IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED',
            'IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED',
            'IDR_INCLUDE_NOT_WHITELISTED',
        ]
        for output_file in (header, map_cc):
            self._verifyWhitelistedOutput(
                output_file,
                whitelisted_ids,
                non_whitelisted_ids,
            )
Esempio n. 9
0
    def testRcIncludeFlattenedHtmlFile(self):
        input_file = util.PathFromRoot('grit/testdata/include_test.html')
        output_file = '%s/HTML_FILE1_include_test.html' % tempfile.gettempdir()
        root = grd_reader.Parse(StringIO.StringIO('''
      <includes>
        <include name="HTML_FILE1" flattenhtml="true" file="%s" type="BINDATA" />
      </includes>''' % input_file),
                                flexible_root=True)
        util.FixRootForUnittest(root, '.')

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

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

        fo = file(output_file)
        file_contents = fo.read()
        fo.close()

        # 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)
Esempio n. 10
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)
Esempio n. 11
0
  def testGenerateDepFile(self):
    output_dir = tempfile.mkdtemp()
    builder = build.RcBuilder()
    class DummyOpts(object):
      def __init__(self):
        self.input = util.PathFromRoot('grit/testdata/substitute.grd')
        self.verbose = False
        self.extra_verbose = False
    builder.Run(DummyOpts(), ['-o', output_dir, '--dep-dir', output_dir])

    expected_dep_file = os.path.join(output_dir, 'substitute.grd.d')
    self.failUnless(os.path.isfile(expected_dep_file))
    with open(expected_dep_file) as f:
      line = f.readline()
      (dep_file_name, deps_string) = line.split(': ')
      deps = deps_string.split(' ')
      self.failUnlessEqual(os.path.abspath(expected_dep_file),
          os.path.abspath(os.path.join(output_dir, dep_file_name)),
          "depfile should refer to itself as the depended upon file")
      self.failUnlessEqual(1, len(deps))
      self.failUnlessEqual(deps[0],
          util.PathFromRoot('grit/testdata/substitute.xmb'))
Esempio n. 12
0
  def testSkeleton(self):
    grd = grd_reader.Parse(StringIO.StringIO(
      '''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
        <release seq="3">
          <structures>
            <structure type="dialog" name="IDD_ABOUTBOX" file="klonk.rc" encoding="utf-16-le">
              <skeleton expr="lang == 'fr'" variant_of_revision="1" file="klonk-alternate-skeleton.rc" />
            </structure>
          </structures>
        </release>
      </grit>'''), dir=util.PathFromRoot('grit\\test\\data'))
    grd.RunGatherers(recursive=True)
    grd.output_language = 'fr'

    node = grd.GetNodeById('IDD_ABOUTBOX')
    formatter = node.ItemFormatter('rc_all')
    self.failUnless(formatter)
    transl = formatter.Format(node, 'fr')

    self.failUnless(transl.count('040704') and transl.count('110978'))
    self.failUnless(transl.count('2005",IDC_STATIC'))
  def testSectionFromFile(self):
    buf = '''IDC_SOMETHINGELSE BINGO
BEGIN
    BLA BLA
    BLA BLA
END
%s

IDC_KLONK BINGOBONGO
BEGIN
  HONGO KONGO
END
''' % self.part_we_want

    f = StringIO.StringIO(buf)

    out = rc.Section.FromFile(f, 'IDC_KLONKACC')
    self.failUnless(out.GetText() == self.part_we_want)

    out = rc.Section.FromFile(util.PathFromRoot(r'grit/test/data/klonk.rc'),
                              'IDC_KLONKACC',
                              encoding='utf-16')
    self.failUnless(out.GetText() == self.part_we_want)
Esempio n. 14
0
    def testStructureNodeOutputfile(self):
        input_file = util.PathFromRoot('grit/testdata/simple.html')
        root = util.ParseGrdForUnittest('''\
        <structures>
          <structure type="tr_html" name="IDR_HTML" file="%s" />
        </structures>''' % input_file)
        struct, = root.GetChildrenOfType(structure.StructureNode)
        # We must run the gatherer since we'll be wanting the translation of the
        # file.  The file exists in the location pointed to.
        root.SetOutputLanguage('en')
        root.RunGatherers()

        output_dir = tempfile.gettempdir()
        en_file = struct.FileForLanguage('en', output_dir)
        self.failUnless(en_file == input_file)
        fr_file = struct.FileForLanguage('fr', output_dir)
        self.failUnless(fr_file == os.path.join(output_dir, 'fr_simple.html'))

        contents = util.ReadFile(fr_file, util.RAW_TEXT)

        self.failUnless(
            contents.find('<p>') != -1)  # should contain the markup
        self.failUnless(contents.find('Hello!') == -1)  # should be translated
Esempio n. 15
0
    def testSubstitutionRc(self):
        root = grd_reader.Parse(
            StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
    <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
          base_dir=".">
      <outputs>
        <output lang="en" type="rc_all" filename="grit\\testdata\klonk_resources.rc"/>
      </outputs>
      <release seq="1" allow_pseudo="False">
        <structures>
          <structure type="menu" name="IDC_KLONKMENU"
              file="grit\\testdata\klonk.rc" encoding="utf-16"
              expand_variables="true" />
        </structures>
        <messages>
          <message name="good" sub_variable="true">
            excellent
          </message>
        </messages>
      </release>
    </grit>
    '''), util.PathFromRoot('.'))
        root.SetOutputLanguage('en')
        root.RunGatherers()

        buf = StringIO.StringIO()
        build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
        output = buf.getvalue()
        self.assertEqual(
            '''
// This file is automatically generated by GRIT.  Do not edit.

#include "resource.h"
#include <winresrc.h>
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif
#define IDC_STATIC (-1)

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL


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 excellent",           ID_GONK_KLONKIS
        END
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About ...",                  IDM_ABOUT
    END
END

STRINGTABLE
BEGIN
  good            "excellent"
END
'''.strip(), output.strip())
Esempio n. 16
0
 def __init__(self):
     self.input = util.PathFromRoot(
         'grit/testdata/substitute_no_ids.grd')
     self.verbose = False
     self.extra_verbose = False
Esempio n. 17
0
 def __init__(self):
     self.input = util.PathFromRoot('grit/testdata/depfile.grd')
     self.verbose = False
     self.extra_verbose = False
Esempio n. 18
0
 def __init__(self):
     self.input = util.PathFromRoot(
         'grit/testdata/allowlist_resources.grd')
     self.verbose = False
     self.extra_verbose = False
Esempio n. 19
0
 def testParseLargeFile(self):
   def Callback(id, structure):
     pass
   path = util.PathFromRoot('grit/testdata/generated_resources_fr.xtb')
   with open(path, 'rb') as xtb:
     xtb_reader.Parse(xtb, Callback)
Esempio n. 20
0
 def __init__(self):
     self.input = util.PathFromRoot(
         'grit/testdata/whitelist_strings.grd')
     self.verbose = False
     self.extra_verbose = False
 def testFromFile(self):
   fname = util.PathFromRoot('grit/testdata/GoogleDesktop.adm')
   gatherer = admin_template.AdmGatherer(fname)
   gatherer.Parse()
   cliques = gatherer.GetCliques()
   self.VerifyCliquesFromAdmFile(cliques)
Esempio n. 22
0
    def testExtractTranslations(self):
        path = util.PathFromRoot('grit/testdata')
        current_grd = grd_reader.Parse(
            StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
        <release seq="3">
          <messages>
            <message name="IDS_SIMPLE">
              One
            </message>
            <message name="IDS_PLACEHOLDER">
              <ph name="NUMBIRDS">%s<ex>3</ex></ph> birds
            </message>
            <message name="IDS_PLACEHOLDERS">
              <ph name="ITEM">%d<ex>1</ex></ph> of <ph name="COUNT">%d<ex>3</ex></ph>
            </message>
            <message name="IDS_REORDERED_PLACEHOLDERS">
              <ph name="ITEM">$1<ex>1</ex></ph> of <ph name="COUNT">$2<ex>3</ex></ph>
            </message>
            <message name="IDS_CHANGED">
              This is the new version
            </message>
            <message name="IDS_TWIN_1">Hello</message>
            <message name="IDS_TWIN_2">Hello</message>
            <message name="IDS_NOT_TRANSLATEABLE" translateable="false">:</message>
            <message name="IDS_LONGER_TRANSLATED">
              Removed document <ph name="FILENAME">$1<ex>c:\temp</ex></ph>
            </message>
            <message name="IDS_DIFFERENT_TWIN_1">Howdie</message>
            <message name="IDS_DIFFERENT_TWIN_2">Howdie</message>
          </messages>
          <structures>
            <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="klonk.rc" />
            <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" />
          </structures>
        </release>
      </grit>'''), path)
        current_grd.RunGatherers(recursive=True)

        source_rc_path = util.PathFromRoot('grit/testdata/source.rc')
        source_rc = file(source_rc_path).read()
        transl_rc_path = util.PathFromRoot('grit/testdata/transl.rc')
        transl_rc = file(transl_rc_path).read()

        tool = transl2tc.TranslationToTc()
        output_buf = StringIO.StringIO()
        globopts = MakeOptions()
        globopts.verbose = True
        globopts.output_stream = output_buf
        tool.Setup(globopts, [])
        translations = tool.ExtractTranslations(current_grd, source_rc,
                                                source_rc_path, transl_rc,
                                                transl_rc_path)

        values = translations.values()
        output = output_buf.getvalue()

        self.failUnless('Ein' in values)
        self.failUnless('NUMBIRDS Vogeln' in values)
        self.failUnless('ITEM von COUNT' in values)
        self.failUnless(values.count('Hallo') == 1)
        self.failIf('Dass war die alte Version' in values)
        self.failIf(':' in values)
        self.failIf('Dokument FILENAME ist entfernt worden' in values)
        self.failIf('Nicht verwendet' in values)
        self.failUnless(
            ('Howdie' in values or 'Hallo sagt man' in values)
            and not ('Howdie' in values and 'Hallo sagt man' in values))

        self.failUnless(
            'XX01XX&SkraXX02XX&HaettaXX03XXThetta er "Klonk" sem eg fylaXX04XXgonkurinnXX05XXKlonk && er "gott"XX06XX&HjalpXX07XX&Um...XX08XX'
            in values)

        self.failUnless('I lagi' in values)

        self.failUnless(
            output.count(
                'Structure of message IDS_REORDERED_PLACEHOLDERS has changed'))
        self.failUnless(output.count('Message IDS_CHANGED has changed'))
        self.failUnless(
            output.count(
                'Structure of message IDS_LONGER_TRANSLATED has changed'))
        self.failUnless(
            output.count('Two different translations for "Howdie"'))
        self.failUnless(
            output.count(
                'IDD_DIFFERENT_LENGTH_IN_TRANSL has wrong # of cliques'))
    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>
            <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>
      </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},
  {"IDR_BLOB", IDR_BLOB},
  {"IDR_METEOR", IDR_METEOR},
  {"IDR_LAST", IDR_LAST},
};
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},
  {"IDR_BLOB", IDR_BLOB},
  {"IDR_METEOR", IDR_METEOR},
  {"IDR_LAST", IDR_LAST},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
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)