Example #1
0
        private void Setup(String[] args)
        {
            m_commandLine = new IDLToCLSCommandLine(args);
            if (m_commandLine.IsHelpRequested)
            {
                HowTo();
                Environment.Exit(0);
            }

            if (m_commandLine.IsInvalid)
            {
                Error(m_commandLine.ErrorMessage);
            }

            // create output directory
            if (!Directory.Exists(m_commandLine.OutputDirectory.FullName))
            {
                Directory.CreateDirectory(m_commandLine.OutputDirectory.FullName);
            }

            // process include dirs
            for (int i = 0; i < m_commandLine.IdlSourceDirectories.Count; i++)
            {
                IDLPreprocessor.SetIdlDir((DirectoryInfo)m_commandLine.IdlSourceDirectories[i]);
            }

            if (m_commandLine.BaseDirectory != null)
            {
                Environment.CurrentDirectory = m_commandLine.BaseDirectory.FullName;
            }

            // preprocessor defines
            for (int i = 0; i < m_commandLine.PreprocessorDefines.Count; i++)
            {
                IDLPreprocessor.AddDefine((string)m_commandLine.PreprocessorDefines[i]);
            }

            // vt-skeleton generation setup
            if (m_commandLine.GenerateValueTypeSkeletons &&
                m_commandLine.ValueTypeSkeletonCodeDomProviderType != null)
            {
                m_vtSkelcodeDomProvider =
                    (CodeDomProvider)Activator.CreateInstance(
                        m_commandLine.ValueTypeSkeletonCodeDomProviderType);
            }

            SetupAssemblyResolver();
            AddCustomMappings(m_commandLine.CustomMappingFiles);
        }
