예제 #1
0
파일: Nil.cs 프로젝트: jneedhamspkt/ndf5
        public void TestBasicLengthedNilRead(
            [Values] uMessages.MessageAttributeFlag aFlags,
            [Values(2, 4, 8)] int aOffsetBytes,
            [Values(2, 4, 8)] int aLengthBytes,
            [Values(0, 2, 4, 8, 255, 2047)] int aReadBytes)
        {
            Mock <ndf5.Metadata.ISuperBlock>
            fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);

            fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)aOffsetBytes);
            fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)aLengthBytes);

            Hdf5Reader
                fReader = new Hdf5Reader(new System.IO.MemoryStream(new byte[0]), fSuperBlock.Object);

            long fRead;

            uMessages.Message fShortTest = ndf5.Messages.Message.Read(
                fReader,
                uMessages.MessageType.NIL,
                aFlags,
                (long)aReadBytes,
                out fRead);

            Assert.That(fShortTest, Is.InstanceOf(typeof(uMessages.Nil)),
                        "Incorrect Message type parsed");
            Assert.That(fRead, Is.EqualTo(0),
                        "Zero bytes should be read");
        }
예제 #2
0
        public void Test_Data_Space_V2_Special_Parsing(
            [Values(uObjects.DataSpaceType.Null,
                    uObjects.DataSpaceType.Scaler)]
            uObjects.DataSpaceType aType)
        {
            using (Stream fTestSource = new MemoryStream())
                using (BinaryWriter fWriter = new BinaryWriter(fTestSource))
                {
                    fWriter.Write((byte)2);   //Version 2
                    fWriter.Write((byte)0);   //Dimensionality
                    fWriter.Write((byte)0x1); //Flags, Has Max
                    fWriter.Write((byte)aType);

                    fTestSource.Seek(0, SeekOrigin.Begin);

                    Mock <ndf5.Metadata.ISuperBlock>
                    fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);
                    fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)8);
                    fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)8);

                    Hdf5Reader
                        fReader = new Hdf5Reader(fTestSource, fSuperBlock.Object);

                    //Act
                    long fRead;
                    uMessages.Message fTest = ndf5.Messages.Message.Read(
                        fReader,
                        uMessages.MessageType.Dataspace,
                        uMessages.MessageAttributeFlag.None,
                        null,
                        out fRead);

                    uMessages.Dataspace
                        fResult = fTest as uMessages.Dataspace;

                    //Assert
                    Assert.That(fResult,
                                Is.Not.Null,
                                "Incorrect Message Type returned");
                    Assert.That(fResult.Dimensions.Count,
                                Is.EqualTo(0),
                                "Incorrect Dimensions");
                    Assert.That(fRead,
                                Is.EqualTo(fTestSource.Position),
                                "Incorrect Read Bytes");
                    Assert.That(fResult.DataSpaceType,
                                Is.EqualTo(aType),
                                "Incorrect object type");
                }
        }
예제 #3
0
파일: Nil.cs 프로젝트: jneedhamspkt/ndf5
        public void TestBasicNilRead(
            [Values] uMessages.MessageAttributeFlag aFlags,
            [Values(2, 4, 8)] int aOffsetBytes,
            [Values(2, 4, 8)] int aLengthBytes)
        {
            Mock <ndf5.Metadata.ISuperBlock>
            fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);

            fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)aOffsetBytes);
            fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)aLengthBytes);

            Hdf5Reader
                fReader = new Hdf5Reader(new System.IO.MemoryStream(new byte[0]), fSuperBlock.Object);

            uMessages.Message fShortTest = ndf5.Messages.Message.Read(
                fReader,
                uMessages.MessageType.NIL,
                aFlags);

            Assert.That(fShortTest, Is.InstanceOf(typeof(uMessages.Nil)));
        }
