public void PerOS() { SimplePlatform p = TestSetup.PlatformLib; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.IsNotNull(p); // Assumption: No known non-unicode encoding support ancient Korean, non-ASCII latin, Chinese characters at once. const string uniFile = "ᄒᆞᆫ글ḀḘ韓國.txt"; const string asciiFile = "ASCII.txt"; string bclUniFullPath = Path.GetFullPath(uniFile); string bclAsciiFullPath = Path.GetFullPath(asciiFile); // UTF-16 mode (automatic) string nativeAsciiFullPath = p.GetFullPathName(asciiFile); Assert.IsTrue(nativeAsciiFullPath.Equals(bclAsciiFullPath, StringComparison.Ordinal)); string nativeUniFullPath = p.GetFullPathName(uniFile); Assert.IsTrue(nativeUniFullPath.Equals(bclUniFullPath, StringComparison.Ordinal)); // UTF-8 mode (manual) p.ForceChangeUnicode(UnicodeConvention.Utf8); nativeAsciiFullPath = p.GetFullPathName(asciiFile); Assert.IsTrue(nativeAsciiFullPath.Equals(bclAsciiFullPath, StringComparison.Ordinal)); nativeUniFullPath = p.GetFullPathName(uniFile); Assert.IsFalse(nativeUniFullPath.Equals(bclUniFullPath, StringComparison.Ordinal)); // UTF-16 mode (manual) p.ForceChangeUnicode(UnicodeConvention.Utf16); nativeAsciiFullPath = p.GetFullPathName(asciiFile); Assert.IsTrue(nativeAsciiFullPath.Equals(bclAsciiFullPath, StringComparison.Ordinal)); nativeUniFullPath = p.GetFullPathName(uniFile); Assert.IsTrue(nativeUniFullPath.Equals(bclUniFullPath, StringComparison.Ordinal)); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.IsNotNull(p); string magicFile1 = p.MagicGetPath1(null); string magicFile2 = p.MagicGetPath2(null); Assert.IsTrue(magicFile1.Equals(magicFile2, StringComparison.Ordinal)); } else { Assert.IsNull(p); } }
public static void AssemblyInitalize(TestContext ctx) { BaseDir = Path.GetFullPath(Path.Combine(TestHelper.GetProgramAbsolutePath(), "..", "..", "..")); SampleDir = Path.Combine(BaseDir, "Samples"); const string zlibDllName = "zlibwapi.dll"; const string magicDllName = "libmagic-1.dll"; #if NETCOREAPP const string zlibSoName = "libz.so"; const string zlibDylibName = "libz.dylib"; const string magicSoName = "libmagic.so"; const string magicDylibName = "libmagic.dylib"; #endif string arch = null; switch (RuntimeInformation.ProcessArchitecture) { case Architecture.X86: arch = "x86"; break; case Architecture.X64: arch = "x64"; break; case Architecture.Arm: arch = "armhf"; break; case Architecture.Arm64: arch = "arm64"; break; } bool implicitLoadZLib = false; bool implicitLoadMagic = false; bool implicitLoadPlataform = false; string libDir; #if NETFRAMEWORK libDir = arch; #elif NETCOREAPP libDir = "runtimes"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { libDir = Path.Combine(libDir, "win-"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libDir = Path.Combine(libDir, "linux-"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libDir = Path.Combine(libDir, "osx-"); } libDir += arch; libDir = Path.Combine(libDir, "native"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) #endif { PackagedZLibPath = Path.Combine(libDir, zlibDllName); PackagedMagicPath = Path.Combine(libDir, magicDllName); implicitLoadPlataform = true; } #if NETCOREAPP else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { PackagedZLibPath = Path.Combine(libDir, zlibSoName); PackagedMagicPath = Path.Combine(libDir, magicSoName); implicitLoadZLib = true; implicitLoadMagic = true; implicitLoadPlataform = true; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { PackagedZLibPath = Path.Combine(libDir, zlibDylibName); PackagedMagicPath = Path.Combine(libDir, magicDylibName); implicitLoadZLib = true; } #endif ExplicitZLib = new SimpleZLib(); ExplicitZLib.LoadLibrary(PackagedZLibPath); if (implicitLoadZLib) { ImplicitZLib = new SimpleZLib(); ImplicitZLib.LoadLibrary(); } ExplicitMagic = new SimpleFileMagic(); ExplicitMagic.LoadLibrary(PackagedMagicPath); if (implicitLoadMagic) { ImplicitMagic = new SimpleFileMagic(); ImplicitMagic.LoadLibrary(); } if (implicitLoadPlataform) { PlatformLib = new SimplePlatform(); PlatformLib.LoadLibrary(); } }