Example #2
0
 private static void HowTo()
 {
     IDLToCLSCommandLine.HowTo(Console.Out);
 }
        public void TestIdlSourceDirectories()
        {
            DirectoryInfo dir1 = new DirectoryInfo(".");
            DirectoryInfo dir2 = new DirectoryInfo(Path.Combine(".", "testIdlDir"));

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-idir", dir1.FullName, "-idir", dir2.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(2,
                                   commandLine.IdlSourceDirectories.Count, "idl source dirs");
            Assert.AreEqual(dir1.FullName,
                                   ((DirectoryInfo)commandLine.IdlSourceDirectories[0]).FullName, 
                                   "idl source dir 1");
            Assert.AreEqual(dir2.FullName,
                                   ((DirectoryInfo)commandLine.IdlSourceDirectories[1]).FullName,
                                   "idl source dir 2");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
 public void TestVtGenerationProvider()
 {
     Type provider = typeof(Microsoft.CSharp.CSharpCodeProvider);
     string providerName = provider.AssemblyQualifiedName;
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "-vtSkelProv", providerName, "testAsm", "test.idl" });
     Assert.IsTrue(!commandLine.IsInvalid, "Command Line Validity");
     Assert.AreEqual(provider, commandLine.ValueTypeSkeletonCodeDomProviderType, "Valuetype Skeletons Generation Provider");
 }
        public void TestVtSkelOverwrite()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-vtSkelO", "testAsm", "test.idl" });
            Assert.IsTrue(commandLine.OverwriteValueTypeSkeletons, "Value Type Skeleton overwrite");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
 public void TestBaseInterfaceNonExisting()
 {
     string baseInterfaceName = "System.IDisposableNonExisting";
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "-b", baseInterfaceName, "testAsm", "test.idl" });
     Assert.IsTrue(commandLine.IsInvalid, "Invalid base interface");
     Assert.AreEqual(string.Format("Error: base interface {0} does not exist!", baseInterfaceName),
                            commandLine.ErrorMessage, "invalid arguments message");
 }
 public void TestBaseDirectoryNonExisting()
 {
     DirectoryInfo testDir = new DirectoryInfo(Path.Combine(".", "NonExistantBaseDir"));
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "-basedir", testDir.FullName, "testAsm", "test.idl" });
     Assert.IsTrue(commandLine.IsInvalid, "Invalid Base directory");
     Assert.AreEqual(string.Format("Error: base directory {0} does not exist!", testDir.FullName),
                            commandLine.ErrorMessage, "invalid arguments message");
 }
        public void TestMapToAnyContainer()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-mapAnyToCont", "testAsm", "test.idl" });
            Assert.IsTrue(commandLine.MapAnyToAnyContainer, "Map any to any container");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
 public void TestMissingIdlFileName()
 {
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "testAsm" });
     Assert.IsTrue(commandLine.IsInvalid, "Invalid commandLine detection");
     Assert.AreEqual("Error: idl-file(s) missing",
                            commandLine.ErrorMessage, "invalid commandLine message");
 }
 public void TestMissingTargetAssemblyName()
 {
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[0]);
     Assert.IsTrue(commandLine.IsInvalid, "Invalid commandLine detection");
     Assert.AreEqual("Error: target assembly name missing",
                            commandLine.ErrorMessage, "invalid commandLine message");
 }
 public void TestWrongArgument()
 {
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "-InvalidArg" });
     Assert.IsTrue(commandLine.IsInvalid, "Invalid Arg detection");
     Assert.AreEqual("Error: invalid option -InvalidArg",
                            commandLine.ErrorMessage, "invalid arguments message");
 }
        public void TestOutDirColonSeparator()
        {
            DirectoryInfo testDir = new DirectoryInfo(Path.Combine(".", "testOut"));
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-out:" + testDir.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(testDir.FullName,
                                   commandLine.OutputDirectory.FullName, "OutputDirectory");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestDefaultOutputDir()
        {
            DirectoryInfo testDir = new DirectoryInfo(".");
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "testAsm", "test.idl" });
            Assert.AreEqual(testDir.FullName,
                                   commandLine.OutputDirectory.FullName, "OutputDirectory");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestIdlFilesRecursivelyFromDirectory()
        {
            string tempPath = Path.Combine(Path.GetTempPath(), "IDLCommandLineRecursiveFileTest");
            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            string subDir1 = Path.Combine(tempPath, "subDir1");
            string subDir2 = Path.Combine(tempPath, "subDir2");

            try
            {
                Directory.CreateDirectory(tempPath);
                Directory.CreateDirectory(subDir1);
                Directory.CreateDirectory(subDir2);

                string file1 = Path.Combine(tempPath, "test1.idl");
                string file2 = Path.Combine(tempPath, "test2.idl");
                string file3 = Path.Combine(subDir1, "test3.idl");
                string file4 = Path.Combine(subDir2, "test4.idl");


                using (FileStream fs = File.Create(file1))
                {
                    fs.Close();
                }
                using (FileStream fs = File.Create(file2))
                {
                    fs.Close();
                }
                using (FileStream fs = File.Create(file3))
                {
                    fs.Close();
                }
                using (FileStream fs = File.Create(file4))
                {
                    fs.Close();
                }

                IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                    new string[] { "-pidl:" + tempPath, "testAsm" });
                Assert.AreEqual(4,
                                   commandLine.InputFileNames.Count, "idl files");
                Assert.AreEqual(
                                       file1,
                                       commandLine.InputFileNames[0], "idl file1");
                Assert.AreEqual(
                                       file2,
                                       commandLine.InputFileNames[1], "idl file2");
                Assert.AreEqual(file3,
                                       commandLine.InputFileNames[2], "idl file3");
                Assert.AreEqual(file4,
                                       commandLine.InputFileNames[3], "idl file4");

                Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");

            }
            finally
            {
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
        }
        public void TestIdlFilesReadFromFile()
        {
            string fileWithIdlFiles = Path.GetTempFileName();
            try
            {
                string file1 = "test1.idl";
                string file2 = "test2.idl";
                using (StreamWriter sw = new StreamWriter(fileWithIdlFiles))
                {
                    sw.WriteLine(file1);
                    sw.WriteLine(file2);
                }

                IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                    new string[] { "-fidl:" + fileWithIdlFiles, "testAsm" });
                Assert.AreEqual(2,
                                   commandLine.InputFileNames.Count, "idl files");
                Assert.AreEqual(file1,
                                       commandLine.InputFileNames[0], "idl file1");
                Assert.AreEqual(
                                       file2,
                                       commandLine.InputFileNames[1], "idl file2");

                Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");

            }
            finally
            {
                if (File.Exists(fileWithIdlFiles))
                {
                    File.Delete(fileWithIdlFiles);
                }
            }
        }
        public void TestLibDirs()
        {
            DirectoryInfo dir1 = new DirectoryInfo(Path.Combine(".", "lib1"));
            DirectoryInfo dir2 = new DirectoryInfo(Path.Combine(".", "lib2"));
            DirectoryInfo dir3 = new DirectoryInfo(Path.Combine(".", "lib3"));

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-lib:" + dir1.FullName + ";" + dir2.FullName, 
                               "-lib:" + dir3.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(3,
                                   commandLine.LibDirectories.Count, "libs");
            Assert.AreEqual(dir1.FullName,
                                   ((DirectoryInfo)commandLine.LibDirectories[0]).FullName,
                                   "lib dir 1");
            Assert.AreEqual(dir2.FullName,
                                   ((DirectoryInfo)commandLine.LibDirectories[1]).FullName,
                                   "lib dir 2");
            Assert.AreEqual(dir3.FullName,
                                   ((DirectoryInfo)commandLine.LibDirectories[2]).FullName,
                                   "lib dir 3");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestAsmVersion()
        {
            string asmVersion = "1.0.0.0";
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-asmVersion", asmVersion, "testAsm", "test.idl" });
            Assert.AreEqual(asmVersion, commandLine.AssemblyVersion, "Target Assembly Version");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestIsHelpRequested()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-h" });
            Assert.IsTrue(commandLine.IsHelpRequested, "Help requested");
            commandLine = new IDLToCLSCommandLine(
                new string[] { "-help" });
            Assert.IsTrue(commandLine.IsHelpRequested, "Help requested");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestBaseDirectory()
        {
            DirectoryInfo testDir = new DirectoryInfo(".");
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-basedir", testDir.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(testDir.FullName, commandLine.BaseDirectory.FullName, "BaseDirectory");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestTargetAssemblyName()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "testAsm", "test.idl" });
            Assert.AreEqual("testAsm", commandLine.TargetAssemblyName, "targetAssemblyName");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestInheritBaseInterface()
        {
            Type type = typeof(IDisposable);
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-b", type.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(type.FullName, commandLine.BaseInterface.FullName, "BaseInterface");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestSingleIdlFile()
        {
            string file1 = "test1.idl";

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "testAsm", file1 });
            Assert.AreEqual(1,
                                   commandLine.InputFileNames.Count, "idl files");
            Assert.AreEqual(file1, commandLine.InputFileNames[0], "idl file1");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestVtSkel()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-vtSkel", "testAsm", "test.idl" });
            Assert.IsTrue(commandLine.GenerateValueTypeSkeletons, "Value Type Skeleton generation");

            Assert.IsTrue(!commandLine.IsInvalid,"Command line validity");
        }
        public void TestIdlFiles()
        {
            string file1 = "test1.idl";
            string file2 = "test2.idl";
            string file3 = "test3.idl";

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "testAsm", file1, file2, file3 });
            Assert.AreEqual(3,
                                   commandLine.InputFileNames.Count, "idl files");
            Assert.AreEqual(file1,
                                   commandLine.InputFileNames[0], "idl file1");
            Assert.AreEqual(
                                   file2,
                                   commandLine.InputFileNames[1], "idl file2");
            Assert.AreEqual(
                                   file3,
                                   commandLine.InputFileNames[2], "idl file3");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestVtTargetDir()
        {
            DirectoryInfo testDir = new DirectoryInfo(Path.Combine(".", "testGenVtDir"));
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-vtSkelTd", testDir.FullName, "testAsm", "test.idl" });
            Assert.AreEqual(testDir.FullName, commandLine.ValueTypeSkeletonsTargetDir.FullName,
                                "Valuetype Skeletons Target Directory");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestCustomMappingFiles()
        {
            string customMappingFile1 = "customMapping1.xml";
            string customMappingFile2 = "customMapping2.xml";

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-c", customMappingFile1, "-c", customMappingFile2,
                               "testAsm", "test.idl" });
            Assert.AreEqual( 2,
                                   commandLine.CustomMappingFiles.Count, "CustomMappingFiles");
            Assert.AreEqual(customMappingFile1,
                                   ((FileInfo)commandLine.CustomMappingFiles[0]).Name, "CustomMappingFile 1");
            Assert.AreEqual(customMappingFile2,
                                   ((FileInfo)commandLine.CustomMappingFiles[1]).Name, "CustomMappingFile 2");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
 public void TestVtGenerationProviderInvalid()
 {
     string providerName = "System.NonExistingProvider";
     IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
         new string[] { "-vtSkelProv", providerName, "testAsm", "test.idl" });
     Assert.IsTrue(commandLine.IsInvalid, "Invalid codedom provider");
     Assert.AreEqual(string.Format("provider {0} not found!", providerName),
                            commandLine.ErrorMessage, "invalid arguments message");
 }
        public void TestCustomMappingFilesMultipleTheSame()
        {
            string customMappingFile1 = "customMapping1.xml";
            string customMappingFile2 = "customMapping1.xml";

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-c", customMappingFile1, "-c", customMappingFile2,
                               "testAsm", "test.idl" });
            Assert.IsTrue(commandLine.IsInvalid, "Invalid commandLine detection");
            Assert.IsTrue(commandLine.ErrorMessage.StartsWith(
                                "tried to add a custom mapping file multiple times: "), "invalid commandLine message");
        }
