Skip to content

Commit aea8cdd

Browse files
committed
added test for long, ulong and DateTime
fixed GetField assert
1 parent b00fee6 commit aea8cdd

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

Editor/Scripts/TestVariables.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//
2-
// Heap Explorer for Unity. Copyright (c) 2019-2020 Peter Schraut (www.console-dev.de). See LICENSE.md
2+
// Heap Explorer for Unity. Copyright (c) 2019-2022 Peter Schraut (www.console-dev.de). See LICENSE.md
33
// https://github.com/pschraut/UnityHeapExplorer/
44
//
5+
#pragma warning disable 0414
56
using System;
67
using UnityEngine;
78
using UnityEditor;
@@ -18,7 +19,6 @@ namespace HeapExplorer
1819
/// </summary>
1920
public class TestVariables
2021
{
21-
#pragma warning disable 0414
2222
interface ITestInterface
2323
{
2424
void HelloWorld();
@@ -234,6 +234,18 @@ struct MyStruct
234234
uint m_magic0 = (uint)0xdeadbeef;
235235

236236
string m_testString = "This is a string";
237-
#pragma warning restore 0414
237+
238+
long m_long = -1234567890;
239+
ulong m_ulong = 0x11_22_33_44_55_66_77_88;
240+
241+
Color m_redColor = Color.red;
242+
Color m_greenColor = Color.green;
243+
Color m_blueColor = Color.blue;
244+
245+
Color32 m_redColor32 = Color.red;
246+
Color32 m_greenColor32 = Color.green;
247+
Color32 m_blueColor32 = Color.blue;
248+
249+
DateTime m_dateTime_1999_11_22 = new DateTime(1999, 11, 22, 1, 2, 3);
238250
}
239251
}

Tests/Editor/Test_Editor.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//
2-
// Heap Explorer for Unity. Copyright (c) 2019-2021 Peter Schraut (www.console-dev.de). See LICENSE.md
2+
// Heap Explorer for Unity. Copyright (c) 2019-2022 Peter Schraut (www.console-dev.de). See LICENSE.md
33
// https://github.com/pschraut/UnityHeapExplorer/
44
//
5+
#pragma warning disable 0414
56
#if HEAPEXPLORER_ENABLE_TESTS
67
using System;
78
using UnityEngine;
@@ -96,13 +97,18 @@ void RunTest()
9697
AssertQuaternion("m_quaternion1", Quaternion.AngleAxis(90, Vector3.up), managedObject);
9798

9899
AssertMatrix4x4("m_matrix", Matrix4x4.identity, managedObject);
100+
101+
AssertLong("m_long", -1234567890, managedObject);
102+
AssertULong("m_ulong", 0x11_22_33_44_55_66_77_88, managedObject);
103+
104+
AssertDateTime("m_dateTime_1999_11_22", new DateTime(1999, 11, 22, 1, 2, 3), managedObject);
99105
}
100106

101107
PackedManagedField GetField(string fieldName, RichManagedObject managedObject)
102108
{
103109
PackedManagedField field;
104-
var index = managedObject.type.FindField(fieldName, out field);
105-
Assert.AreNotEqual(-1, index, "Field '{0}' not found.", fieldName);
110+
var found = managedObject.type.FindField(fieldName, out field);
111+
Assert.IsTrue(found, $"Field '{fieldName}' not found.");
106112

107113
return field;
108114
}
@@ -123,6 +129,22 @@ void AssertInt(string fieldName, int value, RichManagedObject managedObject)
123129
Assert.AreEqual(value, memory.ReadInt32((uint)field.offset + managedObject.address));
124130
}
125131

132+
void AssertLong(string fieldName, long value, RichManagedObject managedObject)
133+
{
134+
var memory = new MemoryReader(m_snapshot);
135+
136+
var field = GetField(fieldName, managedObject);
137+
Assert.AreEqual(value, memory.ReadInt64((uint)field.offset + managedObject.address));
138+
}
139+
140+
void AssertULong(string fieldName, ulong value, RichManagedObject managedObject)
141+
{
142+
var memory = new MemoryReader(m_snapshot);
143+
144+
var field = GetField(fieldName, managedObject);
145+
Assert.AreEqual(value, memory.ReadUInt64((uint)field.offset + managedObject.address));
146+
}
147+
126148
void AssertVector2(string fieldName, Vector2 value, RichManagedObject managedObject)
127149
{
128150
var memory = new MemoryReader(m_snapshot);
@@ -174,6 +196,15 @@ void AssertMatrix4x4(string fieldName, Matrix4x4 value, RichManagedObject manage
174196
Assert.AreEqual(value, matrix);
175197
}
176198

199+
void AssertDateTime(string fieldName, DateTime value, RichManagedObject managedObject)
200+
{
201+
var memory = new MemoryReader(m_snapshot);
202+
203+
var field = GetField(fieldName, managedObject);
204+
var ticks = memory.ReadInt64(0 + (uint)field.offset + managedObject.address);
205+
Assert.AreEqual(value, new DateTime(ticks));
206+
}
207+
177208
void OnSnapshotReceived(string path, bool captureResult)
178209
{
179210
var args = new MemorySnapshotProcessingArgs();
@@ -182,7 +213,6 @@ void OnSnapshotReceived(string path, bool captureResult)
182213
m_snapshot = PackedMemorySnapshot.FromMemoryProfiler(args);
183214
}
184215

185-
#pragma warning disable 0414
186216
int m_intOne = 1;
187217
int m_intTwo = 2;
188218
int m_intThree = 3;
@@ -377,7 +407,19 @@ struct MyStruct
377407
uint m_magic0 = (uint)0xdeadbeef;
378408

379409
string m_testString = "This is a string";
380-
#pragma warning restore 0414
410+
411+
long m_long = -1234567890;
412+
ulong m_ulong = 0x11_22_33_44_55_66_77_88;
413+
414+
Color m_redColor = Color.red;
415+
Color m_greenColor = Color.green;
416+
Color m_blueColor = Color.blue;
417+
418+
Color32 m_redColor32 = Color.red;
419+
Color32 m_greenColor32 = Color.green;
420+
Color32 m_blueColor32 = Color.blue;
421+
422+
DateTime m_dateTime_1999_11_22 = new DateTime(1999, 11, 22, 1, 2, 3);
381423
}
382424
}
383425
#endif // HEAPEXPLORER_ENABLE_TESTS

0 commit comments

Comments
 (0)