Пример #1
0
        public void LoadColor()
        {
            var data = BinaryDataExtensions.SaveToMemoryStream(Color.Red);
            var reconstructedColor = data.CreateFromMemoryStream();

            Assert.AreEqual(Color.Red, reconstructedColor);
        }
Пример #2
0
        public void SaveRangeGraph()
        {
            var range = new RangeGraph <Vector2D>(Vector2D.Zero, new Vector2D(3.0f, 3.0f));
            var data  = BinaryDataExtensions.SaveToMemoryStream(range);

            Assert.AreEqual(68, data.Length);
        }
Пример #3
0
        public static void AssertObjectWhenSavedAndRestoredByToString <T>(T anyObject)
        {
            MemoryStream serializedData  = BinaryDataExtensions.SaveToMemoryStream(anyObject);
            var          restoredMessage = (T)serializedData.CreateFromMemoryStream();

            Assert.AreEqual(anyObject.ToString(), restoredMessage.ToString());
        }
Пример #4
0
        public void SaveAndLoadFromMemoryStream()
        {
            var entity = new Entity2D(Rectangle.HalfCentered);

            entity.OnDraw <MockDrawBehavior>();
            Assert.AreEqual(0, entity.NumberOfComponents);
            var data = BinaryDataExtensions.SaveToMemoryStream(entity);

            byte[]    savedBytes         = data.ToArray();
            int       bytesForName       = "Entity2D".Length + 1;
            const int VersionNumberBytes = 4;
            int       componentBytes     = 1 + "Rectangle".Length + 1 + 16 + "IsVisible".Length + 1 + 1 + 2;
            const int BehaviorBytes      = 27;

            Assert.AreEqual(bytesForName + VersionNumberBytes + componentBytes + BehaviorBytes,
                            savedBytes.Length);
            var loadedEntity = data.CreateFromMemoryStream() as Entity2D;

            Assert.AreEqual(0, loadedEntity.NumberOfComponents);
            Assert.IsTrue(loadedEntity.IsActive);
            Assert.AreEqual(Rectangle.HalfCentered, loadedEntity.DrawArea);
            Assert.AreEqual(1, loadedEntity.GetDrawBehaviors().Count);
            Assert.AreEqual("MockDrawBehavior",
                            loadedEntity.GetDrawBehaviors()[0].GetShortNameOrFullNameIfNotFound());
        }
Пример #5
0
 public void ThrowExceptionIfTypeNameEndsWithImageOrSound()
 {
     Assert.Throws <BinaryDataSaver.UnableToSave>(
         () => BinaryDataExtensions.SaveToMemoryStream(new NonContentImage()));
     Assert.Throws <BinaryDataSaver.UnableToSave>(
         () => BinaryDataExtensions.SaveToMemoryStream(new NonContentSound()));
 }
Пример #6
0
        public void DrawLoadedRadioDialog()
        {
            var stream = BinaryDataExtensions.SaveToMemoryStream(dialog);

            dialog.IsActive = false;
            stream.CreateFromMemoryStream();
        }
Пример #7
0
        [Test, CloseAfterFirstFrame, Ignore]         //ncrunch: no coverage start
        public void SaveAndLoad()
        {
            var stream       = BinaryDataExtensions.SaveToMemoryStream(button);
            var loadedButton = (InteractiveButton)stream.CreateFromMemoryStream();

            Assert.AreEqual(Center, loadedButton.DrawArea);
            Assert.AreEqual("Click Me", loadedButton.Text);
        }
Пример #8
0
        public void DrawLoadedSlider()
        {
            slider.Value = 70;
            var stream = BinaryDataExtensions.SaveToMemoryStream(slider);

            slider.IsActive = false;
            stream.CreateFromMemoryStream();
        }
Пример #9
0
        private static MemoryStream Save3DMaterial()
        {
            var material = new Material(ShaderFlags.ColoredTextured, "DeltaEngineLogo");
            var data     = BinaryDataExtensions.SaveToMemoryStream(material);

            data.Seek(0, SeekOrigin.Begin);
            return(data);
        }
Пример #10
0
        public void DrawLoadedScrollbar()
        {
            scrollbar.CenterValue = 50;
            var stream = BinaryDataExtensions.SaveToMemoryStream(scrollbar);

            scrollbar.IsActive = false;
            stream.CreateFromMemoryStream();
        }
