コード例 #1
0
ファイル: connect.cs プロジェクト: Xenioz/qt-labs-vstools
        private void AutoTestCase5()
        {
            foreach (String extension in extensions)
            {
                foreach (string mocDirectory in mocDirectories)
                {
                    bool success = true;
                    Exception currentException = null;
                    try
                    {
                        logger.WriteLine(DateTime.Now.ToString()
                            + ": Case5 (Change Preprocessor Definitions) begins");
                        logger.WriteLine("\textension: " + extension);
                        logger.WriteLine("\tmoc directory: " + mocDirectory);

                        String solutionRootDir = BackupSolution(testPath + templatePath, "Test2" + extension);
                        _applicationObject.Solution.Open(solutionRootDir + "Test2" + extension + ".sln");
                        Solution solution = _applicationObject.Solution;
                        if (solution == null)
                            throw new Exception(DateTime.Now.ToString() + ": Case5: Could not open solution");

                        Project project = GetProject("Test2", solution);
                        SetProjectDirectory(project, ProjectDirectory.MocDir, mocDirectory);
                        VCProject vcProject = (VCProject)project.Object;
                        foreach (VCConfiguration proConfig in (IVCCollection)vcProject.Configurations)
                        {
                            string define = proConfig.Name.Remove(proConfig.Name.IndexOf('|'));
                            CompilerToolWrapper compiler = new CompilerToolWrapper(proConfig);
                            compiler.AddPreprocessorDefinitions(define);
                        }

                        vcProject.Save();

                        currentException = RebuildSolution();
                        if (currentException != null)
                        {
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case5: " + currentException.Message);
                            success = false;
                        }
                        else
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case5: Build process succeeded");

                        if (success)
                        {
                            foreach (VCFile file in (IVCCollection)vcProject.Files)
                            {
                                if (file.Name == "foo.h")
                                {
                                    IVCCollection fileConfigs = (IVCCollection)file.FileConfigurations;
                                    foreach (VCFileConfiguration fileConfig in fileConfigs)
                                    {
                                        string define = fileConfig.Name.Remove(fileConfig.Name.IndexOf('|'));
                                        VCCustomBuildTool buildTool = (VCCustomBuildTool)fileConfig.Tool;
                                        if (buildTool != null)
                                        {
                                            if (!buildTool.CommandLine.Contains(define))
                                            {
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case5: Preprocessor definition was not "
                                                    + "added to the custom build step (" + fileConfig.Name + ")");
                                                success = false;
                                            }
                                            else
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case5: Preprocessor definition was "
                                                    + "added to the custom build step (" + fileConfig.Name + ")");
                                        }
                                        else
                                            success = false;
                                    }
                                }
                            }

                            if (!success)
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case5: Preprocessor definition was not "
                                    + "added to all custom build steps");
                            }
                            else
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case5: Preprocessor definition was "
                                    + "added to all custom build steps");

                            }
                        }
                    }
                    catch (Exception e)
                    {
                        success = false;
                        logger.WriteLine(e.Message);
                    }
                    if (success)
                        logger.WriteLine(DateTime.Now.ToString() + ": Case5 succeeded");
                    else
                        logger.WriteLine(DateTime.Now.ToString() + ": Case5 failed");
                    logger.WriteLine("");
                }
            }
        }
