Пример #1
0
        internal void PopulateWithHeader(HierarchyItem headerUnderTest)
        {
            functionsTree.Nodes.Clear();

            ProjectItem     projectItem = headerUnderTest.GetExtObjectAs <ProjectItem>();
            VCFileCodeModel codeModel   = projectItem.FileCodeModel as VCFileCodeModel;

            PopulateRecursively(functionsTree.Nodes, codeModel.CodeElements);

            functionsTree.ExpandAll();
        }
        // ------------------------------------------------------
        /// <summary>
        /// Gets the path to the executable file generated by the active
        /// configuration of the specified project.
        /// </summary>
        /// <param name="projectHier">
        /// The project to get the executable file for.
        /// </param>
        /// <returns>
        /// The full path to the executable generated by the active
        /// configuration for this project.
        /// </returns>
        private string GetActiveExecutablePath(HierarchyItem projectHier)
        {
            Project       project      = projectHier.GetExtObjectAs <Project>();
            Configuration activeConfig =
                project.ConfigurationManager.ActiveConfiguration;

            string outputPath =
                activeConfig.Properties.Item("OutputPath").Value as string;
            string outputName = ((object[])activeConfig.OutputGroups.Item(
                                     "Built").FileNames)[0] as string;

            return(Path.Combine(outputPath, outputName));
        }
        // ------------------------------------------------------
        /// <summary>
        /// Creates the test runner source file for the current startup
        /// project and adds it to the project.
        /// </summary>
        /// <param name="doNotRunTests">
        /// If true, the file will be generated but will not include any
        /// statements to run any tests. If false, the tests will be run
        /// based on the current selection in the CxxTest Suites view.
        /// </param>
        public void CreateTestRunnerFile(bool doNotRunTests)
        {
            TestSuiteCollection suites = AllTestSuites;

            Dictionary <string, bool> testsToRun;

            if (doNotRunTests)
            {
                testsToRun = null;
            }
            else
            {
                testsToRun = TryToGetTestsToRun();
            }

            HierarchyItem startupProject =
                VsShellUtils.GetStartupProject(this);

            string projectDir = startupProject.ProjectDirectory;
            string workingDir = GetActiveWorkingDirectory(startupProject);

            Project project = startupProject.GetExtObjectAs <Project>();

            string runnerPath = Path.Combine(
                projectDir, Constants.TestRunnerFilename);

            // Remove the file from the project if necessary, and delete it
            // from the file system if it exists.
            VCProject vcproj = (VCProject)project.Object;

            if (!vcproj.CanAddFile(runnerPath))
            {
                IVCCollection coll = (IVCCollection)vcproj.Files;
                vcproj.RemoveFile(coll.Item(Constants.TestRunnerFilename));
            }

            if (File.Exists(runnerPath))
            {
                File.Delete(runnerPath);
            }

            TestRunnerGenerator generator =
                new TestRunnerGenerator(runnerPath, suites, testsToRun);

            generator.Generate();

            // Add the file to the project.

            vcproj.AddFile(runnerPath);
        }
        // ------------------------------------------------------
        /// <summary>
        /// Gets the path to the working directory used by the active
        /// configuration of the specified project.
        /// </summary>
        /// <param name="projectHier">
        /// The project to get the working directory for.
        /// </param>
        /// <returns>
        /// The full path to the working directory used by the active
        /// configuration for this project.
        /// </returns>
        private string GetActiveWorkingDirectory(HierarchyItem projectHier)
        {
            Project       project      = projectHier.GetExtObjectAs <Project>();
            Configuration activeConfig =
                project.ConfigurationManager.ActiveConfiguration;

            Property workingDirProp =
                activeConfig.Properties.Item("WorkingDirectory");
            string workingDir = workingDirProp.Value as string;

            if (string.IsNullOrEmpty(workingDir))
            {
                workingDir = projectHier.ProjectDirectory;
            }

            return(workingDir);
        }
        internal void PopulateWithHeader(HierarchyItem headerUnderTest)
        {
            functionsTree.Nodes.Clear();

            ProjectItem projectItem = headerUnderTest.GetExtObjectAs<ProjectItem>();
            VCFileCodeModel codeModel = projectItem.FileCodeModel as VCFileCodeModel;

            PopulateRecursively(functionsTree.Nodes, codeModel.CodeElements);

            functionsTree.ExpandAll();
        }
        // ------------------------------------------------------
        /// <summary>
        /// Gets the path to the working directory used by the active
        /// configuration of the specified project.
        /// </summary>
        /// <param name="projectHier">
        /// The project to get the working directory for.
        /// </param>
        /// <returns>
        /// The full path to the working directory used by the active
        /// configuration for this project.
        /// </returns>
        private string GetActiveWorkingDirectory(HierarchyItem projectHier)
        {
            Project project = projectHier.GetExtObjectAs<Project>();
            Configuration activeConfig =
                project.ConfigurationManager.ActiveConfiguration;

            Property workingDirProp =
                activeConfig.Properties.Item("WorkingDirectory");
            string workingDir = workingDirProp.Value as string;

            if (string.IsNullOrEmpty(workingDir))
                workingDir = projectHier.ProjectDirectory;

            return workingDir;
        }
        // ------------------------------------------------------
        /// <summary>
        /// Gets the path to the executable file generated by the active
        /// configuration of the specified project.
        /// </summary>
        /// <param name="projectHier">
        /// The project to get the executable file for.
        /// </param>
        /// <returns>
        /// The full path to the executable generated by the active
        /// configuration for this project.
        /// </returns>
        private string GetActiveExecutablePath(HierarchyItem projectHier)
        {
            Project project = projectHier.GetExtObjectAs<Project>();
            Configuration activeConfig =
                project.ConfigurationManager.ActiveConfiguration;

            string outputPath =
                activeConfig.Properties.Item("OutputPath").Value as string;
            string outputName = ((object[]) activeConfig.OutputGroups.Item(
                "Built").FileNames)[0] as string;

            return Path.Combine(outputPath, outputName);
        }