Пример #11
0
        private static MemoryStream SaveTestMenu()
        {
            var emptyScene = new AutoArrangingMenu(Size.One);
            var data       = BinaryDataExtensions.SaveToMemoryStream(emptyScene);

            data.Seek(0, SeekOrigin.Begin);
            return(data);
        }
Пример #12
0
        public void DrawLoadedSelectBox()
        {
            SetToTenValues();
            var stream = BinaryDataExtensions.SaveToMemoryStream(dropdownList);

            dropdownList.IsActive = false;
            stream.CreateFromMemoryStream();
        }
Пример #13
0
        private static MemoryStream SaveEmptyScene()
        {
            var emptyScene = new Scene();
            var data       = BinaryDataExtensions.SaveToMemoryStream(emptyScene);

            data.Seek(0, SeekOrigin.Begin);
            return(data);
        }
Пример #14
0
        public void SaveAndLoad()
        {
            var stream       = BinaryDataExtensions.SaveToMemoryStream(dialog);
            var loadedDialog = (RadioDialog)stream.CreateFromMemoryStream();

            Assert.AreEqual(3, loadedDialog.Buttons.Count);
            Assert.AreEqual(dialog.Buttons[1].DrawArea, loadedDialog.Buttons[1].DrawArea);
            Assert.AreEqual(dialog.Buttons[1].Text, loadedDialog.Buttons[1].Text);
        }
Пример #15
0
        public void SaveAndLoadGenericType()
        {
            var range       = new Range <Vector2D>(Vector2D.Zero, new Vector2D(3.0f, 3.0f));
            var data        = BinaryDataExtensions.SaveToMemoryStream(range);
            var loadedRange = data.CreateFromMemoryStream() as Range <Vector2D>;

            Assert.AreEqual(range.Start, loadedRange.Start);
            Assert.AreEqual(range.End, loadedRange.End);
        }
Пример #16
0
        public void DrawLoadedPicture()
        {
            picture.IsActive = false;
            picture          = new Picture(new Theme(), material, Rectangle.HalfCentered);
            var stream = BinaryDataExtensions.SaveToMemoryStream(picture);

            picture.IsActive = false;
            stream.CreateFromMemoryStream();
        }
Пример #17
0
        public void SaveAndLoad()
        {
            var stream          = BinaryDataExtensions.SaveToMemoryStream(selectBox);
            var loadedSelectBox = (SelectBox)stream.CreateFromMemoryStream();

            Assert.AreEqual(selectBox.DrawArea, loadedSelectBox.DrawArea);
            Assert.AreEqual(3, loadedSelectBox.Values.Count);
            Assert.AreEqual(selectBox.Values[1].ToString(), loadedSelectBox.Values[1].ToString());
        }
Пример #18
0
        public void SaveAndLoadInfoMessage()
        {
            var info       = new LogInfoMessage("A test info message");
            var data       = BinaryDataExtensions.SaveToMemoryStream(info);
            var loadedInfo = data.CreateFromMemoryStream() as LogInfoMessage;

            Assert.AreEqual(info.Text, loadedInfo.Text);
            Assert.AreEqual(info.TimeStamp, loadedInfo.TimeStamp);
        }
Пример #19
0
        public void SaveAndLoad()
        {
            var stream      = BinaryDataExtensions.SaveToMemoryStream(label);
            var loadedLabel = (Label)stream.CreateFromMemoryStream();

            Assert.AreEqual(Rectangle.FromCenter(0.5f, 0.5f, 0.3f, 0.1f), loadedLabel.DrawArea);
            Assert.AreEqual("Hello World", loadedLabel.Text);
            Assert.AreEqual(label.children.Count, loadedLabel.children.Count);
        }
Пример #20
0
        public void DrawLoadedLabel()
        {
            label.Text = "Original";
            var stream      = BinaryDataExtensions.SaveToMemoryStream(label);
            var loadedLabel = (Label)stream.CreateFromMemoryStream();

            loadedLabel.Text     = "Loaded";
            loadedLabel.DrawArea = loadedLabel.DrawArea.Move(0.0f, 0.15f);
        }
Пример #21
0
        public void DrawLoadedFont()
        {
            var text       = new FontText(tahoma, "Original", Top);
            var stream     = BinaryDataExtensions.SaveToMemoryStream(text);
            var loadedText = (FontText)stream.CreateFromMemoryStream();

            loadedText.Text     = "Loaded";
            loadedText.DrawArea = Bottom;
        }
