@@ -8,7 +8,7 @@ namespace FixedMathSharp.Unity.Tests
88{
99 public sealed class FixedSerializationPersistenceTests
1010 {
11- private const string TestAssetFolder = "Assets/Packages/Tests/EditMode/ GeneratedSerializationPersistenceTests" ;
11+ private const string TestAssetFolder = "Assets/GeneratedSerializationPersistenceTests" ;
1212
1313 private static readonly FixedSerializationProbeSnapshot ExpectedSnapshot = new ( )
1414 {
@@ -20,25 +20,20 @@ public sealed class FixedSerializationPersistenceTests
2020 Fixed64 . FromRaw ( 0x33333333 ) ,
2121 Fixed64 . FromRaw ( 0x44444444 ) ,
2222 Fixed64 . FromRaw ( 0x55555555 ) ) ,
23- NestedValue = new FixedSerializationNestedProbe
24- {
25- Value = Fixed64 . FromRaw ( 0x66666666 )
26- } ,
27- ListValue = new FixedSerializationListProbe
28- {
29- Value = Fixed64 . FromRaw ( 0x77777777 ) ,
30- Position = new Vector3d (
31- Fixed64 . FromRaw ( 0x11112222 ) ,
32- Fixed64 . FromRaw ( 0x33334444 ) ,
33- Fixed64 . FromRaw ( 0x55556666 ) )
34- }
23+ NestedValue = Fixed64 . FromRaw ( 0x66666666 ) ,
24+ ListCount = 1 ,
25+ ListValue = Fixed64 . FromRaw ( 0x77777777 ) ,
26+ ListPosition = new Vector3d (
27+ Fixed64 . FromRaw ( 0x11112222 ) ,
28+ Fixed64 . FromRaw ( 0x33334444 ) ,
29+ Fixed64 . FromRaw ( 0x55556666 ) )
3530 } ;
3631
3732 [ SetUp ]
3833 public void SetUp ( )
3934 {
4035 DeleteTestAssets ( ) ;
41- AssetDatabase . CreateFolder ( "Assets/Packages/Tests/EditMode " , "GeneratedSerializationPersistenceTests" ) ;
36+ AssetDatabase . CreateFolder ( "Assets" , "GeneratedSerializationPersistenceTests" ) ;
4237 }
4338
4439 [ TearDown ]
@@ -52,7 +47,7 @@ public void ScriptableObjectSaveReload_PreservesFixedMathSharpValues()
5247 {
5348 string assetPath = $ "{ TestAssetFolder } /FixedSerializationProbe.asset";
5449 FixedSerializationScriptableProbe asset = ScriptableObject . CreateInstance < FixedSerializationScriptableProbe > ( ) ;
55- asset . SetSnapshot ( ExpectedSnapshot ) ;
50+ SetSnapshot ( asset , ExpectedSnapshot ) ;
5651
5752 AssetDatabase . CreateAsset ( asset , assetPath ) ;
5853 AssetDatabase . SaveAssets ( ) ;
@@ -64,7 +59,7 @@ public void ScriptableObjectSaveReload_PreservesFixedMathSharpValues()
6459 FixedSerializationScriptableProbe reloaded = AssetDatabase . LoadAssetAtPath < FixedSerializationScriptableProbe > ( assetPath ) ;
6560
6661 Assert . That ( reloaded , Is . Not . Null ) ;
67- AssertSnapshotEqual ( reloaded . GetSnapshot ( ) , ExpectedSnapshot ) ;
62+ AssertSnapshotEqual ( GetSnapshot ( reloaded ) , ExpectedSnapshot ) ;
6863 }
6964
7065 [ Test ]
@@ -75,7 +70,7 @@ public void ScriptableObjectEditSaveReload_PreservesFixedMathSharpValues()
7570 AssetDatabase . CreateAsset ( asset , assetPath ) ;
7671 AssetDatabase . SaveAssets ( ) ;
7772
78- asset . SetSnapshot ( ExpectedSnapshot ) ;
73+ SetSnapshot ( asset , ExpectedSnapshot ) ;
7974 EditorUtility . SetDirty ( asset ) ;
8075 AssetDatabase . SaveAssets ( ) ;
8176 Resources . UnloadAsset ( asset ) ;
@@ -86,15 +81,15 @@ public void ScriptableObjectEditSaveReload_PreservesFixedMathSharpValues()
8681 FixedSerializationScriptableProbe reloaded = AssetDatabase . LoadAssetAtPath < FixedSerializationScriptableProbe > ( assetPath ) ;
8782
8883 Assert . That ( reloaded , Is . Not . Null ) ;
89- AssertSnapshotEqual ( reloaded . GetSnapshot ( ) , ExpectedSnapshot ) ;
84+ AssertSnapshotEqual ( GetSnapshot ( reloaded ) , ExpectedSnapshot ) ;
9085 }
9186
9287 [ Test ]
9388 public void PrefabSaveReload_PreservesFixedMathSharpValues ( )
9489 {
9590 string prefabPath = $ "{ TestAssetFolder } /FixedSerializationProbe.prefab";
9691 GameObject source = new ( "Fixed Serialization Probe" ) ;
97- source . AddComponent < FixedSerializationPrefabProbe > ( ) . SetSnapshot ( ExpectedSnapshot ) ;
92+ SetSnapshot ( source . AddComponent < FixedSerializationPrefabProbe > ( ) , ExpectedSnapshot ) ;
9893
9994 try
10095 {
@@ -113,7 +108,7 @@ public void PrefabSaveReload_PreservesFixedMathSharpValues()
113108 FixedSerializationPrefabProbe reloaded = reloadedPrefab . GetComponent < FixedSerializationPrefabProbe > ( ) ;
114109
115110 Assert . That ( reloaded , Is . Not . Null ) ;
116- AssertSnapshotEqual ( reloaded . GetSnapshot ( ) , ExpectedSnapshot ) ;
111+ AssertSnapshotEqual ( GetSnapshot ( reloaded ) , ExpectedSnapshot ) ;
117112 }
118113
119114 [ Test ]
@@ -136,7 +131,7 @@ public void PrefabEditSaveReload_PreservesFixedMathSharpValues()
136131 GameObject contents = PrefabUtility . LoadPrefabContents ( prefabPath ) ;
137132 try
138133 {
139- contents . GetComponent < FixedSerializationPrefabProbe > ( ) . SetSnapshot ( ExpectedSnapshot ) ;
134+ SetSnapshot ( contents . GetComponent < FixedSerializationPrefabProbe > ( ) , ExpectedSnapshot ) ;
140135 PrefabUtility . SaveAsPrefabAsset ( contents , prefabPath ) ;
141136 }
142137 finally
@@ -151,7 +146,72 @@ public void PrefabEditSaveReload_PreservesFixedMathSharpValues()
151146 FixedSerializationPrefabProbe reloaded = reloadedPrefab . GetComponent < FixedSerializationPrefabProbe > ( ) ;
152147
153148 Assert . That ( reloaded , Is . Not . Null ) ;
154- AssertSnapshotEqual ( reloaded . GetSnapshot ( ) , ExpectedSnapshot ) ;
149+ AssertSnapshotEqual ( GetSnapshot ( reloaded ) , ExpectedSnapshot ) ;
150+ }
151+
152+ private struct FixedSerializationProbeSnapshot
153+ {
154+ public Fixed64 FixedValue ;
155+ public Vector2d Vector2Value ;
156+ public Vector3d Vector3Value ;
157+ public Fixed64 NestedValue ;
158+ public int ListCount ;
159+ public Fixed64 ListValue ;
160+ public Vector3d ListPosition ;
161+ }
162+
163+ private static void SetSnapshot (
164+ FixedSerializationScriptableProbe probe ,
165+ FixedSerializationProbeSnapshot snapshot )
166+ {
167+ probe . SetValues (
168+ snapshot . FixedValue ,
169+ snapshot . Vector2Value ,
170+ snapshot . Vector3Value ,
171+ snapshot . NestedValue ,
172+ snapshot . ListValue ,
173+ snapshot . ListPosition ) ;
174+ }
175+
176+ private static void SetSnapshot (
177+ FixedSerializationPrefabProbe probe ,
178+ FixedSerializationProbeSnapshot snapshot )
179+ {
180+ probe . SetValues (
181+ snapshot . FixedValue ,
182+ snapshot . Vector2Value ,
183+ snapshot . Vector3Value ,
184+ snapshot . NestedValue ,
185+ snapshot . ListValue ,
186+ snapshot . ListPosition ) ;
187+ }
188+
189+ private static FixedSerializationProbeSnapshot GetSnapshot ( FixedSerializationScriptableProbe probe )
190+ {
191+ return new FixedSerializationProbeSnapshot
192+ {
193+ FixedValue = probe . FixedValue ,
194+ Vector2Value = probe . Vector2Value ,
195+ Vector3Value = probe . Vector3Value ,
196+ NestedValue = probe . NestedValue ,
197+ ListCount = probe . ListCount ,
198+ ListValue = probe . ListValue ,
199+ ListPosition = probe . ListPosition
200+ } ;
201+ }
202+
203+ private static FixedSerializationProbeSnapshot GetSnapshot ( FixedSerializationPrefabProbe probe )
204+ {
205+ return new FixedSerializationProbeSnapshot
206+ {
207+ FixedValue = probe . FixedValue ,
208+ Vector2Value = probe . Vector2Value ,
209+ Vector3Value = probe . Vector3Value ,
210+ NestedValue = probe . NestedValue ,
211+ ListCount = probe . ListCount ,
212+ ListValue = probe . ListValue ,
213+ ListPosition = probe . ListPosition
214+ } ;
155215 }
156216
157217 private static void AssertSnapshotEqual (
@@ -163,9 +223,11 @@ private static void AssertSnapshotEqual(
163223 CollectFixedFailure ( actual . FixedValue , expected . FixedValue , "Fixed64 field" , failures ) ;
164224 CollectVector2Failure ( actual . Vector2Value , expected . Vector2Value , "Vector2d field" , failures ) ;
165225 CollectVector3Failure ( actual . Vector3Value , expected . Vector3Value , "Vector3d field" , failures ) ;
166- CollectFixedFailure ( actual . NestedValue . Value , expected . NestedValue . Value , "nested Fixed64 field" , failures ) ;
167- CollectFixedFailure ( actual . ListValue . Value , expected . ListValue . Value , "list Fixed64 field" , failures ) ;
168- CollectVector3Failure ( actual . ListValue . Position , expected . ListValue . Position , "list Vector3d field" , failures ) ;
226+ CollectFixedFailure ( actual . NestedValue , expected . NestedValue , "nested Fixed64 field" , failures ) ;
227+ if ( actual . ListCount != expected . ListCount )
228+ failures . Add ( $ "list count: expected { expected . ListCount } , got { actual . ListCount } ") ;
229+ CollectFixedFailure ( actual . ListValue , expected . ListValue , "list Fixed64 field" , failures ) ;
230+ CollectVector3Failure ( actual . ListPosition , expected . ListPosition , "list Vector3d field" , failures ) ;
169231
170232 if ( failures . Count > 0 )
171233 Assert . Fail ( string . Join ( Environment . NewLine , failures ) ) ;
0 commit comments