예제 #1
0
        public void GenericsSerialize()
        {
            var generics = new GenericTypesContainer <Transform, Rectangle, string>
            {
                Stuff      = new Transform(100, 200, 300, 400, 500),
                StuffTwo   = new Rectangle(1, 2, 3, 4),
                StuffThree = "Dudeee"
            };

            string gen      = XMLFormat.To(generics);
            var    restored = XMLFormat.From <GenericTypesContainer <Transform, Rectangle, string> >(gen);

            Assert.Equal(restored.Stuff.X, 100);
            Assert.Equal(restored.Stuff.Y, 200);
            Assert.Equal(restored.Stuff.Z, 300);
            Assert.Equal(restored.Stuff.Width, 400);
            Assert.Equal(restored.Stuff.Height, 500);

            Assert.Equal(restored.StuffTwo.X, 1);
            Assert.Equal(restored.StuffTwo.Y, 2);
            Assert.Equal(restored.StuffTwo.Width, 3);
            Assert.Equal(restored.StuffTwo.Height, 4);

            Assert.Equal(restored.StuffThree, "Dudeee");
        }
예제 #2
0
        public void XMLFormat_Equals_Test2()
        {
            XMLFormat xml  = new XMLFormat(new XMLFormatInitializerTest2());
            XMLFormat xml2 = new XMLFormat();

            xml2.SetRoot("deo");
            xml2.Append(0, new XMLFormat.DirNode {
                id = 36, name = "sek"
            });
            xml2.Append(0, new XMLFormat.FileNode {
                id = 121, name = "try"
            });
            xml2.Append(36, new XMLFormat.DirNode {
                id = 99, name = "uig"
            });
            xml2.Append(36, new XMLFormat.FileNode {
                id = 2092, name = "qvg"
            });
            xml2.Append(99, new XMLFormat.FileNode {
                id = 370, name = "xoj"
            });

            Boolean isEqual = xml.Equals(xml2);

            Assert.True(isEqual);
        }
예제 #3
0
        public void ComplexTypeWithCustomDefaults()
        {
            string xml = XMLFormat.To(new CustomDefaultsComplex
            {
                Test      = TestEnum.A,
                Number    = 0,
                Bool      = false,
                Str       = "",
                Rect      = new Rectangle(),
                Transform = null,
                Array     = null,
                Inherited = null,
                Nullable  = null
            });
            var restored = XMLFormat.From <CustomDefaultsComplex>(xml);

            Assert.Equal(restored.Test, TestEnum.A);
            Assert.Equal(restored.Number, 0);
            Assert.Equal(restored.Bool, false);
            Assert.Equal(restored.Str, "");
            Assert.Equal(restored.Rect.X, 0);
            Assert.True(restored.Transform == null);
            Assert.True(restored.Array == null);
            Assert.True(restored.Inherited == null);
            Assert.True(restored.Nullable == null);
        }
예제 #4
0
        public void StringSanitizeSerialize()
        {
            string str      = XMLFormat.To("Test test <<<:O<< Whaaa");
            var    restored = XMLFormat.From <string>(str);

            Assert.Equal(restored, "Test test <<<:O<< Whaaa");
        }
예제 #5
0
        static void Main(string[] args)
        {
#if false
            if (args.Contains("--nogui"))
            {
                NoGuiMode(args);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new YAMTForm());
#endif

            // ----------------------------------------------------
            // BEGIN TEST MODE
            // ----------------------------------------------------

            JSONParser json = new JSONParser();

            if (!json.Parse(@"yatpproto_def.json"))
            {
                throw new Exception("JSON error");
            }

            uint[] keys =
            {
                173217,
                72619434,
                408587239,
                27973291
            };

            //XMLFormat src = new XMLFormat();
            LZOFormat src = new LZOFormat(keys, false);
            XMLFormat dst = new XMLFormat();

            if (!src.Initialize(@"item_proto", false))
            {
                throw new Exception("SRC init error");
            }

            if (!dst.Initialize(@"yamttest.xml", true))
            {
                throw new Exception("DST init error");
            }

            ProtoFactory.ProcessItemProto(json, src, dst);

            if (!src.Finalize())
            {
                throw new Exception("SRC end error");
            }

            if (!dst.Finalize())
            {
                throw new Exception("DST end error");
            }
        }
