示例#1
0
        public void Clone()
        {
            string path = Assembly.GetExecutingAssembly().Location;

            path = Path.GetDirectoryName(path);

            var root       = new RootFolderDefinition(Path.Combine(path, "CppTestProject"));
            var header     = new HeaderDefinition("header1.h");
            var @namespace = new NamespaceDefinition();
            var @class     = new ClassDefinition("CppClass");
            var @enum      = new EnumDefinition("CppEnum");

            root.AddChild(header);

            @namespace.AddChild(@class);
            header.AddNode(@class);

            @namespace.AddChild(@enum);
            header.AddNode(@enum);

            var cloner = new StructureCloner();

            cloner.Clone(@namespace);
            var rootClone          = cloner.RootFolderClone;
            var rootNamespaceClone = cloner.RootNamespaceClone;


            Assert.AreNotSame(root, rootClone);
            Assert.AreEqual(root.FullPath, rootClone.FullPath);
            Assert.AreEqual(root.Children.Count, rootClone.Children.Count);

            var headerClone = (HeaderDefinition)rootClone.Children.First();

            Assert.AreNotSame(header, headerClone);
            Assert.AreSame(rootClone, headerClone.Parent);
            Assert.AreEqual(2, headerClone.Nodes.Count);

            var classClone = (ClassDefinition)headerClone.Nodes[0];

            Assert.AreNotSame(@class, classClone);
            Assert.AreSame(headerClone, classClone.Header);
            Assert.AreEqual(@class.Name, classClone.Name);
            Assert.AreEqual(@class.Children.Count, classClone.Children.Count);
            Assert.AreSame(rootNamespaceClone, classClone.Parent);

            var enumClone = (EnumDefinition)headerClone.Nodes[1];

            Assert.AreNotSame(@enum, enumClone);
            Assert.AreSame(headerClone, enumClone.Header);
            Assert.AreEqual(@enum.Name, enumClone.Name);
            Assert.AreEqual(@enum.Children.Count, enumClone.Children.Count);
            Assert.AreSame(rootNamespaceClone, enumClone.Parent);

            Assert.AreNotSame(@namespace, rootNamespaceClone);
            Assert.AreEqual(@namespace.Children.Count, rootNamespaceClone.Children.Count);
        }
示例#2
0
        public void ReplaceRootNode()
        {
            string path = Assembly.GetExecutingAssembly().Location;

            path = Path.GetDirectoryName(path);

            var root   = new RootFolderDefinition(Path.Combine(path, "CppTestProject"));
            var header = new HeaderDefinition("header1.h");

            root.AddChild(header);
            var @class = new ClassDefinition("CppClass");

            header.AddNode(@class);

            var replacement = new RootFolderDefinition(Path.Combine(path, "CppTestProject2"));

            StructureNodeReplacer.Replace(root, replacement);

            Assert.IsNull(root.Parent);
            Assert.AreEqual(0, root.Children.Count);

            Assert.IsNull(replacement.Parent);
            Assert.AreEqual(1, replacement.Children.Count);

            Assert.AreEqual(replacement, header.Parent);
        }
示例#3
0
        public void Transform(NamespaceDefinition globalNamespace, RootFolderDefinition rootFolder)
        {
            var methodsHeader = new HeaderDefinition("UnsafeNativeMethods.cs");
            var methodsClass  = new ClassDefinition("UnsafeNativeMethods");

            CreateExternMethods(globalNamespace, methodsClass);

            methodsHeader.AddNode(methodsClass);
            globalNamespace.AddChild(methodsClass);
            rootFolder.AddChild(methodsHeader);
        }
        public void CreatesNativeMethodImports()
        {
            var @namespace = new NamespaceDefinition();
            var @class     = new ClassDefinition("CppClass");
            var method     = new MethodDefinition("method");

            @namespace.AddChild(@class);
            @class.AddChild(method);

            var rootFolder = new RootFolderDefinition("root");
            var header     = new HeaderDefinition("header.h");

            rootFolder.AddChild(header);

            header.AddNode(@class);

            new DotNetTransformer().Transform(@namespace, rootFolder);

            var methodsHeader = rootFolder.Children.FirstOrDefault(c => c.Name == "UnsafeNativeMethods.cs");

            Assert.IsNotNull(methodsHeader);

            var methodsClass = @namespace.Children.FirstOrDefault(c => c.Name == "UnsafeNativeMethods") as ClassDefinition;

            Assert.IsNotNull(methodsClass);

            Assert.That(methodsClass.Children, Has.Count.EqualTo(1));
            var nativeMethod = methodsClass.Methods.First();

            Assert.AreEqual("CppClass_method", nativeMethod.Name);
            Assert.IsTrue(nativeMethod.IsStatic);
            Assert.IsTrue(nativeMethod.IsExtern);

            Assert.That(nativeMethod.Parameters, Has.Length.EqualTo(1));
            var objParameter = nativeMethod.Parameters[0];

            Assert.AreEqual("obj", objParameter.Name);
        }