コード例 #1
0
        public void Bitness()
        {
            DynLoaderBase instance = new EmptyLoader();

            switch (RuntimeInformation.ProcessArchitecture)
            {
            case Architecture.X86:
            case Architecture.Arm:
                Assert.AreEqual(PlatformBitness.Bit32, instance.PlatformBitness);
                break;

            case Architecture.X64:
            case Architecture.Arm64:
                Assert.AreEqual(PlatformBitness.Bit64, instance.PlatformBitness);
                break;
            }
        }
コード例 #2
0
        public void Unicode()
        {
            DynLoaderBase defaultInstance = new EmptyLoader();
            DynLoaderBase customInstance  = new EncLoader();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.AreEqual(UnicodeConvention.Utf16, defaultInstance.UnicodeConvention);
                Assert.IsTrue(defaultInstance.UnicodeEncoding.Equals(Encoding.Unicode));

                Assert.AreEqual(UnicodeConvention.Ansi, customInstance.UnicodeConvention);
                Assert.IsTrue(customInstance.UnicodeEncoding.Equals(new UTF8Encoding(false)));
            }
            else
            {
                Assert.AreEqual(UnicodeConvention.Utf8, defaultInstance.UnicodeConvention);
                Assert.IsTrue(defaultInstance.UnicodeEncoding.Equals(new UTF8Encoding(false)));

                Assert.AreEqual(UnicodeConvention.Utf8, customInstance.UnicodeConvention);
                Assert.IsTrue(customInstance.UnicodeEncoding.Equals(new UTF8Encoding(false)));
            }
        }
コード例 #3
0
        public void DataModel()
        {
            DynLoaderBase instance = new EmptyLoader();

            instance.LoadLibrary();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                switch (RuntimeInformation.ProcessArchitecture)
                {
                case Architecture.X86:
                case Architecture.Arm:
                    Assert.AreEqual(PlatformDataModel.ILP32, instance.PlatformDataModel);
                    break;

                case Architecture.X64:
                case Architecture.Arm64:
                    Assert.AreEqual(PlatformDataModel.LLP64, instance.PlatformDataModel);
                    break;
                }
            }
            else
            {
                switch (RuntimeInformation.ProcessArchitecture)
                {
                case Architecture.X86:
                case Architecture.Arm:
                    Assert.AreEqual(PlatformDataModel.ILP32, instance.PlatformDataModel);
                    break;

                case Architecture.X64:
                case Architecture.Arm64:
                    Assert.AreEqual(PlatformDataModel.LP64, instance.PlatformDataModel);
                    break;
                }
            }
        }
コード例 #4
0
        public void LongSize()
        {
            DynLoaderBase instance = new EmptyLoader();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.AreEqual(PlatformLongSize.Long32, instance.PlatformLongSize);
            }
            else
            {
                switch (RuntimeInformation.ProcessArchitecture)
                {
                case Architecture.X86:
                case Architecture.Arm:
                    Assert.AreEqual(PlatformLongSize.Long32, instance.PlatformLongSize);
                    break;

                case Architecture.X64:
                case Architecture.Arm64:
                    Assert.AreEqual(PlatformLongSize.Long64, instance.PlatformLongSize);
                    break;
                }
            }
        }
コード例 #5
0
        public void StringPtr()
        {
            DynLoaderBase defaultInstance = new EmptyLoader();
            DynLoaderBase customInstance  = new EncLoader();

            const string str         = "Joveler.DynLoader";
            IntPtr       ansiUtf8Ptr = Marshal.StringToHGlobalAnsi(str); // ANSI on Windows, UTF8 on POSIX
            IntPtr       utf16Ptr    = Marshal.StringToHGlobalUni(str);

            try
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // PtrToStringAuto
                    string fromUniStr = defaultInstance.PtrToStringAuto(utf16Ptr);
                    Assert.IsTrue(str.Equals(fromUniStr, StringComparison.Ordinal));
                    string fromAnsiStr = customInstance.PtrToStringAuto(ansiUtf8Ptr);
                    Assert.IsTrue(str.Equals(fromAnsiStr, StringComparison.Ordinal));

                    // StringToHGlobalAuto
                    IntPtr fromUniPtr = defaultInstance.StringToHGlobalAuto(str);
                    try
                    {
                        fromUniStr = Marshal.PtrToStringUni(fromUniPtr);
                        Assert.IsTrue(str.Equals(fromUniStr, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(fromUniPtr);
                    }
                    IntPtr fromAnsiPtr = customInstance.StringToHGlobalAuto(str);
                    try
                    {
                        fromAnsiStr = Marshal.PtrToStringAnsi(fromAnsiPtr);
                        Assert.IsTrue(str.Equals(fromAnsiStr, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(fromAnsiPtr);
                    }

                    // StringToCoTaskMemAuto
                    fromUniPtr = defaultInstance.StringToCoTaskMemAuto(str);
                    try
                    {
                        fromUniStr = Marshal.PtrToStringUni(fromUniPtr);
                        Assert.IsTrue(str.Equals(fromUniStr, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(fromUniPtr);
                    }
                    fromAnsiPtr = customInstance.StringToCoTaskMemAuto(str);
                    try
                    {
                        fromAnsiStr = Marshal.PtrToStringAnsi(fromAnsiPtr);
                        Assert.IsTrue(str.Equals(fromAnsiStr, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(fromAnsiPtr);
                    }
                }
                else
                {
                    // PtrToStringAuto
                    string fromUtf8Str = defaultInstance.PtrToStringAuto(ansiUtf8Ptr);
                    Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));
                    fromUtf8Str = customInstance.PtrToStringAuto(ansiUtf8Ptr);
                    Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));

                    // StringToHGlobalAuto
                    IntPtr fromUtf8Ptr = defaultInstance.StringToHGlobalAuto(str);
                    try
                    {
                        fromUtf8Str = Marshal.PtrToStringAnsi(fromUtf8Ptr);
                        Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(fromUtf8Ptr);
                    }
                    fromUtf8Ptr = customInstance.StringToHGlobalAuto(str);
                    try
                    {
                        fromUtf8Str = Marshal.PtrToStringAnsi(fromUtf8Ptr);
                        Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(fromUtf8Ptr);
                    }

                    // StringToCoTaskMemAuto
                    fromUtf8Ptr = defaultInstance.StringToCoTaskMemAuto(str);
                    try
                    {
                        fromUtf8Str = Marshal.PtrToStringAnsi(fromUtf8Ptr);
                        Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(fromUtf8Ptr);
                    }
                    fromUtf8Ptr = customInstance.StringToCoTaskMemAuto(str);
                    try
                    {
                        fromUtf8Str = Marshal.PtrToStringAnsi(fromUtf8Ptr);
                        Assert.IsTrue(str.Equals(fromUtf8Str, StringComparison.Ordinal));
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(fromUtf8Ptr);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ansiUtf8Ptr);
                Marshal.FreeHGlobal(utf16Ptr);
            }
        }