예제 #4
0
        public void Full_Creation_Tracking_NonCompact(
            [Values(2, 4, 8)] int aOffsetBytes,
            [Random(2)] ushort aHeapAddr,
            [Random(2)] ushort aTreeAddr,
            [Random(2)] ushort aCreateTreeAddr,
            [Random(2)] ulong aMaxCreation)
        {
            //Arrange
            using (Stream fTestSource = new MemoryStream())
                using (BinaryWriter fWriter = new BinaryWriter(fTestSource))
                {
                    Action <ulong?> fWriteOffset = null;
                    switch (aOffsetBytes)
                    {
                    case 2:
                        fWriteOffset = a => fWriter.Write((ushort)(a ?? ushort.MaxValue));
                        break;

                    case 4:
                        fWriteOffset = a => fWriter.Write((uint)(a ?? uint.MaxValue));
                        break;

                    case 8:
                        fWriteOffset = a => fWriter.Write((ulong)(a ?? ulong.MaxValue));
                        break;
                    }
                    fWriter.Write((byte)0);        // Version 0
                    fWriter.Write((byte)0x3);      // Flags
                    fWriter.Write((byte)0x0);      // Reserved
                    fWriter.Write((byte)0x0);      // Reserved
                    fWriter.Write(aMaxCreation);   // Max  Creation
                    fWriteOffset(aHeapAddr);       // Heap
                    fWriteOffset(aTreeAddr);       // Name
                    fWriteOffset(aCreateTreeAddr); // Creation Index

                    fTestSource.Seek(0, SeekOrigin.Begin);

                    Mock <ndf5.Metadata.ISuperBlock>
                    fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);
                    fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)aOffsetBytes);
                    fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)8);

                    Hdf5Reader
                        fReader = new Hdf5Reader(fTestSource, fSuperBlock.Object);

                    //Test read bytes checking
                    long fRead;
                    Assert.That(() =>
                    {
                        ndf5.Messages.Message.Read(
                            fReader,
                            uMessages.MessageType.LinkInfo,
                            uMessages.MessageAttributeFlag.None,
                            5,
                            out fRead);
                    },
                                Throws.ArgumentException,
                                "Read bytes not checked properly");

                    fTestSource.Seek(0, SeekOrigin.Begin);

                    //Act
                    uMessages.Message fTest = ndf5.Messages.Message.Read(
                        fReader,
                        uMessages.MessageType.LinkInfo,
                        uMessages.MessageAttributeFlag.None,
                        null,
                        out fRead);

                    uMessages.LinkInfo
                        fResult = fTest as uMessages.LinkInfo;

                    //Assert
                    Assert.That(fResult,
                                Is.Not.Null,
                                "Incorrect Message Type returned");
                    Assert.That(
                        fRead, Is.EqualTo(
                            fTestSource.Position),
                        "Incorrect Read bytes");
                    Assert.That(
                        fResult.IsCreationOrderTracked,
                        Is.True,
                        "Incorrect flag for IsCreationOrderTracked parsed");
                    Assert.That(
                        fResult.IsCreationOrderIndexed,
                        Is.True,
                        "Incorrect flag for IsCreationOrderIndexed parsed");
                    Assert.That(
                        fResult.MaximumCreationIndex,
                        Is.EqualTo(aMaxCreation),
                        "Incorrect value for MaximumCreationIndex parsed");
                    Assert.That(
                        (ulong)fResult.FractalHeapAddress,
                        Is.EqualTo(aHeapAddr),
                        "Incorrect value for FractalHeapAddress parsed");
                    Assert.That(
                        (ulong)fResult.NameIndexBTreeAddress,
                        Is.EqualTo(aTreeAddr),
                        "Incorrect value for NameIndexBTreeAddress parsed");
                    Assert.That(
                        fResult.CreationOrderIndexBTreeAddress,
                        Is.EqualTo((Offset)aCreateTreeAddr),
                        "Incorrect value for CreationOrderIndexBTreeAddress parsed");
                }
        }
