public void BinaryDefaultValue() { // Output registry var registry = new UTinyRegistry(); using (var binary = new MemoryStream()) using (var command = new MemoryStream()) { Debug.Log(Serialization.FlatJson.BackEnd.Persist(m_EnumType, m_ComponentType, m_Entity)); // Write our data to binary Serialization.Binary.BackEnd.Persist(binary, m_EnumType, m_ComponentType, m_Entity); binary.Position = 0; // Read from binary to command stream Serialization.Binary.FrontEnd.Accept(binary, command); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertDefaultValue(registry); }
public void FlatJsonOverrideValue() { // Output registry var registry = new UTinyRegistry(); var component = m_Entity.GetComponent((UTinyType.Reference)m_ComponentType); component["TestEnumField"] = new UTinyEnum.Reference(m_EnumType, 3); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { // Write our data to json Serialization.FlatJson.BackEnd.Persist(json, m_EnumType, m_ComponentType, m_Entity); json.Position = 0; // Read from json to command stream Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertOverrideValue(registry); }
public void FlatJsonDefaultValues() { // Output registry var registry = new UTinyRegistry(); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { Debug.Log(Serialization.FlatJson.BackEnd.Persist(m_ComponentType, m_DefaultEntity, m_OverridenEntity)); // Write our data to binary Serialization.FlatJson.BackEnd.Persist(json, m_ComponentType, m_DefaultEntity, m_OverridenEntity); json.Position = 0; // Read from binary to command stream Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertSerializationDefaultValues(registry); }
public void NestedSourceScope() { var registry = new UTinyRegistry(); var builtInCount = registry.Count; var sourceId = "outer"; var nestedSourceId = "inner"; UTinyType testType, testType2; using (registry.SourceIdentifierScope(sourceId)) { testType = registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Component); using (registry.SourceIdentifierScope(nestedSourceId)) { testType2 = registry.CreateType(UTinyId.New(), "TestType2", UTinyTypeCode.Component); } } var testTypeRef = (UTinyType.Reference)testType; var testType2Ref = (UTinyType.Reference)testType2; Assert.AreEqual(builtInCount + 2, registry.Count); registry.UnregisterAllBySource(sourceId); Assert.AreEqual(builtInCount + 1, registry.Count); Assert.IsNull(testTypeRef.Dereference(registry)); Assert.IsNotNull(testType2Ref.Dereference(registry)); registry.UnregisterAllBySource(nestedSourceId); Assert.AreEqual(builtInCount, registry.Count); Assert.IsNull(testTypeRef.Dereference(registry)); Assert.IsNull(testType2Ref.Dereference(registry)); }
public void FlatJsonStructListValue() { // Output registry var registry = new UTinyRegistry(); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { Serialization.FlatJson.BackEnd.Persist(json, m_StructType, m_StructArrayComponentType, m_StructArrayEntity); json.Position = 0; var reader = new StreamReader(json); { UnityEngine.Debug.Log(reader.ReadToEnd()); } json.Position = 0; Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; Serialization.CommandStream.FrontEnd.Accept(command, registry); } }
public void AssetSerializationTest() { // Create some asset on disc File.WriteAllBytes(Application.dataPath + "/TestTexture.png", new Texture2D(32, 32).EncodeToPNG()); AssetDatabase.ImportAsset("Assets/TestTexture.png"); m_Texture2D = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/TestTexture.png"); // Reference the asset in the module m_Module.AddAsset(m_Texture2D); Debug.Log(m_Module); var registry = new UTinyRegistry(); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { // Write the module to the stream Serialization.FlatJson.BackEnd.Persist(json, m_Module); json.Position = 0; Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; Serialization.CommandStream.FrontEnd.Accept(command, registry); } var module = registry.FindById <UTinyModule>(m_Module.Id); Debug.Log(module); var path = AssetDatabase.GetAssetPath(m_Texture2D); AssetDatabase.DeleteAsset(path); }
public void ObjectListVersionChange() { var registry = new UTinyRegistry(); var type = registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Struct); type.CreateField("TestField", (UTinyType.Reference)UTinyType.Int32); var list = new UTinyList(registry, (UTinyType.Reference)type) { new UTinyObject(registry, (UTinyType.Reference)type) { ["TestField"] = 1 }, new UTinyObject(registry, (UTinyType.Reference)type) { ["TestField"] = 2 }, new UTinyObject(registry, (UTinyType.Reference)type) { ["TestField"] = 3 } }; var version = list.Version; (list[0] as UTinyObject)["TestField"] = 7; Assert.AreNotEqual(version, list.Version); Debug.Log(list); }
public void BinaryObjectValue() { // Output registry var registry = new UTinyRegistry(); var component = m_Entity.GetComponent((UTinyType.Reference)m_ComponentType); component["TestTexture2DField"] = m_Texture2D; Assert.AreEqual(m_Texture2D, component["TestTexture2DField"]); using (var binary = new MemoryStream()) using (var command = new MemoryStream()) { // Write our data to binary Serialization.Binary.BackEnd.Persist(binary, m_ComponentType, m_Entity); binary.Position = 0; // Read from binary to command stream Serialization.Binary.FrontEnd.Accept(binary, command); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertObjectValue(registry); }
public void TypeInitialDefaultValue() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); type.CreateField( "TestIntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField( "TestFloatField", (UTinyType.Reference)UTinyType.Float32); var defaultValue = type.DefaultValue as UTinyObject; // Assert that we have some default value object that has been created for us Assert.IsNotNull(defaultValue); // Test the existance and value of the fields Assert.AreEqual(0, defaultValue["TestIntField"]); Assert.AreEqual(0f, defaultValue["TestFloatField"]); }
public void FlatJsonObjectValue() { var component = m_Entity.GetComponent((UTinyType.Reference)m_ComponentType); component["TestTexture2DField"] = null; component["TestTexture2DField"] = m_Texture2D; Assert.AreEqual(m_Texture2D, component["TestTexture2DField"]); // Output registry var registry = new UTinyRegistry(); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { Serialization.FlatJson.BackEnd.Persist(json, m_ComponentType, m_Entity); json.Position = 0; var reader = new StreamReader(json); Debug.Log(reader.ReadToEnd()); json.Position = 0; Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertObjectValue(registry); }
public void EnumDefaultValue() { var registry = new UTinyRegistry(); var enumType = registry.CreateType(UTinyId.New(), "TestEnum", UTinyTypeCode.Enum); enumType.BaseType = (UTinyType.Reference)UTinyType.Int32; enumType.CreateField("A", (UTinyType.Reference)UTinyType.Int32); enumType.CreateField("B", (UTinyType.Reference)UTinyType.Int32); enumType.CreateField("C", (UTinyType.Reference)UTinyType.Int32); enumType.DefaultValue = new UTinyObject(registry, (UTinyType.Reference)enumType) { ["A"] = 1, ["B"] = 2, ["C"] = 3, }; var structType = registry.CreateType(UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); structType.CreateField("EnumField", (UTinyType.Reference)enumType); structType.DefaultValue = new UTinyObject(registry, (UTinyType.Reference)structType) { ["EnumField"] = new UTinyEnum.Reference(enumType, "B") }; var instance = new UTinyObject(registry, (UTinyType.Reference)structType); Assert.AreEqual(2, ((UTinyEnum.Reference)instance["EnumField"]).Value); Assert.AreEqual("B", ((UTinyEnum.Reference)instance["EnumField"]).Name); }
public void FieldTest() { var registry = new UTinyRegistry(); var @enum = registry.CreateType( UTinyId.New(), "TestEnum", UTinyTypeCode.Enum ); @enum.BaseType = (UTinyType.Reference)UTinyType.Int32; @enum.CreateField("A", (UTinyType.Reference)UTinyType.Int32); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct ); type.CreateField( "TextureReference", (UTinyType.Reference)UTinyType.Texture2DEntity); type.CreateField( "EntityReference", (UTinyType.Reference)UTinyType.EntityReference); type.CreateField( "EnumReference", (UTinyType.Reference)@enum); type.Refresh(); Debug.Log(type); }
public void ListFieldPrimitiveAssignment() { var registry = new UTinyRegistry(); var type = registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Struct); type.CreateField("TestField", (UTinyType.Reference)UTinyType.Int32, true); var instance = new UTinyObject(registry, (UTinyType.Reference)type) { ["TestField"] = new UTinyList(registry, (UTinyType.Reference)UTinyType.Int32) { 1, 2, 3 } }; instance["TestField"] = new UTinyList(registry, (UTinyType.Reference)UTinyType.Int32) { 3, 6, 7 }; Debug.Log(instance); }
public void FlatJsonEntityRoundTrip() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestType", UTinyTypeCode.Component ); type.CreateField("TestIntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("TestStringField", (UTinyType.Reference)UTinyType.String); var entity = registry.CreateEntity( UTinyId.New(), "TestEntity"); var component = entity.AddComponent((UTinyType.Reference)type); component.Refresh(); component["TestIntField"] = 10; component["TestStringField"] = "Test"; using (var json = new MemoryStream()) using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> json Serialization.FlatJson.BackEnd.Persist(json, type, entity); json.Position = 0; var reader = new StreamReader(json); { Debug.Log(reader.ReadToEnd()); } json.Position = 0; // Read the data model // json -> commands Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem Serialization.CommandStream.FrontEnd.Accept(command, output); } }
public void FlatJsonRoundTrip() { var input = new UTinyRegistry(); var structType = input.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); structType.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32); structType.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32); structType.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32); var module = input.CreateModule( UTinyId.New(), "TestModule"); module.AddStructReference((UTinyType.Reference)structType); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> json Serialization.FlatJson.BackEnd.Persist(json, structType, module); json.Position = 0; var reader = new StreamReader(json); { Debug.Log(reader.ReadToEnd()); } json.Position = 0; // Read the data model // json -> commands Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem Serialization.CommandStream.FrontEnd.Accept(command, output); Assert.IsNotNull(output.FindById <UTinyType>(structType.Id)); Assert.IsNotNull(output.FindById <UTinyModule>(module.Id)); } }
public void FlatJsonProjectWrite() { var registry = new UTinyRegistry(); var project = registry.CreateProject( UTinyId.New(), "TestProject"); var json = Serialization.FlatJson.BackEnd.Persist(project); Debug.Log(json); }
public void PrimitiveList() { var registry = new UTinyRegistry(); var list = new UTinyList(registry, (UTinyType.Reference)UTinyType.Int32) { 1, 2, 3 }; Assert.AreEqual(3, list.Count); Debug.Log(list); }
public void Clear() { var registry = new UTinyRegistry(); var builtInCount = registry.Count; var type = registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Component); var typeRef = (UTinyType.Reference)type; Assert.AreEqual(builtInCount + 1, registry.Count); registry.Clear(); Assert.AreEqual(builtInCount, registry.Count); Assert.IsNull(typeRef.Dereference(registry)); }
public void Register() { var registry = new UTinyRegistry(); var builtInCount = registry.Count; var type = registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Component); Assert.AreEqual(builtInCount + 1, registry.Count); registry.Register(type); Assert.AreEqual(builtInCount + 1, registry.Count); registry.Unregister(type); Assert.AreEqual(builtInCount, registry.Count); }
public void SourceScope() { var registry = new UTinyRegistry(); var builtInCount = registry.Count; var sourceId = "test"; using (registry.SourceIdentifierScope(sourceId)) { registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Component); } Assert.AreEqual(builtInCount + 1, registry.Count); registry.UnregisterAllBySource(sourceId); Assert.AreEqual(builtInCount, registry.Count); }
public void StructType() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct ); type.CreateField( "TestField", (UTinyType.Reference)UTinyType.Int32); Assert.AreEqual(type.Fields.Count, 1); }
public void NestedTypeInitialDefaultValue() { var registry = new UTinyRegistry(); // Create a struct with a single int field var structType = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); structType.CreateField( "TestIntField", (UTinyType.Reference)UTinyType.Int32); // Default the TestStruct.IntField to 7 structType.DefaultValue = new UTinyObject(registry, (UTinyType.Reference)structType) { ["TestIntField"] = 7 }; // Create a component with a single TestStruct field var componentType = registry.CreateType( UTinyId.New(), "TestComponent", UTinyTypeCode.Component); componentType.CreateField( "TestStructField", (UTinyType.Reference)structType); // Grab the default value for TestComponent var testComponentDefaultValue = componentType.DefaultValue as UTinyObject; Assert.IsNotNull(testComponentDefaultValue); // Grab the TestComponent.TestStructField FIELD defaultValue // NOTE: This is NOT the same as the TestStruct TYPE defaultValue var testComponentTestStructFieldDefaultValue = testComponentDefaultValue["TestStructField"] as UTinyObject; Assert.IsNotNull(testComponentTestStructFieldDefaultValue); Assert.AreNotEqual(testComponentDefaultValue, testComponentTestStructFieldDefaultValue); // This value should have been inherited from the type level but CAN be overriden Assert.AreEqual(7, testComponentTestStructFieldDefaultValue["TestIntField"]); }
public void FlatJsonTypeWrite() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); type.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32); var json = Serialization.FlatJson.BackEnd.Persist(type); Debug.Log(json); }
public void FlatJsonSceneWrite() { var registry = new UTinyRegistry(); var entityGroup = registry.CreateEntityGroup( UTinyId.New(), "TestEntityGroup"); var entity = registry.CreateEntity( UTinyId.New(), "TestEntity"); entityGroup.AddEntityReference((UTinyEntity.Reference)entity); var json = Serialization.FlatJson.BackEnd.Persist(entityGroup, entity); Debug.Log(json); }
public void CommandStreamDefaultValues() { // Output registry var registry = new UTinyRegistry(); using (var command = new MemoryStream()) { // Write from memory directly to the command stream Serialization.CommandStream.BackEnd.Persist(command, m_ComponentType, m_DefaultEntity, m_OverridenEntity); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertSerializationDefaultValues(registry); }
public void CommandStreamDefaultValue() { // Output registry var registry = new UTinyRegistry(); using (var command = new MemoryStream()) { // Write our data to command stream Serialization.CommandStream.BackEnd.Persist(command, m_EnumType, m_ComponentType, m_Entity); command.Position = 0; // Read from command stream to registry Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertDefaultValue(registry); }
public void ResetObjectToDefaultValues() { var registry = new UTinyRegistry(); // Create a type var type = registry.CreateType( UTinyId.New(), "TestStructType", UTinyTypeCode.Struct); type.CreateField( "TestIntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField( "TestFloatField", (UTinyType.Reference)UTinyType.Float32); // Default the TestStruct.IntField to 7 and FloatField to 0.5f type.DefaultValue = new UTinyObject(registry, (UTinyType.Reference)type) { ["TestIntField"] = 7, ["TestFloatField"] = 0.5f }; var @object = new UTinyObject(registry, (UTinyType.Reference)type); Assert.AreEqual(7, @object["TestIntField"]); Assert.AreEqual(0.5f, @object["TestFloatField"]); @object["TestIntField"] = 1; @object["TestFloatField"] = 7.9f; Assert.AreEqual(1, @object["TestIntField"]); Assert.AreEqual(7.9f, @object["TestFloatField"]); @object.Reset(); Assert.AreEqual(7, @object["TestIntField"]); Assert.AreEqual(0.5f, @object["TestFloatField"]); }
public void BinaryListValue() { // Output registry var registry = new UTinyRegistry(); using (var binary = new MemoryStream()) using (var command = new MemoryStream()) { Serialization.Binary.BackEnd.Persist(binary, m_IntArrayComponentType, m_IntArrayEntity); binary.Position = 0; Serialization.Binary.FrontEnd.Accept(binary, command); command.Position = 0; Serialization.CommandStream.FrontEnd.Accept(command, registry); } AssertListValue(registry); }
public void StreamingRoundTrip() { var input = new UTinyRegistry(); var type = input.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); type.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32); var module = input.CreateModule( UTinyId.New(), "TestModule"); module.AddStructReference((UTinyType.Reference)type); using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> command BackEnd.Persist(command, type, module); command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem FrontEnd.Accept(command, output); Assert.IsNotNull(output.FindById <UTinyType>(type.Id)); Assert.IsNotNull(output.FindById <UTinyModule>(module.Id)); } }
public void NameChangeTest() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct ); var module = registry.CreateModule( UTinyId.New(), "TestModule" ); module.AddStructReference((UTinyType.Reference)type); module.Refresh(); type.Name = "NewStruct"; Debug.Log(module.ToString()); }