예제 #6
0
        public void XMLFormat_GetNode_Test1()
        {
            XMLFormat xml = new XMLFormat(new XMLFormatInitializerTest1());

            var node = xml.GetNode(12);

            Assert.AreEqual("news", node.name);
        }
예제 #7
0
        public void XMLFormat_ToString_Test2()
        {
            XMLFormat xml = new XMLFormat(new XMLFormatInitializerTest2());

            String res = xml.ToString();

            Assert.True(true);
        }
예제 #8
0
        public void XMLFormat_GetNode_Test4()
        {
            XMLFormat xml = new XMLFormat(new XMLFormatInitializerTest2());

            var node = xml.GetNode(99);

            Assert.AreEqual("uig", node.name);
        }
예제 #9
0
        public void BasicValueType()
        {
            string v2       = XMLFormat.To(new Vector2(100, 100));
            var    restored = XMLFormat.From <Vector2>(v2);

            Assert.Equal(restored.X, 100);
            Assert.Equal(restored.Y, 100);
        }
예제 #10
0
        public void ComplexType()
        {
            string p        = XMLFormat.To(new Positional(100, 200, 300));
            var    restored = XMLFormat.From <Positional>(p);

            Assert.Equal(restored.X, 100);
            Assert.Equal(restored.Y, 200);
            Assert.Equal(restored.Z, 300);
        }
예제 #11
0
        /// <summary>
        /// Save the save file to the asset store.
        /// </summary>
        public void Save()
        {
            string data = XMLFormat.To(Content);

            if (!Engine.AssetLoader.Save(Encoding.UTF8.GetBytes(data), Name))
            {
                Engine.Log.Warning($"Couldn't save file {Name}.", MessageSource.Other);
            }
        }
예제 #12
0
        public void XMLFormat_ToString_Test1()
        {
            XMLFormat xml          = new XMLFormat(new XMLFormatInitializerTest1());
            String    estimatedRes = "<dir name='site' id='0'>\n  <file name='news' id='12'/>\n</dir>\n";

            Boolean isEqual = xml.ToString() == estimatedRes;

            Assert.True(isEqual);
        }
예제 #13
0
        public void BasicStringNull()
        {
            string str = XMLFormat.To(new StringContainer {
                Test = null
            });
            var restored = XMLFormat.From <StringContainer>(str);

            Assert.True(restored.Test == null);
        }
예제 #14
0
    public void Init(AFormat format)
    {
        XMLFormat xml = (XMLFormat)format;

        xml.SetRoot("site");
        xml.Append(0, new XMLFormat.FileNode {
            id = 12, name = "news"
        });
    }
예제 #15
0
        public void BasicString()
        {
            string str = XMLFormat.To(new StringContainer {
                Test = "Hello"
            });
            var restored = XMLFormat.From <StringContainer>(str);

            Assert.Equal(restored.Test, "Hello");
        }
예제 #16
0
    public AFormat Transform(AFormat aFormat)
    {
        find = (FindFormat)aFormat;
        xml  = new XMLFormat();
        xml.SetRoot(find.GetPath(0));
        var root = (DirNode)xml.GetNode(0);

        FindSubNodesAndAppend(root, 1, root.name);
        return(xml);
    }
예제 #17
0
        public void ComplexValueType()
        {
            string r        = XMLFormat.To(new Rectangle(100, 100, 200, 200));
            var    restored = XMLFormat.From <Rectangle>(r);

            Assert.Equal(restored.X, 100);
            Assert.Equal(restored.Y, 100);
            Assert.Equal(restored.Width, 200);
            Assert.Equal(restored.Height, 200);
        }
예제 #18
0
        public void ComplexInheritedType()
        {
            string t        = XMLFormat.To(new Transform(100, 200, 300, 400, 500));
            var    restored = XMLFormat.From <Transform>(t);

            Assert.Equal(restored.X, 100);
            Assert.Equal(restored.Y, 200);
            Assert.Equal(restored.Z, 300);
            Assert.Equal(restored.Width, 400);
            Assert.Equal(restored.Height, 500);
        }
