def testRcHeaderFormat(self):
    grd = util.ParseGrdForUnittest('''
        <includes first_id="300" comment="bingo">
          <include type="gif" name="IDR_LOGO" file="images/logo.gif" />
        </includes>
        <messages first_id="10000">
          <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="IDS_BONGO">
            Bongo!
          </message>
        </messages>''')

    # Using the default settings.
    output = rc_header.FormatDefines(grd)
    self.assertEqual(('#define IDR_LOGO 300\n'
                      '#define IDS_GREETING 10000\n'
                      '#define IDS_BONGO 10001\n'), ''.join(output))

    # Using resource allowlist support.
    grd.SetAllowlistSupportEnabled(True)
    output = rc_header.FormatDefines(grd)
    self.assertEqual(('#define IDR_LOGO '
                      '(::ui::AllowlistedResource<300>(), 300)\n'
                      '#define IDS_GREETING '
                      '(::ui::AllowlistedResource<10000>(), 10000)\n'
                      '#define IDS_BONGO '
                      '(::ui::AllowlistedResource<10001>(), 10001)\n'),
                     ''.join(output))
Exemplo n.º 2
0
    def testRcHeaderFormat(self):
        grd = util.ParseGrdForUnittest('''
        <includes first_id="300" comment="bingo">
          <include type="gif" name="IDR_LOGO" file="images/logo.gif" />
        </includes>
        <messages first_id="10000">
          <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="IDS_BONGO">
            Bongo!
          </message>
        </messages>''')

        # Using the default rc_header format string.
        output = rc_header.FormatDefines(grd,
                                         grd.ShouldOutputAllResourceDefines(),
                                         grd.GetRcHeaderFormat())
        self.assertEqual(('#define IDR_LOGO 300\n'
                          '#define IDS_GREETING 10000\n'
                          '#define IDS_BONGO 10001\n'), ''.join(output))

        # Using a custom rc_header format string.
        grd.AssignRcHeaderFormat(
            '#define {textual_id} _Pragma("{textual_id}") {numeric_id}')
        output = rc_header.FormatDefines(grd,
                                         grd.ShouldOutputAllResourceDefines(),
                                         grd.GetRcHeaderFormat())
        self.assertEqual(
            ('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n'
             '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n'
             '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'),
            ''.join(output))
Exemplo n.º 3
0
  def testRcHeaderFormat(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=".">
        <release seq="3">
          <includes first_id="300" comment="bingo">
            <include type="gif" name="IDR_LOGO" file="images/logo.gif" />
          </includes>
          <messages first_id="10000">
            <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="IDS_BONGO">
              Bongo!
            </message>
          </messages>
        </release>
      </grit>'''), '.')

    # Using the default rc_header format string.
    output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
                                     grd.GetRcHeaderFormat())
    self.assertEqual(('#define IDR_LOGO 300\n'
                      '#define IDS_GREETING 10000\n'
                      '#define IDS_BONGO 10001\n'), ''.join(output))

    # Using a custom rc_header format string.
    grd.AssignRcHeaderFormat(
        '#define {textual_id} _Pragma("{textual_id}") {numeric_id}')
    output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
                                     grd.GetRcHeaderFormat())
    self.assertEqual(('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n'
                      '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n'
                      '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'),
                     ''.join(output))
Exemplo n.º 4
0
 def testPredeterminedIdsOverlap(self):
     predetermined_ids_file = self._MakeTempPredeterminedIdsFile(
         'ID_LOGO 10000\n')
     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=".">
     <release seq="3">
       <includes first_id="300" comment="bingo">
         <include type="gif" name="ID_LOGO" file="images/logo.gif" />
       </includes>
       <messages first_id="10000">
         <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="IDS_BONGO">
           Bongo!
         </message>
       </messages>
     </release>
   </grit>'''),
         '.',
         predetermined_ids_file=predetermined_ids_file)
     output = rc_header.FormatDefines(grd,
                                      grd.ShouldOutputAllResourceDefines(),
                                      grd.GetRcHeaderFormat())
     self.assertRaises(exception.IdRangeOverlap, self.FormatAll, grd)
