public void ValidityWithValidSamplesTest() { // Arrange byte[] inputBytes1 = File.ReadAllBytes(validSample1Filename); byte[] inputBytes2 = File.ReadAllBytes(validSample2Filename); byte[] inputBytes3 = File.ReadAllBytes(validSample3Filename); byte[] inputBytes4 = File.ReadAllBytes(validSample4Filename); // Act bool wasTest1Valid = false; string test1PossibleError = ""; using (MemoryStream ms1 = new MemoryStream(inputBytes1)) { (wasTest1Valid, test1PossibleError) = KtxLoader.CheckIfInputIsValid(ms1); } bool wasTest2Valid = false; string test2PossibleError = ""; using (MemoryStream ms2 = new MemoryStream(inputBytes2)) { (wasTest2Valid, test2PossibleError) = KtxLoader.CheckIfInputIsValid(ms2); } bool wasTest3Valid = false; string test3PossibleError = ""; using (MemoryStream ms3 = new MemoryStream(inputBytes3)) { (wasTest3Valid, test3PossibleError) = KtxLoader.CheckIfInputIsValid(ms3); } bool wasTest4Valid = false; string test4PossibleError = ""; using (MemoryStream ms4 = new MemoryStream(inputBytes4)) { (wasTest4Valid, test4PossibleError) = KtxLoader.CheckIfInputIsValid(ms4); } // Assert CollectionAssert.AreNotEqual(inputBytes1, inputBytes2, "Input files should NOT have equal content"); CollectionAssert.AreNotEqual(inputBytes1, inputBytes3, "Input files should NOT have equal content"); CollectionAssert.AreNotEqual(inputBytes1, inputBytes4, "Input files should NOT have equal content"); Assert.IsTrue(wasTest1Valid); Assert.IsTrue(wasTest2Valid); Assert.IsTrue(wasTest3Valid); Assert.IsTrue(wasTest4Valid); Assert.AreEqual("", test1PossibleError, "There should NOT be any errors"); Assert.AreEqual("", test2PossibleError, "There should NOT be any errors"); Assert.AreEqual("", test3PossibleError, "There should NOT be any errors"); Assert.AreEqual("", test4PossibleError, "There should NOT be any errors"); }
internal Texture2D(string path) { textureType = TextureTarget.Texture2D; GenerateTextureID(); Bitmap tex1; //check texture try { if (path.EndsWith("ktx", StringComparison.OrdinalIgnoreCase)) { byte[] ktxBytes = File.ReadAllBytes(path); KtxStructure ktxStructure = null; using (MemoryStream ms = new MemoryStream(ktxBytes)) { ktxStructure = KtxLoader.LoadInput(ms); LoadTexture(ktxStructure); } return; } ///cause .NET cant read tga natievly ///png , jpg, bmp is ok if (path.EndsWith("tga", StringComparison.OrdinalIgnoreCase)) { tex1 = Paloma.TargaImage.LoadTargaImage(path); } /// .spa| .sph textures is png bmp or jpg textures else if (path.EndsWith("spa", StringComparison.OrdinalIgnoreCase) || path.EndsWith("sph", StringComparison.OrdinalIgnoreCase)) { Stream strm = File.OpenRead(path); tex1 = new Bitmap(strm); } //process alpha channel on bmp else if (path.EndsWith("bmp", StringComparison.OrdinalIgnoreCase)) { tex1 = CustomBMPLoader.Load(path); } else { tex1 = new Bitmap(path); } LoadTexture(tex1); tex1.Dispose(); } catch (Exception) { logger.Error("cant load texture " + path, ""); Texture2D empty = LoadEmpty(); textureID = empty.textureID; Name = empty.Name; } }
public void ValidityWithValidSamplesTest() { // Arrange byte[] inputBytes1 = File.ReadAllBytes(CommonFiles.validSample1Filename); byte[] inputBytes2 = File.ReadAllBytes(CommonFiles.validSample2Filename); byte[] inputBytes3 = File.ReadAllBytes(CommonFiles.validSample3Filename); byte[] inputBytes4 = File.ReadAllBytes(CommonFiles.validSample4Filename); MemoryStream msWriter1 = new MemoryStream(); MemoryStream msWriter2 = new MemoryStream(); MemoryStream msWriter3 = new MemoryStream(); MemoryStream msWriter4 = new MemoryStream(); // Act KtxStructure ktxStructure1 = null; KtxStructure ktxStructure2 = null; KtxStructure ktxStructure3 = null; KtxStructure ktxStructure4 = null; using (MemoryStream msReader = new MemoryStream(inputBytes1)) { ktxStructure1 = KtxLoader.LoadInput(msReader); } using (MemoryStream msReader = new MemoryStream(inputBytes2)) { ktxStructure2 = KtxLoader.LoadInput(msReader); } using (MemoryStream msReader = new MemoryStream(inputBytes3)) { ktxStructure3 = KtxLoader.LoadInput(msReader); } using (MemoryStream msReader = new MemoryStream(inputBytes4)) { ktxStructure4 = KtxLoader.LoadInput(msReader); } KtxWriter.WriteTo(ktxStructure1, msWriter1); KtxWriter.WriteTo(ktxStructure2, msWriter2); KtxWriter.WriteTo(ktxStructure3, msWriter3); KtxWriter.WriteTo(ktxStructure4, msWriter4); // Assert CollectionAssert.AreEqual(inputBytes1, msWriter1.ToArray()); CollectionAssert.AreEqual(inputBytes2, msWriter2.ToArray()); CollectionAssert.AreEqual(inputBytes3, msWriter3.ToArray()); CollectionAssert.AreEqual(inputBytes4, msWriter4.ToArray()); }
public void NullOrInvalidInputsTest() { // Arrange KtxStructure structure = null; MemoryStream msWriter = new MemoryStream(); MemoryStream msWriterNonWriteable = new MemoryStream(new byte[] { 0 }, writable: false); // Act using (FileStream input = new FileStream(CommonFiles.validSample1Filename, FileMode.Open)) { structure = KtxLoader.LoadInput(input); } // Assert Assert.Throws <NullReferenceException>(() => { KtxWriter.WriteTo(null, msWriter); }); Assert.Throws <NullReferenceException>(() => { KtxWriter.WriteTo(structure, null); }); Assert.Throws <ArgumentException>(() => { KtxWriter.WriteTo(structure, msWriterNonWriteable); }); }
public void ValidityWithInvalidSamplesTest() { // Arrange byte[] inputBytes4 = File.ReadAllBytes(CommonFiles.validSample4Filename); // Act inputBytes4[73] = 0xC0; // Make string invalid UTF-8 inputBytes4[74] = 0xB1; bool wasTest4Valid = false; string test4PossibleError = ""; using (MemoryStream ms4 = new MemoryStream(inputBytes4)) { (wasTest4Valid, test4PossibleError) = KtxLoader.CheckIfInputIsValid(ms4); } // Assert Assert.IsFalse(wasTest4Valid); Assert.IsTrue(test4PossibleError.Contains("Byte array to UTF-8 failed")); }
public void CheckHeadersWithValidSamplesTest() { // Arrange byte[] inputBytes1 = File.ReadAllBytes(validSample1Filename); byte[] inputBytes2 = File.ReadAllBytes(validSample2Filename); byte[] inputBytes3 = File.ReadAllBytes(validSample3Filename); byte[] inputBytes4 = File.ReadAllBytes(validSample4Filename); // Act KtxStructure ktxStructure1 = null; using (MemoryStream ms1 = new MemoryStream(inputBytes1)) { ktxStructure1 = KtxLoader.LoadInput(ms1); } KtxStructure ktxStructure2 = null; using (MemoryStream ms2 = new MemoryStream(inputBytes2)) { ktxStructure2 = KtxLoader.LoadInput(ms2); } KtxStructure ktxStructure3 = null; using (MemoryStream ms3 = new MemoryStream(inputBytes3)) { ktxStructure3 = KtxLoader.LoadInput(ms3); } KtxStructure ktxStructure4 = null; using (MemoryStream ms4 = new MemoryStream(inputBytes4)) { ktxStructure4 = KtxLoader.LoadInput(ms4); } // Assert CollectionAssert.AreNotEqual(inputBytes1, inputBytes2, "Input files should NOT have equal content"); CollectionAssert.AreNotEqual(inputBytes1, inputBytes3, "Input files should NOT have equal content"); CollectionAssert.AreNotEqual(inputBytes1, inputBytes4, "Input files should NOT have equal content"); // Compressonator sample file resolution Assert.AreEqual(16, ktxStructure1.header.pixelWidth); Assert.AreEqual(16, ktxStructure1.header.pixelHeight); // PVRTexTool sample file resolution Assert.AreEqual(16, ktxStructure2.header.pixelWidth); Assert.AreEqual(16, ktxStructure2.header.pixelHeight); // ETCPACK sample file resolution Assert.AreEqual(2048, ktxStructure3.header.pixelWidth); Assert.AreEqual(32, ktxStructure3.header.pixelHeight); // ktx_specs.ktx resolution Assert.AreEqual(32, ktxStructure4.header.pixelWidth); Assert.AreEqual(32, ktxStructure4.header.pixelHeight); // ktx_specs.ktx Data type and internal format Assert.AreEqual(GlDataType.Compressed, ktxStructure4.header.glDataType); Assert.AreEqual((uint)GlDataType.Compressed, ktxStructure4.header.glTypeAsUint); Assert.AreEqual(GlInternalFormat.GL_ETC1_RGB8_OES, ktxStructure4.header.glInternalFormat); Assert.AreEqual((uint)GlInternalFormat.GL_ETC1_RGB8_OES, ktxStructure4.header.glInternalFormatAsUint); // ktx_specs.ktx Metadata Assert.AreEqual(1, ktxStructure4.header.metadataDictionary.Count); Assert.IsTrue(ktxStructure4.header.metadataDictionary.ContainsKey("api")); Assert.IsTrue(ktxStructure4.header.metadataDictionary["api"].isString); Assert.AreEqual("joke2", ktxStructure4.header.metadataDictionary["api"].stringValue); }