예제 #19
0
 public override Boolean Equals(Object obj)
 {
     return(EqualityComparerHelper(this, obj, () => {
         if (root != null)
         {
             XMLFormat xml = (XMLFormat)obj;
             return root.Equals(xml.root);
         }
         return false;
     }));
 }
예제 #20
0
        /// <summary>
        /// Save the file to the asset store with the provided name.
        /// </summary>
        public bool SaveAs(string name, bool backup = true)
        {
            string data  = XMLFormat.To(Content);
            bool   saved = Engine.AssetLoader.Save(Encoding.UTF8.GetBytes(data), name, backup);

            if (!saved)
            {
                Engine.Log.Warning($"Couldn't save file {name}.", MessageSource.Other);
            }
            return(saved);
        }
예제 #21
0
 protected override void CreateInternal(byte[] data)
 {
     try
     {
         Content = XMLFormat.From <T>(data);
     }
     catch (Exception ex)
     {
         Engine.Log.Error(new Exception($"Couldn't parse XML asset of type {GetType()}!", ex));
     }
 }
예제 #22
0
        public void ComplexTypeExcludedProperties()
        {
            var classWithExcluded = new ClassWithExcluded {
                NotMe = true, Me = true
            };
            string ex = XMLFormat.To(classWithExcluded);

            var restored = XMLFormat.From <ClassWithExcluded>(ex);

            Assert.True(restored.Me);
            Assert.False(restored.NotMe);
        }
예제 #23
0
        public void NullableTrivialNull()
        {
            var nullableTrivial = new NullableTrivialContainer
            {
                Number = null
            };

            string nul      = XMLFormat.To(nullableTrivial);
            var    restored = XMLFormat.From <NullableTrivialContainer>(nul);

            Assert.True(restored.Number == null);
        }
예제 #24
0
        public void EnumSerialize()
        {
            var enumContainer = new EnumContainer
            {
                Hello = TestEnum.Test
            };

            string enm      = XMLFormat.To(enumContainer);
            var    restored = XMLFormat.From <EnumContainer>(enm);

            Assert.Equal(restored.Hello, TestEnum.Test);
        }
예제 #25
0
        public void NullableComplex()
        {
            var nullableComplex = new NullableComplexContainer
            {
                Stuff = new ComplexNullableSubject
                {
                    Number = 1
                }
            };

            string nul      = XMLFormat.To(nullableComplex);
            var    restored = XMLFormat.From <NullableComplexContainer>(nul);

            Assert.True(restored.Stuff != null);
            // ReSharper disable once PossibleInvalidOperationException
            Assert.Equal(restored.Stuff.Value.Number, 1);

            nullableComplex = new NullableComplexContainer
            {
                Stuff = new ComplexNullableSubject
                {
                    Number = 0
                }
            };

            nul      = XMLFormat.To(nullableComplex);
            restored = XMLFormat.From <NullableComplexContainer>(nul);
            Assert.True(restored.Stuff != null);
            // ReSharper disable once PossibleInvalidOperationException
            Assert.Equal(restored.Stuff.Value.Number, 0);

            nullableComplex = new NullableComplexContainer
            {
                Stuff = new ComplexNullableSubject()
            };

            nul      = XMLFormat.To(nullableComplex);
            restored = XMLFormat.From <NullableComplexContainer>(nul);
            Assert.True(restored.Stuff != null);
            // ReSharper disable once PossibleInvalidOperationException
            Assert.Equal(restored.Stuff.Value.Number, 0);

            nullableComplex = new NullableComplexContainer
            {
                Stuff = null
            };

            nul      = XMLFormat.To(nullableComplex);
            restored = XMLFormat.From <NullableComplexContainer>(nul);
            Assert.True(restored.Stuff == null);
        }
예제 #26
0
        public void ComplexTypeRecursiveReferenceError()
        {
            var transformLink = new TransformRecursiveRef {
                X = 100
            };

            transformLink.Other = transformLink;
            string re = XMLFormat.To(transformLink);

            var restored = XMLFormat.From <TransformRecursiveRef>(re);

            Assert.Equal(restored.X, 100);
            Assert.True(restored.Other == null);
        }
