예제 #1
0
파일: NativeTests.cs 프로젝트: woydmw/repkg
        public unsafe void Test(
            string name,
            TexFlags?validateFlags = TexFlags.None)
        {
            var path = $"{TestHelper.BasePath}\\{TexDecompressingTests.InputDirectoryName}\\{name}.tex";
            var ctex = Native.RePKG.tex_load_file((byte *)Marshal.StringToHGlobalAnsi(path).ToPointer());

            using (var environment = Native.RePKG.GetEnvironmentFor(ctex))
            {
                ITex texture = new WCTex(ctex, environment);

                var firstMipmap = texture.FirstImage.FirstMipmap;
                var bytes       = firstMipmap.Bytes;

                if (validateFlags.HasValue)
                {
                    Assert.IsTrue(texture.Header.Flags.HasFlag(validateFlags));
                }

                TexDecompressingTests.ValidateBytes(bytes, name);
            }
        }
예제 #2
0
        public void TestWriteAndRead(string name)
        {
            // Load file
            var inputFileReader = TexDecompressingTests.LoadTestFile(name);
            var inputBytes      = new byte[inputFileReader.BaseStream.Length];
            var bytesRead       = inputFileReader.Read(inputBytes, 0, (int)inputFileReader.BaseStream.Length);

            Assert.AreEqual(inputFileReader.BaseStream.Length, bytesRead, "Failed to read input file");
            inputFileReader.Close();

            // Read tex
            var reader = new BinaryReader(new MemoryStream(inputBytes), Encoding.UTF8);
            var tex    = _reader.ReadFrom(reader);

            // Write tex
            var memoryStream = new MemoryStream(inputBytes.Length);
            var writer       = new BinaryWriter(memoryStream, Encoding.UTF8);

            _writer.WriteTo(writer, tex);
            var outputBytes = memoryStream.ToArray();

            // Verify
            Assert.AreEqual(inputBytes.Length, outputBytes.Length, "Written tex size doesn't match input size");

            for (var i = 0; i < inputBytes.Length; i++)
            {
                if (inputBytes[i] == outputBytes[i])
                {
                    continue;
                }

                throw new Exception(
                          $"Rewritten tex bytes are not the same at index: {i}\r\n" +
                          $"Expected: {inputBytes[i]}\r\n" +
                          $"Actual: {outputBytes[i]}");
            }
        }