コード例 #2
0
ファイル: connect.cs プロジェクト: Xenioz/qt-labs-vstools
        private void AutoTestCase6()
        {
            foreach (String extension in extensions)
            {
                foreach (string mocDirectory in mocDirectories)
                {
                    bool success = true;
                    Exception currentException = null;
                    try
                    {
                        logger.WriteLine(DateTime.Now.ToString()
                            + ": Case6 (Change Additional Include Directories) begins");
                        logger.WriteLine("\textension: " + extension);
                        logger.WriteLine("\tmoc directory: " + mocDirectory);

                        String solutionRootDir = BackupSolution(testPath + templatePath, "Test2" + extension);
                        _applicationObject.Solution.Open(solutionRootDir + "Test2" + extension + ".sln");
                        Solution solution = _applicationObject.Solution;
                        if (solution == null)
                            throw new Exception(DateTime.Now.ToString() + ": Case6: "
                                + currentException.Message);

                        Project project = GetProject("Test2", solution);
                        SetProjectDirectory(project, ProjectDirectory.MocDir, mocDirectory);
                        VCProject vcProject = (VCProject)project.Object;

                        foreach (VCConfiguration config in (IVCCollection)vcProject.Configurations)
                        {
                            string include = config.Name.Remove(config.Name.IndexOf('|'));
                            CompilerToolWrapper compiler = new CompilerToolWrapper(config);
                            compiler.AddAdditionalIncludeDirectories(include);
                        }
                        vcProject.Save();

                        currentException = RebuildSolution();
                        if (currentException != null)
                        {
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: " + currentException.Message);
                            success = false;
                        }
                        else
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: Build process succeeded");

                        if (success)
                        {
                            foreach (VCFile file in (IVCCollection)vcProject.Files)
                            {
                                if (file.Name == "foo.h")
                                {
                                    foreach (VCFileConfiguration fileConfig in (IVCCollection)file.FileConfigurations)
                                    {
                                        string include = fileConfig.Name.Remove(fileConfig.Name.IndexOf('|'));
                                        VCCustomBuildTool buildTool = (VCCustomBuildTool)fileConfig.Tool;
                                        if (buildTool != null)
                                        {
                                            if (!buildTool.CommandLine.Contains("\"-I.\\" + include + "\""))
                                            {
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was not added to the custom build step (" + fileConfig.Name + ")");
                                                success = false;
                                            }
                                            else
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was added to the custom build step (" + fileConfig.Name + ")");
                                        }
                                    }
                                }
                            }

                            if (!success)
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was not "
                                    + "added to all custom build steps");
                            }
                            else
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was "
                                    + "added to all custom build steps");

                            }
                        }
                    }
                    catch (Exception e)
                    {
                        success = false;
                        logger.WriteLine(e.Message);
                    }
                    if (!success)
                    {
                        logger.WriteLine(DateTime.Now.ToString() + ": Case6 failed");
                        return;
                    }
                    try
                    {
                        string include = "$(SolutionDir)";
                        String solutionRootDir = BackupSolution(testPath + templatePath, "Test2" + extension);
                        _applicationObject.Solution.Open(solutionRootDir + "Test2" + extension + ".sln");
                        Solution solution = _applicationObject.Solution;
                        if (solution == null)
                            throw new Exception(DateTime.Now.ToString() + ": Case6: "
                                + currentException.Message);

                        Project project = GetProject("Test2", solution);
                        SetProjectDirectory(project, ProjectDirectory.MocDir, mocDirectory);
                        VCProject vcProject = (VCProject)project.Object;

                        foreach (VCConfiguration config in (IVCCollection)vcProject.Configurations)
                        {
                            CompilerToolWrapper compiler = new CompilerToolWrapper(config);
                            compiler.AddAdditionalIncludeDirectories(include);
                        }
                        vcProject.Save();

                        currentException = RebuildSolution();
                        if (currentException != null)
                        {
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: " + currentException.Message);
                            success = false;
                        }
                        else
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: Build process succeeded");

                        if (success)
                        {
                            foreach (VCFile file in (IVCCollection)vcProject.Files)
                            {
                                if (file.Name == "foo.h")
                                {
                                    foreach (VCFileConfiguration fileConfig in (IVCCollection)file.FileConfigurations)
                                    {
                                        VCCustomBuildTool buildTool = (VCCustomBuildTool)fileConfig.Tool;
                                        if (buildTool != null)
                                        {
                                            if (!buildTool.CommandLine.Contains("\"-I" + include + "\\.\""))
                                            {
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was not added to the custom build step (" + fileConfig.Name + ")");
                                                success = false;
                                            }
                                            else
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was added to the custom build step (" + fileConfig.Name + ")");
                                        }
                                    }
                                }
                            }

                            if (!success)
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was not "
                                    + "added to all custom build steps");
                            }
                            else
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was "
                                    + "added to all custom build steps");

                            }
                        }
                    }
                    catch (Exception e)
                    {
                        success = false;
                        logger.WriteLine(e.Message);
                    }
                    if (!success)
                    {
                        logger.WriteLine(DateTime.Now.ToString() + ": Case6 failed");
                        return;
                    }
                    try
                    {
                        string include = "C:\\FOO\\";
                        String solutionRootDir = BackupSolution(testPath + templatePath, "Test2" + extension);
                        _applicationObject.Solution.Open(solutionRootDir + "Test2" + extension + ".sln");
                        Solution solution = _applicationObject.Solution;
                        if (solution == null)
                            throw new Exception(DateTime.Now.ToString() + ": Case6: "
                                + currentException.Message);

                        Project project = GetProject("Test2", solution);
                        SetProjectDirectory(project, ProjectDirectory.MocDir, mocDirectory);
                        VCProject vcProject = (VCProject)project.Object;

                        foreach (VCConfiguration config in (IVCCollection)vcProject.Configurations)
                        {
                            CompilerToolWrapper compiler = new CompilerToolWrapper(config);
                            compiler.AddAdditionalIncludeDirectories(include);
                        }
                        vcProject.Save();

                        currentException = RebuildSolution();
                        if (currentException != null)
                        {
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: " + currentException.Message);
                            success = false;
                        }
                        else
                            logger.WriteLine(DateTime.Now.ToString()
                                + ": Case6: Build process succeeded");

                        if (success)
                        {
                            foreach (VCFile file in (IVCCollection)vcProject.Files)
                            {
                                if (file.Name == "foo.h")
                                {
                                    foreach (VCFileConfiguration fileConfig in (IVCCollection)file.FileConfigurations)
                                    {
                                        VCCustomBuildTool buildTool = (VCCustomBuildTool)fileConfig.Tool;
                                        if (buildTool != null)
                                        {
                                            if (!buildTool.CommandLine.Contains("\"-IC:\\FOO\""))
                                            {
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was not added to the custom build step (" + fileConfig.Name + ")");
                                                success = false;
                                            }
                                            else
                                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib "
                                                    + include + " was added to the custom build step (" + fileConfig.Name + ")");
                                        }
                                    }
                                }
                            }

                            if (!success)
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was not "
                                    + "added to all custom build steps");
                            }
                            else
                            {
                                logger.WriteLine(DateTime.Now.ToString() + ": Case6: Additional include lib was "
                                    + "added to all custom build steps");

                            }
                        }
                    }
                    catch (Exception e)
                    {
                        success = false;
                        logger.WriteLine(e.Message);
                    }
                    if (success)
                        logger.WriteLine(DateTime.Now.ToString() + ": Case6 succeeded");
                    else
                        logger.WriteLine(DateTime.Now.ToString() + ": Case6 failed");
                    logger.WriteLine("");
                }
            }
        }
