public void ShouldWriteAndReadGuid( [Values(10, 1000, 100000)] int count ) { var stream = new MemoryStream(); var array = new Guid[count]; using (var writer = new PrimitiveWriter(stream)) { for (var i = 0; i < count; i++) { var guid = Guid.NewGuid(); array[i] = guid; writer.Write(guid); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using (var reader = new PrimitiveReader(stream)) { for (var i = 0; i < count; i++) { Assert.AreEqual(array[i], reader.ReadGuid()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void TestingGuid(Guid init) { ResetBois(); PrimitiveWriter.WriteValue(Writer, init); ResetStream(); var final = PrimitiveReader.ReadGuid(Reader); final.Should().Be(init); }
public void ShouldWriteAndReadGuid( [Values(10, 1000, 100000)] int count ) { var stream = new MemoryStream(); var array = new Guid[count]; using(var writer = new PrimitiveWriter(stream)) { for(var i = 0; i < count; i++) { var guid = Guid.NewGuid(); array[i] = guid; writer.Write(guid); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { for(var i = 0; i < count; i++) { Assert.AreEqual(array[i], reader.ReadGuid()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
void ProcessFormatChunk( RiffChunkHeader chunk, PrimitiveReader reader ) { byte[] chunkData = reader.ReadBytes( chunk.DataSize ); Stream source = reader.stream; reader.stream = new MemoryStream( chunkData ); int audioFormat = reader.ReadUInt16(); Metadata["WAVE audio format"] = ((AudioFormat)audioFormat).ToString(); int channels = reader.ReadInt16(); Metadata[MetadataKeys.Channels] = channels.ToString(); int sampleRate = reader.ReadInt32(); Metadata[MetadataKeys.SampleRate] = sampleRate.ToString(); int byteRate = reader.ReadInt32(); int blockAlign = reader.ReadInt16(); int bitsPerSample = reader.ReadInt16(); Metadata[MetadataKeys.BitsPerSample] = bitsPerSample.ToString(); int extraInfoSize = 0; #pragma warning disable 0618 // Usually, only very old wave files don't have this // field included. (WaveFormat structure, not WaveFormatEx structure) // Supress the warning because it's a MemoryStream. if( reader.Position != reader.Length ) { extraInfoSize = reader.ReadUInt16(); } #pragma warning restore 0618 this.freq = sampleRate; transformer = EmptyTransformer.Instance; this.channels = channels; this.bitsPerSample = bitsPerSample; codecBitsPerSample = bitsPerSample; switch( (AudioFormat)audioFormat ) { case AudioFormat.Pcm: // No compression. if( bitsPerSample == 16 && reader.BigEndian ) { transformer = BigEndian16BitTo16BitTransformer.Instance; } break; case AudioFormat.IeeeFloat: if( bitsPerSample == 32 ) { this.bitsPerSample = 16; } else if( bitsPerSample == 64 ) { this.bitsPerSample = 16; } throw new NotSupportedException(); break; case AudioFormat.ALaw: transformer = ALawTransformer.Instance; this.bitsPerSample = 16; break; case AudioFormat.MuLaw: transformer = MuLawTransformer.Instance; this.bitsPerSample = 16; break; // TODO: Properly test this transformer, but I can't seem to find any wave files that use this format. case AudioFormat.DialogicOkiAdpcm: transformer = DialogicAdpcmTransformer.Instance; this.bitsPerSample = 16; break; // TODO: Test this transformer too. case AudioFormat.ImaAdpcm: transformer = ImaAdpcmTransformer.Instance; this.bitsPerSample = 16; break; case AudioFormat.Extensible: ushort validBitsPerSample = reader.ReadUInt16(); uint channelMask = reader.ReadUInt32(); Guid subFormat = reader.ReadGuid(); Metadata["extensible guid"] = subFormat.ToString(); if( subFormat == PcmGuid ) { } else if( subFormat == IeeeFloatGuid ) { throw new NotSupportedException( "Ieee float sub format not supported." ); } else if( subFormat == DrmGuid ) { throw new NotSupportedException( "Drm sub format not supported." ); } else if( subFormat == AlawGuid ) { transformer = ALawTransformer.Instance; this.bitsPerSample = 16; } else if( subFormat == MulawGuid ) { transformer = MuLawTransformer.Instance; this.bitsPerSample = 16; } else if( subFormat == AdpcmGuid ) { throw new NotSupportedException( "Adpcm sub format not supported." ); } else if( subFormat == MpegGuid ) { throw new NotSupportedException( "Mpeg sub format not supported." ); } else { throw new NotSupportedException( "Unsupported sub format: " + subFormat ); } break; default: throw new NotSupportedException( "Unsupported audio format: " + (AudioFormat)audioFormat ); } reader.stream = source; }