예제 #5
0
        public void Test_Data_Space_V2_Limited_Simple_Parsing(
            [Values(2, 4, 8)] int aLengthBytes,
            [Range(1, 5)] int aDims)
        {
            //Arrange
            using (Stream fTestSource = new MemoryStream())
                using (BinaryWriter fWriter = new BinaryWriter(fTestSource))
                {
                    Action <Length> fWriteLength = null;
                    switch (aLengthBytes)
                    {
                    case 2:
                        fWriteLength = a => fWriter.Write((ushort)(a ?? ushort.MaxValue));
                        break;

                    case 4:
                        fWriteLength = a => fWriter.Write((uint)(a ?? uint.MaxValue));
                        break;

                    case 8:
                        fWriteLength = a => fWriter.Write((ulong)(a ?? ulong.MaxValue));
                        break;
                    }
                    fWriter.Write((byte)2);     //Version 2
                    fWriter.Write((byte)aDims); //Dimensionality
                    fWriter.Write((byte)0x1);   //Flags, Has Max
                    fWriter.Write((byte)uObjects.DataSpaceType.Simple);

                    for (int i = 0; i < aDims; ++i)
                    {
                        fWriteLength((ulong)TestDimensions[i].Size);
                    }
                    for (int i = 0; i < aDims; ++i)
                    {
                        fWriteLength((ulong?)TestDimensions[i].MaxSize);
                    }

                    fTestSource.Seek(0, SeekOrigin.Begin);

                    Mock <ndf5.Metadata.ISuperBlock>
                    fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);
                    fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)8);
                    fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)aLengthBytes);

                    Hdf5Reader
                        fReader = new Hdf5Reader(fTestSource, fSuperBlock.Object);

                    //Act
                    long fRead;
                    uMessages.Message fTest = ndf5.Messages.Message.Read(
                        fReader,
                        uMessages.MessageType.Dataspace,
                        uMessages.MessageAttributeFlag.None,
                        null,
                        out fRead);

                    uMessages.Dataspace
                        fResult = fTest as uMessages.Dataspace;

                    //Assert
                    Assert.That(fResult,
                                Is.Not.Null,
                                "Incorrect Message Type returned");
                    Assert.That(fResult.Dimensions,
                                Is.EquivalentTo(TestDimensions.Take(aDims)),
                                "Incorrect Dimensions");
                    Assert.That(fRead,
                                Is.EqualTo(fTestSource.Position),
                                "Incorrect Read Bytes");
                    Assert.That(fResult.DataSpaceType,
                                Is.EqualTo(uObjects.DataSpaceType.Simple),
                                "Incorrect object type");
                }
        }
예제 #6
0
        public void Test_Data_Space_TooShortError(
            [Values(2, 4, 8)] int aLengthBytes,
            [Range(2, 5)] int aTooShortLength,
            [Range(1, 2)] int aVersion)
        {
            //Arrange
            using (Stream fTestSource = new MemoryStream())
                using (BinaryWriter fWriter = new BinaryWriter(fTestSource))
                {
                    int
                                    fDims        = TestDimensions.Length;
                    Action <Length> fWriteLength = null;
                    switch (aLengthBytes)
                    {
                    case 2:
                        fWriteLength = a => fWriter.Write((ushort)(a ?? ushort.MaxValue));
                        break;

                    case 4:
                        fWriteLength = a => fWriter.Write((uint)(a ?? uint.MaxValue));
                        break;

                    case 8:
                        fWriteLength = a => fWriter.Write((ulong)(a ?? ulong.MaxValue));
                        break;
                    }
                    fWriter.Write((byte)aVersion);  //Version
                    fWriter.Write((byte)fDims);     //Dimensionality
                    fWriter.Write((byte)0x1);       //Flags, Has Max
                    fWriter.Write((byte)0x0);       //Reserved
                    fWriter.Write((int)0x0);        //Reserved

                    for (int i = 0; i < fDims; ++i)
                    {
                        fWriteLength((ulong)TestDimensions[i].Size);
                    }
                    for (int i = 0; i < fDims; ++i)
                    {
                        fWriteLength((ulong?)TestDimensions[i].MaxSize);
                    }

                    fTestSource.Seek(0, SeekOrigin.Begin);

                    Mock <ndf5.Metadata.ISuperBlock>
                    fSuperBlock = new Mock <ndf5.Metadata.ISuperBlock>(MockBehavior.Loose);
                    fSuperBlock.SetupGet(a => a.SizeOfOffsets).Returns((byte)8);
                    fSuperBlock.SetupGet(a => a.SizeOfLengths).Returns((byte)aLengthBytes);

                    Hdf5Reader
                        fReader = new Hdf5Reader(fTestSource, fSuperBlock.Object);

                    //Act/Assert
                    long fRead;
                    Assert.That(() =>
                    {
                        uMessages.Message fTest = ndf5.Messages.Message.Read(
                            fReader,
                            uMessages.MessageType.Dataspace,
                            uMessages.MessageAttributeFlag.None,
                            aTooShortLength,
                            out fRead);
                    },
                                Throws.ArgumentException,
                                "Stream should be too short to read");
                }
        }