Ejemplo n.º 1
0
    def _GetProjectFileWriter(self, output_version):
        """Retrieves a Visual Studio project file writer.

    Args:
      output_version (str): output version of the Visual Studio solution.

    Returns:
      VSProjectFileWriter: Visual Studio project file writer or None if version
          is not supported.
    """
        if output_version == '2008':
            return writers.VS2008ProjectFileWriter()
        if output_version == '2010':
            return writers.VS2010ProjectFileWriter()
        if output_version == '2012':
            return writers.VS2012ProjectFileWriter()
        if output_version == '2013':
            return writers.VS2013ProjectFileWriter()
        if output_version == '2015':
            return writers.VS2015ProjectFileWriter()
        if output_version == '2017':
            return writers.VS2017ProjectFileWriter()
        if output_version == '2019':
            return writers.VS2019ProjectFileWriter()

        return None
Ejemplo n.º 2
0
  def testWriteSourceFiles(self):
    """Tests the _WriteSourceFiles function."""
    source_files = ['test.c']

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteSourceFiles(source_files)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t<Filter\r\n'
        b'\t\t\tName="Source Files"\r\n'
        b'\t\t\tFilter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r\n'
        b'\t\t\tUniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r\n'
        b'\t\t\t>\r\n'
        b'\t\t\t<File\r\n'
        b'\t\t\t\tRelativePath="test.c"\r\n'
        b'\t\t\t\t>\r\n'
        b'\t\t\t</File>\r\n'
        b'\t\t</Filter>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 3
0
  def testWriteProjectInformation(self):
    """Tests the WriteProjectInformation function."""
    project_information = resources.VSProjectInformation()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteProjectInformation(project_information)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'<VisualStudioProject\r\n'
        b'\tProjectType="Visual C++"\r\n'
        b'\tVersion="9,00"\r\n'
        b'\tName=""\r\n'
        b'\tProjectGUID="{}"\r\n'
        b'\tRootNamespace=""\r\n'
        b'\tTargetFrameworkVersion="131072"\r\n'
        b'\t>\r\n'
        b'\t<Platforms>\r\n'
        b'\t\t<Platform\r\n'
        b'\t\t\tName="Win32"\r\n'
        b'\t\t/>\r\n'
        b'\t</Platforms>\r\n'
        b'\t<ToolFiles>\r\n'
        b'\t</ToolFiles>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 4
0
  def testWriteResourceFiles(self):
    """Tests the _WriteResourceFiles function."""
    resource_files = ['test.rc']

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteResourceFiles(resource_files)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t<Filter\r\n'
        b'\t\t\tName="Resource Files"\r\n'
        b'\t\t\tFilter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;'
        b'resx;tiff;tif;png;wav"\r\n'
        b'\t\t\tUniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r\n'
        b'\t\t\t>\r\n'
        b'\t\t\t<File\r\n'
        b'\t\t\t\tRelativePath="test.rc"\r\n'
        b'\t\t\t\t>\r\n'
        b'\t\t\t</File>\r\n'
        b'\t\t</Filter>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 5
0
  def testWriteHeaderFiles(self):
    """Tests the _WriteHeaderFiles function."""
    header_files = ['test.h']

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteHeaderFiles(header_files)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t<Filter\r\n'
        b'\t\t\tName="Header Files"\r\n'
        b'\t\t\tFilter="h;hpp;hxx;hm;inl;inc;xsd"\r\n'
        b'\t\t\tUniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r\n'
        b'\t\t\t>\r\n'
        b'\t\t\t<File\r\n'
        b'\t\t\t\tRelativePath="test.h"\r\n'
        b'\t\t\t\t>\r\n'
        b'\t\t\t</File>\r\n'
        b'\t\t</Filter>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 6