Example #29
0
    private void Setup(String[] args) {
        m_commandLine = new IDLToCLSCommandLine(args);
        if (m_commandLine.IsHelpRequested) {
            HowTo();
            Environment.Exit(0);
        }
        
        if (m_commandLine.IsInvalid) {
            Error(m_commandLine.ErrorMessage);
        }
        
        // create output directory
        if (!Directory.Exists(m_commandLine.OutputDirectory.FullName)) {
            Directory.CreateDirectory(m_commandLine.OutputDirectory.FullName);
        }
        
        // process include dirs
        for (int i = 0; i < m_commandLine.IdlSourceDirectories.Count; i++) {
            IDLPreprocessor.SetIdlDir((DirectoryInfo)m_commandLine.IdlSourceDirectories[i]);
        }
        
        if (m_commandLine.BaseDirectory != null) {
            Environment.CurrentDirectory = m_commandLine.BaseDirectory.FullName;
        }

        // preprocessor defines
        for (int i = 0; i < m_commandLine.PreprocessorDefines.Count; i++) {
            IDLPreprocessor.AddDefine((string)m_commandLine.PreprocessorDefines[i]);
        }
        
        // vt-skeleton generation setup
        if (m_commandLine.GenerateValueTypeSkeletons &&
            m_commandLine.ValueTypeSkeletonCodeDomProviderType != null) {
            m_vtSkelcodeDomProvider = 
                    (CodeDomProvider) Activator.CreateInstance(
                        m_commandLine.ValueTypeSkeletonCodeDomProviderType);
        }
        
        SetupAssemblyResolver();
        AddCustomMappings(m_commandLine.CustomMappingFiles);
        
    }
        public void TestSnkFile()
        {
            string snkFile = "test.snk";
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-snk", snkFile, "testAsm", "test.idl" });
            Assert.AreEqual(snkFile, commandLine.SignKeyFile.Name, "Key file");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestDelaySign()
        {
            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-delaySign", "testAsm", "test.idl" });
            Assert.IsTrue(commandLine.DelaySign,"DelaySign");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }
        public void TestPreprocessorDefines()
        {
            string def1 = "def1";
            string def2 = "def2";

            IDLToCLSCommandLine commandLine = new IDLToCLSCommandLine(
                new string[] { "-d", def1, "-d", def2, "testAsm", "test.idl" });
            Assert.AreEqual(2,
                                   commandLine.PreprocessorDefines.Count, "defines");
            Assert.AreEqual(def1,
                                   commandLine.PreprocessorDefines[0], "define 1");
            Assert.AreEqual(def2,
                                   commandLine.PreprocessorDefines[1], "define 2");

            Assert.IsTrue(!commandLine.IsInvalid, "Command line validity");
        }