Exemplo n.º 1
0
        public static void VerifyField(CodeTypeDeclaration ctd, string name, string value)
        {
            CodeMemberField cField = null;

            VerifyField(ctd, name, ref cField);
            Assert.Equal(value, CodeDomPrinter.Convert(cField));
        }
Exemplo n.º 2
0
        public static void VerifyProcCallingConvention(string code, string name, System.Runtime.InteropServices.CallingConvention conv)
        {
            CodeMemberMethod         mem  = ConvertToSingleProc(code, name);
            CodeAttributeDeclaration decl = null;

            VerifyAttribute(mem.CustomAttributes, typeof(System.Runtime.InteropServices.DllImportAttribute), ref decl);
            if (conv == System.Runtime.InteropServices.CallingConvention.Winapi)
            {
                VerifyNoArgument(decl, "CallingConvention");
            }
            else
            {
                CodeAttributeArgument arg = null;
                VerifyArgument(decl, "CallingConvention", ref arg);
                Assert.Equal("CallingConvention." + conv.ToString(), CodeDomPrinter.Convert(arg.Value));
            }
        }
Exemplo n.º 3
0
        public static void VerifyConstValue(CodeTypeDeclarationCollection col, LanguageType lang, string name, string val, string type)
        {
            // Look for the constants class
            CodeTypeDeclaration ctd = null;

            VerifyType(col, TransformConstants.NativeConstantsName, ref ctd);

            // Find the value
            CodeTypeMember cMem = null;

            VerifyMember(ctd, name, ref cMem);

            // Make sure it's a constant value
            CodeMemberField field = cMem as CodeMemberField;

            Assert.NotNull(field);

            // Get the provider
            var provider = default(CodeDomProvider);

            switch (lang)
            {
            case LanguageType.CSharp:
                provider = new Microsoft.CSharp.CSharpCodeProvider();
                break;

            case LanguageType.VisualBasic:
                provider = new Microsoft.VisualBasic.VBCodeProvider();
                break;

            default:
                provider = null;
                break;
            }

            using (var writer = new StringWriter())
            {
                provider.GenerateCodeFromExpression(field.InitExpression, writer, new CodeGeneratorOptions());
                Assert.Equal(val, writer.ToString());
            }

            if (type != null)
            {
                Assert.Equal(type, CodeDomPrinter.Convert(field.Type));
            }
        }
Exemplo n.º 4
0
        private static bool VerifyProcImpl(string code, string sig, ref string all)
        {
            all = string.Empty;
            foreach (CodeMemberMethod method in ConvertToProc(code))
            {
                string p = CodeDomPrinter.Convert(method);
                if (0 == string.CompareOrdinal(sig, p))
                {
                    return(true);
                }
                else
                {
                    all += Environment.NewLine;
                    all += p;
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public static void VerifyExpression(LanguageType lang, string nativeExpr, string managedExpr, string managedType, NativeSymbolBag bag)
        {
            bag = bag ?? new NativeSymbolBag();
            CodeTransform         trans    = new CodeTransform(lang, bag);
            NativeValueExpression nExpr    = new NativeValueExpression(nativeExpr);
            CodeExpression        cExpr    = null;
            CodeTypeReference     codeType = null;
            Exception             ex       = null;

            Assert.True(trans.TryGenerateValueExpression(nExpr, out cExpr, out codeType, out ex));

            var provider = default(System.CodeDom.Compiler.CodeDomProvider);

            switch (lang)
            {
            case LanguageType.CSharp:
                provider = new Microsoft.CSharp.CSharpCodeProvider();
                break;

            case LanguageType.VisualBasic:
                provider = new Microsoft.VisualBasic.VBCodeProvider();
                break;

            default:
                provider = null;
                break;
            }

            Assert.NotNull(provider);
            using (var writer = new StringWriter())
            {
                provider.GenerateCodeFromExpression(cExpr, writer, new System.CodeDom.Compiler.CodeGeneratorOptions());
                Assert.Equal(managedExpr, writer.ToString());
            }

            if (managedType != null)
            {
                Assert.Equal(managedType, CodeDomPrinter.Convert(codeType));
            }
        }
Exemplo n.º 6
0
        public static void VerifyFPtrCallingConvention(string code, string name, System.Runtime.InteropServices.CallingConvention conv)
        {
            CodeTypeDeclarationCollection col  = ConvertToCodeDom(code);
            CodeTypeDeclaration           type = null;

            VerifyType(col, name, ref type);


            if (conv != System.Runtime.InteropServices.CallingConvention.Winapi)
            {
                CodeAttributeDeclaration decl = null;
                VerifyAttribute(type.CustomAttributes, typeof(System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute), ref decl);

                CodeAttributeArgument arg = null;
                VerifyArgument(decl, string.Empty, ref arg);
                Assert.Equal("CallingConvention." + conv.ToString(), CodeDomPrinter.Convert(arg.Value));
            }
            else
            {
                VerifyNoAttribute(type.CustomAttributes, typeof(System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute));
            }
        }