예제 #27
0
        public void XMLFormatInitializerTest1()
        {
            XMLFormat xml  = new XMLFormat(new XMLFormatInitializerTest1());
            XMLFormat xml2 = new XMLFormat();

            xml2.SetRoot("site");
            xml2.Append(0, new XMLFormat.FileNode {
                id = 12, name = "news"
            });

            Boolean isEqual = xml.Equals(xml2);

            Assert.True(isEqual);
        }
예제 #28
0
        private void RenderSaveSection()
        {
            // Saving
            ImGui.InputText("Name", ref _saveName, 100);
            ImGui.SameLine();
            if (string.IsNullOrEmpty(_saveName))
            {
                ImGui.TextDisabled("Save");
                ImGui.SameLine();
                ImGui.TextDisabled("SaveToFile");
            }
            else
            {
                ImGui.SameLine();
                if (!ImGui.Button("SaveToFile"))
                {
                    return;
                }
                string saveName = _saveName;
                if (!saveName.Contains(".anim"))
                {
                    saveName += ".anim";
                }
                if (!saveName.Contains("Player/"))
                {
                    saveName = $"Player/{saveName}";
                }

                try
                {
                    string saveData;
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (_animController != null)
                    {
                        saveData = XMLFormat.To(_animController);
                    }
                    else
                    {
                        saveData = XMLFormat.To(_animation);
                    }

                    Engine.AssetLoader.Save(Encoding.UTF8.GetBytes(saveData), saveName);
                }
                catch (Exception ex)
                {
                    Engine.Log.Error(ex);
                }
            }
        }
예제 #29
0
        public void DeserializeDontSerialize()
        {
            string document = "" +
                              "<TypeWithExcludedMembersDirectParent>\n" +
                              "<GrandparentBool>true</GrandparentBool>\n" +
                              "<ExcludedInheritedField>Hi</ExcludedInheritedField>\n" +
                              "</TypeWithExcludedMembersDirectParent>";
            var memberExcluded = XMLFormat.From <TypeWithExcludedMembersDirectParent>(document);

            Assert.False(memberExcluded.GrandparentBool);              // Excluded member is not deserialized.
            Assert.Equal(memberExcluded.ExcludedInheritedField, "Hi"); // Following fields should be deserialized though.

            document = "<ClassWithExcluded>\n<NotMe>true</NotMe>\n<Me>true</Me>\n</ClassWithExcluded>";
            var memberDontSerialize = XMLFormat.From <ClassWithExcluded>(document);

            Assert.False(memberDontSerialize.NotMe); // DontSerialize is not deserialized.
            Assert.True(memberDontSerialize.Me);

            document = "<ClassWithExcludedComplexType>\n" +
                       "    <A>\n" +
                       "        <NotMe>true</NotMe>\n" +
                       "        <Me>true</Me>\n" +
                       "    </A>\n" +
                       "    <B>\n" +
                       "        <NotMe>true</NotMe>\n" +
                       "        <Me>true</Me>\n" +
                       "    </B>\n" +
                       "</ClassWithExcludedComplexType>";
            var complexExcludedDeserialize = XMLFormat.From <ClassWithExcludedComplexType>(document);

            Assert.True(complexExcludedDeserialize.A == null); // Shouldn't have been deserialized.
            Assert.True(complexExcludedDeserialize.B != null);
            Assert.True(complexExcludedDeserialize.B.Me);
            Assert.False(complexExcludedDeserialize.B.NotMe);

            document = "<ClassWithExcludedComplexType>\n" +
                       "    <A>\n" +
                       "        <NotMe>true</NotMe>\n" +
                       "        <Me>true</Me>\n" +
                       "    <B>\n" +
                       "        <NotMe>true</NotMe>\n" +
                       "        <Me>true</Me>\n" +
                       "    </B>\n" +
                       "</ClassWithExcludedComplexType>";
            var brokenDocument = XMLFormat.From <ClassWithExcludedComplexType>(document);

            Assert.True(brokenDocument.A == null);
            Assert.True(brokenDocument.B == null);
        }
예제 #30
0
        public void XMLFormat_Append_Test1()
        {
            XMLFormat xml = new XMLFormat();

            xml.SetRoot("a");

            xml.Append(0, new XMLFormat.FileNode()
            {
                name = "b", id = 1
            });

            var node = xml.GetNode(1);

            Assert.True(node.name == "b");
        }