Exemplo n.º 1
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");
                }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the message at the current location of an Hdf5Reader
        /// </summary>
        /// <returns>The message.</returns>
        /// <param name="aReader">A reader.</param>
        /// <param name="aReadFlags">Flags that describe how to handle this message</param>
        /// <param name="aMessageType">Type of message to read</param>
        /// <param name="aLocalMessageSize">Number of bytes to read</param>
        /// <param name="aBytes">Number of bytes that were actually read</param>
        public static Message Read(
            Hdf5Reader aReader,
            MessageType aMessageType,
            MessageAttributeFlag aReadFlags,
            long?aLocalMessageSize,
            out long aBytes)
        {
            switch (aMessageType)
            {
            case MessageType.NIL:
                aBytes = 0;
                return(new Nil());

            case MessageType.Dataspace:
                return(Dataspace.Read(
                           aReader,
                           aLocalMessageSize,
                           out aBytes));

            case MessageType.LinkInfo:
                return(LinkInfo.Read(
                           aReader,
                           aLocalMessageSize,
                           out aBytes));

            case MessageType.Datatype:
                return(Datatype.Read(
                           aReader,
                           aLocalMessageSize,
                           out aBytes));


            default:
                if (aReadFlags.HasFlag(MessageAttributeFlag.MustUnderstandToRead))
                {
                    throw new Exceptions.RequiredMessageNotUnderstood(
                              $"Message type {aMessageType} must be understood for this object to be valid");
                }
                break;
            }

            throw new NotImplementedException();//TODO: Add 'Not Undestood' message
        }
Exemplo n.º 3
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");
                }
        }