Exemplo n.º 5
0
 def testPredeterminedIds(self):
   with _MakeTempPredeterminedIdsFile('IDS_A 101\nIDS_B 102') as ids_file:
     grd = util.ParseGrdForUnittest('''
         <includes first_id="300" comment="bingo">
           <include type="gif" name="IDS_B" file="images/logo.gif" />
         </includes>
         <messages first_id="10000">
           <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="IDS_A">
             Bongo!
           </message>
         </messages>''', predetermined_ids_file=ids_file)
     output = rc_header.FormatDefines(grd, grd.GetRcHeaderFormat())
     self.assertEqual(('#define IDS_B 102\n'
                       '#define IDS_GREETING 10000\n'
                       '#define IDS_A 101\n'), ''.join(output))
Exemplo n.º 6
0
    def Process(self, grd, dialog_ids):
        '''Outputs an RC file and header file for the dialog 'dialog_id' stored in
    resource tree 'grd', to self.base_folder, as discussed in this class's
    documentation.

    Arguments:
      grd: grd = grd_reader.Parse(...); grd.RunGatherers()
      dialog_ids: ['IDD_MYDIALOG', 'IDD_OTHERDIALOG']
    '''
        grd.SetOutputLanguage(self.lang)
        grd.SetDefines(self.defines)

        project_name = dialog_ids[0]

        dir_path = os.path.join(self.base_folder, project_name)
        if not os.path.isdir(dir_path):
            os.mkdir(dir_path)

        # If this fails then we're not on Windows (or you don't have the required
        # win32all Python libraries installed), so what are you doing mucking
        # about with RC files anyway? :)
        import pythoncom

        # Create the .vcproj file
        project_text = PROJECT_TEMPLATE.replace(
            '[[PROJECT_GUID]]',
            str(pythoncom.CreateGuid())).replace('[[DIALOG_NAME]]',
                                                 project_name)
        fname = os.path.join(dir_path, '%s.vcproj' % project_name)
        self.WriteFile(fname, project_text)
        print("Wrote %s" % fname)

        # Create the .rc file
        # Output all <include> nodes since the dialogs might depend on them (e.g.
        # for icons and bitmaps).
        include_items = []
        for node in grd.ActiveDescendants():
            if isinstance(node, include.IncludeNode):
                include_items.append(rc.FormatInclude(node, self.lang, '.'))
        rc_text = RC_TEMPLATE.replace('[[CODEPAGE_NUM]]',
                                      str(self.codepage_number))
        rc_text = rc_text.replace('[[INCLUDES]]', ''.join(include_items))

        # Then output the dialogs we have been asked to output.
        dialogs = []
        for dialog_id in dialog_ids:
            node = grd.GetNodeById(dialog_id)
            assert node.name == 'structure' and node.attrs['type'] == 'dialog'
            # TODO(joi) Add exception handling for better error reporting
            dialogs.append(rc.FormatStructure(node, self.lang, '.'))
        rc_text = rc_text.replace('[[DIALOGS]]', ''.join(dialogs))

        fname = os.path.join(dir_path, '%s.rc' % project_name)
        self.WriteFile(fname, rc_text, self.GetEncoding())
        print("Wrote %s" % fname)

        # Create the resource.h file
        header_defines = ''.join(rc_header.FormatDefines(grd))
        header_text = HEADER_TEMPLATE.replace('[[DEFINES]]', header_defines)
        fname = os.path.join(dir_path, 'resource.h')
        self.WriteFile(fname, header_text)
        print("Wrote %s" % fname)
 def FormatAll(self, grd):
   output = rc_header.FormatDefines(grd)
   return ''.join(output).replace(' ', '')
Exemplo n.º 8
0
 def FormatAll(self, grd):
     output = rc_header.FormatDefines(grd,
                                      grd.ShouldOutputAllResourceDefines())
     return ''.join(output).replace(' ', '')