Пример #22
0
        public void DrawLoadedButton()
        {
            button.Text = "Original";
            var stream       = BinaryDataExtensions.SaveToMemoryStream(button);
            var loadedButton = (Button)stream.CreateFromMemoryStream();

            loadedButton.Text     = "Loaded";
            loadedButton.DrawArea = loadedButton.DrawArea.Move(0.0f, 0.15f);
        }
Пример #23
0
        public void SaveAndLoad()
        {
            var stream        = BinaryDataExtensions.SaveToMemoryStream(picture);
            var loadedPicture = (Picture)stream.CreateFromMemoryStream();

            Assert.AreEqual("DeltaEngineLogo", loadedPicture.Material.DiffuseMap.Name);
            Assert.AreEqual("DeltaEngineLogo", loadedPicture.Get <Theme>().SliderPointer.DiffuseMap.Name);
            Assert.AreEqual(Rectangle.HalfCentered, loadedPicture.DrawArea);
        }
Пример #24
0
        public void SaveAndLoad()
        {
            var stream             = BinaryDataExtensions.SaveToMemoryStream(dropdownList);
            var loadedDropdownList = (DropdownList)stream.CreateFromMemoryStream();

            Assert.AreEqual(dropdownList.DrawArea, loadedDropdownList.DrawArea);
            Assert.AreEqual(3, loadedDropdownList.Values.Count);
            Assert.AreEqual(dropdownList.Values[1].ToString(), loadedDropdownList.Values[1].ToString());
        }
Пример #25
0
        public void SaveAndLoadDefaultTheme()
        {
            var theme       = new Theme();
            var stream      = BinaryDataExtensions.SaveToMemoryStream(theme);
            var loadedTheme = (Theme)stream.CreateFromMemoryStream();

            Assert.IsTrue(AreMaterialsEqual(theme.ButtonMouseover, loadedTheme.ButtonMouseover));
            Assert.IsTrue(AreMaterialsEqual(theme.ScrollbarPointer, loadedTheme.ScrollbarPointer));
            Assert.IsTrue(AreMaterialsEqual(theme.TextBoxFocused, loadedTheme.TextBoxFocused));
        }
Пример #26
0
        public void SaveAndLoadParticle2D()
        {
            CreateDataAndEmitter(512, 0.01f, 5);
            var stream = BinaryDataExtensions.SaveToMemoryStream(emitterData);
            var loaded = stream.CreateFromMemoryStream() as ParticleEmitterData;

            File.WriteAllBytes("Test.test", stream.ToArray());
            Assert.AreEqual(685, stream.Length);
            Assert.AreEqual(emitterData.PositionType, loaded.PositionType);
        }
Пример #27
0
        private static Stream SaveMaterial()
        {
            var image    = Create <Image>(new ImageCreationData(new Size(8, 8)));
            var material = new Material(Create <Shader>(
                                            new ShaderCreationData(ShaderFlags.Position2DColoredTextured)), image);
            var data = BinaryDataExtensions.SaveToMemoryStream(material);

            data.Seek(0, SeekOrigin.Begin);
            return(data);
        }
Пример #28
0
        public void SaveAndLoad()
        {
            centerButton.Text = "Original";
            var stream       = BinaryDataExtensions.SaveToMemoryStream(centerButton);
            var loadedButton = (RadioButton)stream.CreateFromMemoryStream();

            loadedButton.Text = "Loaded";
            Assert.AreEqual(Center, loadedButton.DrawArea);
            loadedButton.DrawArea = loadedButton.DrawArea.Move(new Vector2D(0.0f, 0.1f));
        }
Пример #29
0
        public void DrawLoadedTextBox()
        {
            topTextBox.Text        = "Original";
            bottomTextBox.IsActive = false;
            var stream        = BinaryDataExtensions.SaveToMemoryStream(topTextBox);
            var loadedTextBox = (TextBox)stream.CreateFromMemoryStream();

            loadedTextBox.Text     = "Loaded";
            loadedTextBox.DrawArea = loadedTextBox.DrawArea.Move(0.0f, 0.15f);
        }
Пример #30
0
        public void DrawLoadedRadioDialogAttachedToMouse()
        {
            var stream = BinaryDataExtensions.SaveToMemoryStream(dialog);

            dialog.IsActive = false;
            var loadedDialog = (RadioDialog)stream.CreateFromMemoryStream();

            new Command(point => loadedDialog.DrawArea = Rectangle.FromCenter(point,
                                                                              loadedDialog.DrawArea.Size)).Add(new MouseMovementTrigger());
        }