-
Notifications
You must be signed in to change notification settings - Fork 50
/
UnityFileSystemTests.cs
644 lines (503 loc) · 21.2 KB
/
UnityFileSystemTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using NUnit.Framework;
using UnityDataTools.TestCommon;
namespace UnityDataTools.FileSystem.Tests;
#pragma warning disable NUnit2005, NUnit2006
public class ArchiveTests : AssetBundleTestFixture
{
public ArchiveTests(Context context) : base(context)
{
}
protected override void OnLoadExpectedData(Context context)
{
// Uncomment to regenerate expected data.
//ExpectedDataGenerator.Generate(context);
}
[OneTimeSetUp]
public void Setup()
{
UnityFileSystem.Init();
}
[OneTimeTearDown]
public void TearDown()
{
UnityFileSystem.Cleanup();
}
[Test]
public void MountArchive_InvalidPath_ThrowsException()
{
var ex = Assert.Throws<FileNotFoundException>(() => UnityFileSystem.MountArchive("bad/path", "archive:/"));
Assert.AreEqual("File not found.", ex.Message);
Assert.AreEqual("bad/path", ex.FileName);
}
[Test]
public void MountArchive_InvalidArchive_ThrowsException()
{
var path = Path.Combine(Context.TestDataFolder, "invalidfile");
var ex = Assert.Throws<NotSupportedException>(() => UnityFileSystem.MountArchive(path, "archive:/"));
Assert.AreEqual($"Invalid file format reading {path}.", ex.Message);
}
public void MountArchive_ValidArchive_ReturnsArchive()
{
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
UnityArchive archive = null;
Assert.DoesNotThrow(() => archive = UnityFileSystem.MountArchive(path, "archive:/"));
Assert.IsNotNull(archive);
archive.Dispose();
}
[Ignore("This test doesn't return the expected error, this condition is probably not handled correctly in Unity")]
public void DisposeArchive_ValidArchive_UnmountsArchive()
{
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
var archive = UnityFileSystem.MountArchive(path, "archive:/");
var node = archive.Nodes[0];
Assert.DoesNotThrow(() => archive.Dispose());
var ex = Assert.Throws<FileNotFoundException>(() => UnityFileSystem.OpenFile($"archive:/{node.Path}"));
archive.Dispose();
}
public void Nodes_Disposed_ThrowsException()
{
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
var archive = UnityFileSystem.MountArchive(path, "archive:/");
archive.Dispose();
Assert.Throws<ObjectDisposedException>(() => { var _ = archive.Nodes; });
}
public void Nodes_ValidArchive_ExpectedContent(string testFolder)
{
var path = Path.Combine(testFolder, "AssetBundles", "assetbundle");
var archive = UnityFileSystem.MountArchive(path, "archive:/");
var nodes = archive.Nodes;
Assert.AreEqual(Context.ExpectedData.Get("NodeCount"), nodes.Count);
Assert.AreEqual("CAB-5d40f7cad7c871cf2ad2af19ac542994", nodes[0].Path);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-Size"), nodes[0].Size);
Assert.AreEqual((ArchiveNodeFlags)Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-Flags"), nodes[0].Flags);
Assert.AreEqual("CAB-5d40f7cad7c871cf2ad2af19ac542994.resS", nodes[1].Path);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994.resS-Size"), nodes[1].Size);
Assert.AreEqual((ArchiveNodeFlags)Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994.resS-Flags"), nodes[1].Flags);
Assert.AreEqual("CAB-5d40f7cad7c871cf2ad2af19ac542994.resource", nodes[2].Path);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994.resource-Size"), nodes[2].Size);
Assert.AreEqual((ArchiveNodeFlags)Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994.resource-Flags"), nodes[2].Flags);
archive.Dispose();
}
}
public class UnityFileTests : AssetBundleTestFixture
{
private UnityArchive m_Archive;
public UnityFileTests(Context context) : base(context)
{
}
[OneTimeSetUp]
public void Setup()
{
UnityFileSystem.Init();
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
m_Archive = UnityFileSystem.MountArchive(path, "archive:/");
}
[OneTimeTearDown]
public void TearDown()
{
m_Archive.Dispose();
UnityFileSystem.Cleanup();
}
[Test]
public void OpenFile_InvalidPath_ThrowsException()
{
var ex = Assert.Throws<FileNotFoundException>(() => UnityFileSystem.OpenFile("bad/path"));
Assert.AreEqual("File not found.", ex.Message);
Assert.AreEqual("bad/path", ex.FileName);
}
[Test]
public void OpenFile_LocalFileSystem_ReturnsValidFile()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
UnityFile file = null;
Assert.DoesNotThrow(() => file = UnityFileSystem.OpenFile(path));
Assert.IsNotNull(file);
Assert.DoesNotThrow(() => file.Dispose());
}
[Test]
public void GetFileSize_LocalFileSystem_ReturnSize()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
Assert.AreEqual(21, file.GetSize());
file.Dispose();
}
[Test]
public void GetFileSize_InvalidHandle_ThrowsException()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => file.GetSize());
}
[Test]
public void SeekFile_LocalFileSystem_SeekAtExpectedPosition()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
var newPos = 0L;
var buffer = new Byte[16];
var actualSize = 0L;
Assert.DoesNotThrow(() => newPos = file.Seek(16, SeekOrigin.Begin));
Assert.AreEqual(16, newPos);
actualSize = file.Read(4, buffer);
Assert.AreEqual(4, actualSize);
Assert.AreEqual("file", Encoding.Default.GetString(buffer, 0, (int)actualSize));
Assert.DoesNotThrow(() => newPos = file.Seek(-4, SeekOrigin.Current));
Assert.AreEqual(16, newPos);
buffer = new Byte[16];
actualSize = file.Read(4, buffer);
Assert.AreEqual(4, actualSize);
Assert.AreEqual("file", Encoding.Default.GetString(buffer, 0, (int)actualSize));
Assert.DoesNotThrow(() => newPos = file.Seek(-5, SeekOrigin.End));
Assert.AreEqual(16, newPos);
actualSize = file.Read(4, buffer);
Assert.AreEqual(4, actualSize);
Assert.AreEqual("file", Encoding.Default.GetString(buffer, 0, (int)actualSize));
file.Dispose();
}
[Test]
public void SeekFile_InvalidHandle_ThrowsException()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => file.Seek(0, SeekOrigin.Begin));
}
[Test]
public void ReadFile_LocalFileSystem_ReadExpectedData()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
var buffer = new Byte[1000];
var actualSize = file.Read(1000, buffer);
Assert.AreEqual(21, actualSize);
Assert.AreEqual("This is my text file.", Encoding.Default.GetString(buffer, 0, (int)actualSize));
file.Dispose();
}
[Test]
public void ReadFile_InvalidHandle_ThrowsException()
{
var path = Path.Combine(Context.TestDataFolder, "TextFile.txt");
var file = UnityFileSystem.OpenFile(path);
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => file.Read(10, new byte[10]));
}
[Test]
public void OpenFile_ArchiveFileSystem_ReturnsFile()
{
UnityFile file = null;
Assert.DoesNotThrow(() => file = UnityFileSystem.OpenFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994"));
Assert.IsNotNull(file);
file.Dispose();
}
[Test]
public void ReadFile_ArchiveFileSystem_ReadExpectedData()
{
var file = UnityFileSystem.OpenFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
var buffer = new Byte[100];
var actualSize = 0L;
Assert.DoesNotThrow(() => actualSize = file.Read(100, buffer));
Assert.AreEqual(100, actualSize);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-Data"), buffer);
file.Dispose();
}
}
public class SerializedFileTests : AssetBundleTestFixture
{
private UnityArchive m_Archive;
public SerializedFileTests(Context context) : base(context)
{
}
[OneTimeSetUp]
public void Setup()
{
UnityFileSystem.Init();
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
m_Archive = UnityFileSystem.MountArchive(path, "archive:/");
}
[OneTimeTearDown]
public void TearDown()
{
m_Archive.Dispose();
UnityFileSystem.Cleanup();
}
[Test]
public void OpenSerializedFile_InvalidPath_ThrowsException()
{
var ex = Assert.Throws<FileNotFoundException>(() => UnityFileSystem.OpenSerializedFile("bad/path"));
Assert.AreEqual("File not found.", ex.Message);
Assert.AreEqual("bad/path", ex.FileName);
}
[Test]
[Ignore("This test crashes, this condition is not handled properly in Unity")]
public void OpenSerializedFile_NotSerializedFile_ThrowsException()
{
var ex = Assert.Throws<Exception>(() => UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994.resS"));
}
[Test]
public void OpenSerializedFile_ValidSerializedFile_ReturnsFile()
{
SerializedFile file = null;
Assert.DoesNotThrow(() => file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994"));
Assert.IsNotNull(file);
file.Dispose();
}
[Test]
public void ExternalReferences_Disposed_ThrowsException()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => { var _ = file.ExternalReferences.Count; });
}
[Test]
public void Objects_Disposed_ThrowsException()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => { var _ = file.Objects.Count; });
}
[Test]
public void GetTypeTreeRoot_Disposed_ThrowsException()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
file.Dispose();
Assert.Throws<ObjectDisposedException>(() => { var _ = file.GetTypeTreeRoot(0); });
}
[Test]
public void ExternalReferences_ValidSerializedFile_ReturnExpectedExternalReferenceCount()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRefCount"), file.ExternalReferences.Count);
file.Dispose();
}
[Test]
public void ExternalReferences_ValidSerializedFile_ExpectedContent()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
int i = 0;
foreach (var extRef in file.ExternalReferences)
{
Assert.AreEqual(Context.ExpectedData.Get($"CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRef{i}-Guid"), extRef.Guid);
Assert.AreEqual(Context.ExpectedData.Get($"CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRef{i}-Path"), extRef.Path);
Assert.AreEqual(Context.ExpectedData.Get($"CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRef{i}-Type"), (long)extRef.Type);
++i;
}
file.Dispose();
}
[Test]
public void GetObjectCount_ValidSerializedFile_ReturnExpectedObjectCount()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-ObjCount"), file.Objects.Count);
file.Dispose();
}
[Test]
public void GetObjectInfo_ValidSerializedFile_ReturnExpectedObjectInfo()
{
var file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
// Just make sure that first and last ObjectInfo struct are filled.
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-Id"), file.Objects.First().Id);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-Offset"), file.Objects.First().Offset);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-Size"), file.Objects.First().Size);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-TypeId"), file.Objects.First().TypeId);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Id"), file.Objects.Last().Id);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Offset"), file.Objects.Last().Offset);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Size"), file.Objects.Last().Size);
Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-TypeId"), file.Objects.Last().TypeId);
file.Dispose();
}
}
public class TypeTreeTests : AssetBundleTestFixture
{
private UnityArchive m_Archive;
private SerializedFile m_SerializedFile;
public TypeTreeTests(Context context) : base(context)
{
}
[OneTimeSetUp]
public void Setup()
{
UnityFileSystem.Init();
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
m_Archive = UnityFileSystem.MountArchive(path, "archive:/");
m_SerializedFile = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
}
[OneTimeTearDown]
public void TearDown()
{
m_SerializedFile.Dispose();
m_Archive.Dispose();
UnityFileSystem.Cleanup();
}
[Test]
public void GetTypeTreeRoot_InvalidObjectId_ThrowsException()
{
Assert.Throws<ArgumentException>(() => m_SerializedFile.GetTypeTreeRoot(0));
}
[Test]
public void GetTypeTreeRoot_ValidSerializedFile_ReturnsNode()
{
TypeTreeNode node = null;
Assert.DoesNotThrow(() => node = m_SerializedFile.GetTypeTreeRoot(m_SerializedFile.Objects[0].Id));
Assert.IsNotNull(node);
}
[Test]
public void GetTypeTreeRoot_ValidSerializedFile_ReturnsValidData()
{
foreach (var obj in m_SerializedFile.Objects)
{
TypeTreeNode root = null;
Assert.DoesNotThrow(() => root = m_SerializedFile.GetTypeTreeRoot(obj.Id));
Assert.IsNotNull(root);
Assert.AreNotEqual("", root.Type);
Assert.AreEqual("Base", root.Name);
Assert.AreEqual(-1, root.Offset);
Assert.AreNotEqual(0, root.Size);
Assert.AreEqual(TypeTreeFlags.None, root.Flags);
}
}
[Test]
public void TypeTreeNode_IterateAll_ReturnExpectedValues()
{
int ProcessNode(TypeTreeNode node)
{
int count = 1;
Assert.IsNotNull(node);
Assert.AreNotEqual("", node.Type);
Assert.AreNotEqual("", node.Name);
Assert.GreaterOrEqual(node.Offset, -1);
Assert.GreaterOrEqual(node.Size, -1);
Assert.True(node.IsLeaf == (node.Children.Count == 0));
foreach (var child in node.Children)
{
count += ProcessNode(child);
}
return count;
}
foreach (var obj in m_SerializedFile.Objects)
{
var root = m_SerializedFile.GetTypeTreeRoot(obj.Id);
var count = ProcessNode(root);
Assert.Greater(count, 1);
}
}
[Test]
public void GetRefTypeTypeTree_InvalidFQN_ThrowsException()
{
Assert.Throws<ArgumentException>(() => m_SerializedFile.GetRefTypeTypeTreeRoot("this", "is", "wrong"));
}
[Test]
public void GetRefTypeTree_ValidSerializedFile_ReturnNode()
{
TypeTreeNode node = null;
Assert.DoesNotThrow(() => node = m_SerializedFile.GetRefTypeTypeTreeRoot("SerializeReferencePolymorphismExample/Apple", "", "Assembly-CSharp"));
Assert.NotNull(node);
}
[Test]
public void GetTypeTreeNodeInfo_RefTypeTypeTree_ReturnExpectedValues()
{
var node = m_SerializedFile.GetRefTypeTypeTreeRoot("SerializeReferencePolymorphismExample/Apple", "",
"Assembly-CSharp");
Assert.AreEqual(2, node.Children.Count);
Assert.AreEqual("Apple", node.Type);
Assert.AreEqual("Base", node.Name);
Assert.AreEqual("int", node.Children[0].Type);
Assert.AreEqual("m_Data", node.Children[0].Name);
Assert.AreEqual(4, node.Children[0].Size);
Assert.AreEqual("string", node.Children[1].Type);
Assert.AreEqual("m_Description", node.Children[1].Name);
}
}
public class RandomAccessReaderTests : AssetBundleTestFixture
{
private UnityArchive m_Archive;
private SerializedFile m_SerializedFile;
private UnityFileReader m_Reader;
public RandomAccessReaderTests(Context context) : base(context)
{
}
[OneTimeSetUp]
public void Setup()
{
UnityFileSystem.Init();
var path = Path.Combine(Context.UnityDataFolder, "assetbundle");
m_Archive = UnityFileSystem.MountArchive(path, "archive:/");
m_SerializedFile = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994");
m_Reader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024);
}
[OneTimeTearDown]
public void TearDown()
{
m_Reader.Dispose();
m_SerializedFile.Dispose();
m_Archive.Dispose();
UnityFileSystem.Cleanup();
}
ObjectInfo GetObjectInfo(long id)
{
ObjectInfo obj = new ObjectInfo();
int i;
for (i = 0; i < m_SerializedFile.Objects.Count; ++i)
{
obj = m_SerializedFile.Objects[i];
if (obj.Id == id)
{
break;
}
}
Assert.Less(i, m_SerializedFile.Objects.Count);
return obj;
}
[Test]
public void AccessProperty_ValidProperty_ReturnExpectedValues()
{
var obj = GetObjectInfo(-7865028809519950684);
var root = m_SerializedFile.GetTypeTreeRoot(obj.Id);
var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset);
Assert.AreEqual("Lame", reader["m_Name"].GetValue<string>());
Assert.AreEqual(228, reader["m_SubMeshes"][0]["vertexCount"].GetValue<UInt32>());
Assert.AreEqual(false, reader["m_IsReadable"].GetValue<bool>());
}
[Test]
public void AccessProperty_InvalidProperty_ThrowException()
{
var obj = GetObjectInfo(-7865028809519950684);
var root = m_SerializedFile.GetTypeTreeRoot(obj.Id);
var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset);
Assert.Throws<KeyNotFoundException>(() => reader["ThisIsAnUnexistingPropertyName"].GetValue<string>());
}
[Test]
public void AccessReferencedObject_ValidProperty_ReturnExpectedValues()
{
var obj = GetObjectInfo(-4606375687431940004);
var root = m_SerializedFile.GetTypeTreeRoot(obj.Id);
var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset);
long id0;
long id1;
// ManagedReferencesRegistry Version 1
if (reader["m_Item"].HasChild("id"))
{
id0 = reader["m_Item"]["id"].GetValue<int>();
id1 = reader["m_Item2"]["id"].GetValue<int>();
}
// ManagedReferencesRegistry Version 2
else
{
id0 = reader["m_Item"]["rid"].GetValue<long>();
id1 = reader["m_Item2"]["rid"].GetValue<long>();
}
Assert.IsTrue(reader["references"].HasChild($"rid({id0})"));
Assert.IsTrue(reader["references"].HasChild($"rid({id1})"));
Assert.AreEqual(1, reader["references"][$"rid({id0})"]["data"]["m_Data"].GetValue<int>());
Assert.AreEqual("Ripe", reader["references"][$"rid({id0})"]["data"]["m_Description"].GetValue<string>());
Assert.AreEqual(1, reader["references"][$"rid({id1})"]["data"]["m_Data"].GetValue<int>());
Assert.AreEqual(1, reader["references"][$"rid({id1})"]["data"]["m_IsRound"].GetValue<byte>());
}
}