コード例 #3
0
ファイル: connect.cs プロジェクト: Xenioz/qt-labs-vstools
        private void AutoTestCase9()
        {
            bool success = true;
            Exception currentException = null;
            try
            {
                logger.WriteLine(DateTime.Now.ToString()
                    + ": Case9 (Handling of precompiled headers) begins");
                logger.WriteLine(DateTime.Now.ToString()
                    + ": Case9: Adding precompiled header data");

                String solutionRootDir = BackupSolution(testPath + templatePath, "Test2");
                _applicationObject.Solution.Open(solutionRootDir + "Test2.sln");
                Solution solution = _applicationObject.Solution;
                if (solution == null)
                    throw new Exception(DateTime.Now.ToString() + ": Case9: "
                        + currentException.Message);

                Project project = GetProject("Test2", solution);
                VCProject vcProject = (VCProject)project.Object;

                foreach (VCConfiguration vcConfig in vcProject.Configurations as IVCCollection)
                {
                    CompilerToolWrapper wrapper = new CompilerToolWrapper(vcConfig);
                    if (wrapper == null)
                        continue;

                    wrapper.SetUsePrecompiledHeader(pchOption.pchUseUsingSpecific);
                    wrapper.SetPrecompiledHeaderFile("test.pch");
                    wrapper.SetPrecompiledHeaderThrough("test.h");
                }
                VCFilter filter = null;
                foreach (VCFilter tmpFilter in vcProject.Filters as IVCCollection)
                {
                    if (tmpFilter.Name == "Source Files")
                    {
                        filter = tmpFilter;
                    }
                }
                if (filter == null)
                {
                    success = false;
                    throw new Exception("Could not find \"Source Files\" filter");
                }
                foreach (VCFile file in (IVCCollection)filter.Files)
                {
                    if (file.Name.EndsWith(".cpp"))
                    {
                        IVCCollection fileConfigs = (IVCCollection)file.FileConfigurations;
                        foreach (VCFileConfiguration fileConfig in fileConfigs)
                        {
                            CompilerToolWrapper wrapper = new CompilerToolWrapper(fileConfig);
                            if (wrapper == null)
                                continue;

                            wrapper.SetPrecompiledHeaderFile("test.pch");
                            wrapper.SetPrecompiledHeaderThrough("test.h");
                            if (file.Name == "test.cpp")
                                wrapper.SetUsePrecompiledHeader(pchOption.pchCreateUsingSpecific);
                            else
                                wrapper.SetUsePrecompiledHeader(pchOption.pchUseUsingSpecific);
                        }
                    }
                }
                ProjectItem piSource = project.ProjectItems.Item("Source Files");
                foreach (ProjectItem item in piSource.ProjectItems)
                {
                    if (ProjectItemContainsString(item, "//#include \"test.h\""))
                    {
                        currentException = ReplaceStringInProjectItem(item, "//#include \"test.h\"", "#include \"test.h\"");
                    }
                }
                vcProject.Save();
                currentException = RebuildSolution();
                if (currentException != null)
                {
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: " + currentException.Message);
                    success = false;
                }
                else
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: Build process succeeded");

                logger.WriteLine(DateTime.Now.ToString()
                    + ": Case9: Changing precompiled header data");

                solutionRootDir = BackupSolution(testPath + templatePath, "Test4");
                _applicationObject.Solution.Open(solutionRootDir + "Test4.sln");
                solution = _applicationObject.Solution;
                if (solution == null)
                    throw new Exception(DateTime.Now.ToString() + ": Case9: "
                        + currentException.Message);

                project = GetProject("Test4", solution);
                vcProject = (VCProject)project.Object;

                foreach (VCConfiguration vcConfig in vcProject.Configurations as IVCCollection)
                {
                    CompilerToolWrapper wrapper = new CompilerToolWrapper(vcConfig);
                    if (wrapper == null)
                        continue;

                    wrapper.SetUsePrecompiledHeader(pchOption.pchUseUsingSpecific);
                    wrapper.SetPrecompiledHeaderFile("stdafx.pch");
                    wrapper.SetPrecompiledHeaderThrough("stdafx.h");
                }
                filter = null;
                foreach (VCFilter tmpFilter in vcProject.Filters as IVCCollection)
                {
                    if (tmpFilter.Name == "Source Files")
                    {
                        filter = tmpFilter;
                    }
                }
                if (filter == null)
                {
                    success = false;
                    throw new Exception("Could not find \"Source Files\" filter");
                }
                foreach (VCFile file in (IVCCollection)filter.Files)
                {
                    if (file.Name.EndsWith(".cpp"))
                    {
                        IVCCollection fileConfigs = (IVCCollection)file.FileConfigurations;
                        foreach (VCFileConfiguration fileConfig in fileConfigs)
                        {
                            CompilerToolWrapper wrapper = new CompilerToolWrapper(fileConfig);
                            if (wrapper == null)
                                continue;

                            wrapper.SetPrecompiledHeaderFile("stdafx.pch");
                            wrapper.SetPrecompiledHeaderThrough("stdafx.h");
                            if (file.Name == "test.cpp")
                                wrapper.SetUsePrecompiledHeader(pchOption.pchCreateUsingSpecific);
                            else
                                wrapper.SetUsePrecompiledHeader(pchOption.pchUseUsingSpecific);
                        }
                    }
                }
                piSource = project.ProjectItems.Item("Source Files");
                foreach (ProjectItem item in piSource.ProjectItems)
                {
                    if (ProjectItemContainsString(item, "#include \"test.h\""))
                    {
                        currentException = ReplaceStringInProjectItem(item, "#include \"test.h\"", "#include \"stdafx.h\"");
                    }
                }
                vcProject.Save();
                currentException = RebuildSolution();
                if (currentException != null)
                {
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: " + currentException.Message);
                    success = false;
                }
                else
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: Build process succeeded");

                logger.WriteLine(DateTime.Now.ToString()
                    + ": Case9: Removing precompiled header data");

                solutionRootDir = BackupSolution(testPath + templatePath, "Test4");
                _applicationObject.Solution.Open(solutionRootDir + "Test4.sln");
                solution = _applicationObject.Solution;
                if (solution == null)
                    throw new Exception(DateTime.Now.ToString() + ": Case9: "
                        + currentException.Message);
                project = GetProject("Test4", solution);
                vcProject = (VCProject)project.Object;

                foreach (VCConfiguration vcConfig in vcProject.Configurations as IVCCollection)
                {
                    CompilerToolWrapper wrapper = new CompilerToolWrapper(vcConfig);
                    if (wrapper == null)
                        continue;

                    wrapper.SetUsePrecompiledHeader(pchOption.pchNone);
                    wrapper.SetPrecompiledHeaderFile("");
                    wrapper.SetPrecompiledHeaderThrough("");
                }
                foreach (VCFile file in (IVCCollection)vcProject.Files)
                {
                    if (file.Name.EndsWith(".cpp"))
                    {
                        IVCCollection fileConfigs = (IVCCollection)file.FileConfigurations;
                        foreach (VCFileConfiguration fileConfig in fileConfigs)
                        {
                            CompilerToolWrapper wrapper = new CompilerToolWrapper(fileConfig);
                            if (wrapper == null)
                                continue;

                            wrapper.SetPrecompiledHeaderFile("");
                            wrapper.SetPrecompiledHeaderThrough("");
                            wrapper.SetUsePrecompiledHeader(pchOption.pchNone);
                        }
                    }
                }
                piSource = project.ProjectItems.Item("Source Files");
                foreach (ProjectItem item in piSource.ProjectItems)
                {
                    if (ProjectItemContainsString(item, "#include \"test.h\""))
                    {
                        currentException = ReplaceStringInProjectItem(item, "#include \"test.h\"", "//#include \"test.h\"");
                    }
                }
                ProjectItem piHeader = project.ProjectItems.Item("Header Files");
                ProjectItems headerItems = piHeader.ProjectItems;
                for (int i = headerItems.Count; i > 0; i--)
                {
                    ProjectItem item = headerItems.Item(i);
                    if (item.Name == "test.h")
                    {
                        item.Delete();
                    }
                }
                vcProject.Save();
                currentException = RebuildSolution();
                if (currentException != null)
                {
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: " + currentException.Message);
                    success = false;
                }
                else
                    logger.WriteLine(DateTime.Now.ToString()
                        + ": Case9: Build process succeeded");
            }
            catch (Exception e)
            {
                success = false;
                logger.WriteLine(e.Message);
            }
            if (success)
                logger.WriteLine(DateTime.Now.ToString() + ": Case9 succeeded");
            else
                logger.WriteLine(DateTime.Now.ToString() + ": Case9 failed");
            logger.WriteLine("");
        }