mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-12 05:24:14 -05:00
Update MaterialTest for JsonDictionaryValidator.Deserialize
This commit is contained in:
parent
0eff571b60
commit
27d5a453b7
|
|
@ -1,5 +1,6 @@
|
|||
#pragma warning disable 0649
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -145,9 +146,38 @@ namespace UniJSON
|
|||
DeserializeValue(new EnumTest(), "{\"EnumDefault\":0,\"EnumAsInt\":0,\"EnumAsString\":\"Hoge\",\"EnumAsLowerString\":\"hoge\"}");
|
||||
}
|
||||
|
||||
class DictionaryValue
|
||||
class DictionaryValue: IEquatable<DictionaryValue>
|
||||
{
|
||||
public Dictionary<string, object> Dict;
|
||||
public Dictionary<string, object> Dict = new Dictionary<string, object>();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var rhs = obj as DictionaryValue;
|
||||
if (rhs != null)
|
||||
{
|
||||
return Equals(rhs);
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(DictionaryValue other)
|
||||
{
|
||||
if(Dict==null && other.Dict == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(Dict==null || other.Dict==null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Dict.OrderBy(x => x.Key).SequenceEqual(other.Dict.OrderBy(x => x.Key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ namespace UniJSON
|
|||
public void Deserialize<U, V>(ListTreeNode<U> src, ref V dst)
|
||||
where U : IListTreeItem, IValue<U>
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
src.Deserialize(ref dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -219,10 +219,32 @@ namespace VRM
|
|||
[Test]
|
||||
public void MaterialTest()
|
||||
{
|
||||
var model = new glTF_VRM_Material();
|
||||
var model = new glTF_VRM_Material
|
||||
{
|
||||
floatProperties = new Dictionary<string, float>
|
||||
{
|
||||
{"float", 1.0f}
|
||||
},
|
||||
vectorProperties = new Dictionary<string, float[]>
|
||||
{
|
||||
{"vector", new float[]{0, 1, 2, 3 }}
|
||||
},
|
||||
textureProperties = new Dictionary<string, int>
|
||||
{
|
||||
{"texture", 0}
|
||||
},
|
||||
keywordMap = new Dictionary<string, bool>
|
||||
{
|
||||
{"keyword", true}
|
||||
},
|
||||
tagMap = new Dictionary<string, string>
|
||||
{
|
||||
{"tag", "map"}
|
||||
},
|
||||
};
|
||||
|
||||
var json = model.ToJson();
|
||||
Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{},""vectorProperties"":{},""textureProperties"":{},""keywordMap"":{},""tagMap"":{}}", json);
|
||||
Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{""float"":1},""vectorProperties"":{""vector"":[0,1,2,3]},""textureProperties"":{""texture"":0},""keywordMap"":{""keyword"":true},""tagMap"":{""tag"":""map""}}", json);
|
||||
Debug.Log(json);
|
||||
|
||||
var c = new JsonSchemaValidationContext("")
|
||||
|
|
@ -231,7 +253,12 @@ namespace VRM
|
|||
};
|
||||
var json2 = JsonSchema.FromType<glTF_VRM_Material>().Serialize(model, c);
|
||||
// NOTE: New serializer outputs values which will not be used...
|
||||
Assert.AreEqual(json,json2);
|
||||
Assert.AreEqual(json, json2);
|
||||
|
||||
// deserialize
|
||||
var deserialized = default(glTF_VRM_Material);
|
||||
json.ParseAsJson().Deserialize(ref deserialized);
|
||||
Assert.AreEqual(1, deserialized.floatProperties.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user