0
  def testWriteConfigurationTool(self):
    """Tests the _WriteConfigurationTool function."""
    project_configuration = resources.VSProjectConfiguration()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteConfigurationTool(
        project_configuration, 'VCCLCompilerTool',
        file_writer._TOOL_COMPILER_CONFIGURATION_OPTIONS)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t\t<Tool\r\n'
        b'\t\t\t\tName="VCCLCompilerTool"\r\n'
        b'\t\t\t\tAdditionalIncludeDirectories=""\r\n'
        b'\t\t\t\tPreprocessorDefinitions=""\r\n'
        b'\t\t\t\tRuntimeLibrary=""\r\n'
        b'\t\t\t\tWarningLevel=""\r\n'
        b'\t\t\t\tCompileAs=""\r\n'
        b'\t\t\t/>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 7
0
  def testWriteFooter(self):
    """Tests the WriteFooter function."""
    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteFooter()

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = b'</VisualStudioProject>\r\n'
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 8
0
  def testWriteHeader(self):
    """Tests the WriteHeader function."""
    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteHeader()

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = b'<?xml version="1.0" encoding="Windows-1252"?>\r\n'
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 9
0
  def testWriteProjectConfigurations(self):
    """Tests the WriteProjectConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteProjectConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertEqual(output_data, b'')
Ejemplo n.º 10
0
  def testWriteConfiguration(self):
    """Tests the _WriteConfiguration function."""
    project_configuration = resources.VSProjectConfiguration()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteConfiguration(project_configuration)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertTrue(output_data.startswith(b'\t\t<Configuration\r\n'))
    self.assertTrue(output_data.endswith(b'\t\t</Configuration>\r\n'))
Ejemplo n.º 11
0
  def testWriteDependencies(self):
    """Tests the WriteDependencies function."""
    dependencies = []
    solution_projects_by_guid = {}

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteDependencies(dependencies, solution_projects_by_guid)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertEqual(output_data, b'')
Ejemplo n.º 12
0
  def testWriteConfigurationToolFooter(self):
    """Tests the _WriteConfigurationToolFooter function."""
    project_configuration = resources.VSProjectConfiguration()
    project_configuration.compile_as = '1'

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteConfigurationToolFooter()

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = b'\t\t\t/>\r\n'
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 13
0
  def testWriteConfigurations(self):
    """Tests the WriteConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertTrue(output_data.startswith(b'\t<Configurations>\r\n'))
    self.assertTrue(output_data.endswith(
        b'\t</Configurations>\r\n'
        b'\t<References>\r\n'
        b'\t</References>\r\n'))
Ejemplo n.º 14
0
  def testWriteConfigurationToolHeader(self):
    """Tests the _WriteConfigurationToolHeader function."""
    project_configuration = resources.VSProjectConfiguration()
    project_configuration.compile_as = '1'

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteConfigurationToolHeader('VCLinkerTool')

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t\t<Tool\r\n'
        b'\t\t\t\tName="VCLinkerTool"\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 15
0
  def testWriteConfigurationLinkerTool(self):
    """Tests the _WriteConfigurationLinkerTool function."""
    project_configuration = resources.VSProjectConfiguration()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteConfigurationLinkerTool(project_configuration)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'\t\t\t<Tool\r\n'
        b'\t\t\t\tName="VCLinkerTool"\r\n'
        b'\t\t\t\tAdditionalLibraryDirectories="&quot;$(OutDir)&quot;"\r\n'
        b'\t\t\t/>\r\n')
    self.assertEqual(output_data, expected_output_data)
Ejemplo n.º 16
0
  def testWriteFiles(self):
    """Tests the WriteFiles function."""
    header_files = ['test.h']
    resource_files = ['test.rc']
    source_files = ['test.c']

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteFiles(source_files, header_files, resource_files)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertTrue(output_data.startswith(b'\t<Files>\r\n'))
    self.assertTrue(output_data.endswith(
        b'\t</Files>\r\n'
        b'\t<Globals>\r\n'
        b'\t</Globals>\r\n'))