Пример #1
0
        public void UnsafeObjectStream_RawSeekBackward_SeeksToPreviousObject_WhenNotAtBeginningOfStream()
        {
            var stream = new UnsafeObjectStream();

            stream.AcquirePointers();
            try
            {
                unsafe
                {
                    stream.ReserveMultiple(2, 2 * sizeof(UnsafeObjectTypeOne));

                    *(UnsafeObjectTypeOne *)stream.Data = new UnsafeObjectTypeOne()
                    {
                        ObjectType = UnsafeObjectType.TypeOne, Value1 = 123
                    };
                    stream.FinalizeObject(sizeof(UnsafeObjectTypeOne));

                    *(UnsafeObjectTypeOne *)stream.Data = new UnsafeObjectTypeOne()
                    {
                        ObjectType = UnsafeObjectType.TypeOne, Value1 = 234
                    };
                    stream.FinalizeObject(sizeof(UnsafeObjectTypeOne));

                    stream.RawSeekObject(stream.LengthInObjects);

                    TheResultingValue(stream.PositionInBytes).ShouldBe(stream.LengthInBytes);
                    TheResultingValue(stream.PositionInObjects).ShouldBe(stream.LengthInObjects);

                    stream.SeekBackward();

                    TheResultingValue(stream.PositionInBytes).ShouldBe(stream.LengthInBytes - (sizeof(UnsafeObjectTypeOne)));
                    TheResultingValue(stream.PositionInObjects).ShouldBe(stream.LengthInObjects - 1);

                    stream.SeekBackward();

                    TheResultingValue(stream.PositionInBytes).ShouldBe(stream.LengthInBytes - (sizeof(UnsafeObjectTypeOne) + sizeof(UnsafeObjectTypeOne)));
                    TheResultingValue(stream.PositionInObjects).ShouldBe(stream.LengthInObjects - 2);
                }
            }
            finally
            {
                stream.ReleasePointers();
            }
        }
Пример #2
0
        public void UnsafeObjectStream_RawSeekForward_SeeksToNextObject_WhenNotAtEndOfStream()
        {
            var stream = new UnsafeObjectStream();

            stream.AcquirePointers();
            try
            {
                unsafe
                {
                    stream.ReserveMultiple(2, 2 * sizeof(UnsafeObjectTypeOne));

                    *(UnsafeObjectTypeOne *)stream.Data = new UnsafeObjectTypeOne()
                    {
                        ObjectType = UnsafeObjectType.TypeOne, Value1 = 123
                    };
                    stream.FinalizeObject(sizeof(UnsafeObjectTypeOne));

                    *(UnsafeObjectTypeOne *)stream.Data = new UnsafeObjectTypeOne()
                    {
                        ObjectType = UnsafeObjectType.TypeOne, Value1 = 234
                    };
                    stream.FinalizeObject(sizeof(UnsafeObjectTypeOne));

                    stream.RawSeekObject(0);

                    TheResultingValue(stream.PositionInBytes).ShouldBe(0);
                    TheResultingValue(stream.PositionInObjects).ShouldBe(0);

                    stream.SeekForward();

                    TheResultingValue(stream.PositionInBytes).ShouldBe(sizeof(UnsafeObjectTypeOne));
                    TheResultingValue(stream.PositionInObjects).ShouldBe(1);

                    stream.SeekForward();

                    TheResultingValue(stream.PositionInBytes).ShouldBe(sizeof(UnsafeObjectTypeOne) + sizeof(UnsafeObjectTypeOne));
                    TheResultingValue(stream.PositionInObjects).ShouldBe(2);
                }
            }
            finally
            {
                stream.ReleasePointers();
            }
        }