Skip to content

Commit 88d05a4

Browse files
committed
Improve stability of Unity unit testing.
Exclude FILETIME related tests because it is not supported in Unity.
1 parent 46678f3 commit 88d05a4

13 files changed

Lines changed: 85 additions & 61 deletions

test/MsgPack.UnitTest.CodeDom/Serialization/ArrayCodeDomBasedAutoMessagePackSerializerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21152,7 +21152,7 @@ public void TestFullVersionConstructorArrayNull()
2115221152
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2115321153
}
2115421154

21155-
#if !SILVERLIGHT
21155+
#if !SILVERLIGHT && !UNITY
2115621156
[Test]
2115721157
public void TestFILETIMEField()
2115821158
{
@@ -21165,7 +21165,7 @@ public void TestFILETIMEFieldArray()
2116521165
this.TestCoreWithAutoVerify( Enumerable.Repeat( ToFileTime( DateTime.UtcNow ), 2 ).ToArray(), GetSerializationContext() );
2116621166
}
2116721167

21168-
#endif // !SILVERLIGHT
21168+
#endif // !SILVERLIGHT && !UNITY
2116921169
[Test]
2117021170
public void TestTimeSpanField()
2117121171
{
@@ -22569,14 +22569,14 @@ private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context
2256922569
}
2257022570
}
2257122571

22572-
#if !SILVERLIGHT
22572+
#if !SILVERLIGHT && !UNITY
2257322573

2257422574
private static FILETIME ToFileTime( DateTime dateTime )
2257522575
{
2257622576
var fileTime = dateTime.ToFileTimeUtc();
2257722577
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
2257822578
}
2257922579

22580-
#endif // !SILVERLIGHT
22580+
#endif // !SILVERLIGHT && !UNITY
2258122581
}
2258222582
}

test/MsgPack.UnitTest.CodeDom/Serialization/MapCodeDomBasedAutoMessagePackSerializerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21466,7 +21466,7 @@ public void TestFullVersionConstructorArrayNull()
2146621466
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2146721467
}
2146821468

21469-
#if !SILVERLIGHT
21469+
#if !SILVERLIGHT && !UNITY
2147021470
[Test]
2147121471
public void TestFILETIMEField()
2147221472
{
@@ -21479,7 +21479,7 @@ public void TestFILETIMEFieldArray()
2147921479
this.TestCoreWithAutoVerify( Enumerable.Repeat( ToFileTime( DateTime.UtcNow ), 2 ).ToArray(), GetSerializationContext() );
2148021480
}
2148121481

21482-
#endif // !SILVERLIGHT
21482+
#endif // !SILVERLIGHT && !UNITY
2148321483
[Test]
2148421484
public void TestTimeSpanField()
2148521485
{
@@ -22883,14 +22883,14 @@ private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context
2288322883
}
2288422884
}
2288522885

22886-
#if !SILVERLIGHT
22886+
#if !SILVERLIGHT && !UNITY
2288722887

2288822888
private static FILETIME ToFileTime( DateTime dateTime )
2288922889
{
2289022890
var fileTime = dateTime.ToFileTimeUtc();
2289122891
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
2289222892
}
2289322893

22894-
#endif // !SILVERLIGHT
22894+
#endif // !SILVERLIGHT && !UNITY
2289522895
}
2289622896
}

test/MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/MakeAssets.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ foreach($c in $csproj.Project.ItemGroup.Compile)
4343
{
4444
$appender = [IO.File]::AppendText($destination)
4545

46-
foreach($line in $code)
46+
foreach ($line in $code)
4747
{
48-
$appender.WriteLine($line.Replace("protected internal", "protected"))
48+
if ($destination.Contains("gen35"))
49+
{
50+
# Change FILETIME to DateTime because FILETIME in Unity is not supported.
51+
$appender.WriteLine($line.Replace("protected internal", "protected").Replace("System.Runtime.InteropServices.ComTypes.FILETIME", "System.DateTime"))
52+
}
53+
else
54+
{
55+
$appender.WriteLine($line.Replace("protected internal", "protected"))
56+
}
4957
}
5058

5159
$appender.Flush()

test/MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
<DebugType>full</DebugType>
1818
<Optimize>false</Optimize>
1919
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>TRACE;DEBUG;AOT;NET35;UNITY_WORKAROUND;UNITY</DefineConstants>
20+
<DefineConstants>TRACE;DEBUG;AOT;NET35;UNITY_WORKAROUND;UNITY;MP_UNITY_DESKTOP</DefineConstants>
2121
<ErrorReport>prompt</ErrorReport>
2222
<WarningLevel>4</WarningLevel>
2323
</PropertyGroup>
2424
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2525
<DebugType>pdbonly</DebugType>
2626
<Optimize>true</Optimize>
2727
<OutputPath>bin\Release\</OutputPath>
28-
<DefineConstants>TRACE;AOT;NET35;UNITY_WORKAROUND;UNITY2</DefineConstants>
28+
<DefineConstants>TRACE;AOT;NET35;UNITY_WORKAROUND;UNITY;MP_UNITY_DESKTOP</DefineConstants>
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>

test/MsgPack.UnitTest/Serialization/ArrayFieldBasedAutoMessagePackSerializerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21152,7 +21152,7 @@ public void TestFullVersionConstructorArrayNull()
2115221152
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2115321153
}
2115421154

21155-
#if !SILVERLIGHT
21155+
#if !SILVERLIGHT && !UNITY
2115621156
[Test]
2115721157
public void TestFILETIMEField()
2115821158
{
@@ -21165,7 +21165,7 @@ public void TestFILETIMEFieldArray()
2116521165
this.TestCoreWithAutoVerify( Enumerable.Repeat( ToFileTime( DateTime.UtcNow ), 2 ).ToArray(), GetSerializationContext() );
2116621166
}
2116721167

21168-
#endif // !SILVERLIGHT
21168+
#endif // !SILVERLIGHT && !UNITY
2116921169
[Test]
2117021170
public void TestTimeSpanField()
2117121171
{
@@ -22569,14 +22569,14 @@ private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context
2256922569
}
2257022570
}
2257122571

22572-
#if !SILVERLIGHT
22572+
#if !SILVERLIGHT && !UNITY
2257322573

2257422574
private static FILETIME ToFileTime( DateTime dateTime )
2257522575
{
2257622576
var fileTime = dateTime.ToFileTimeUtc();
2257722577
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
2257822578
}
2257922579

22580-
#endif // !SILVERLIGHT
22580+
#endif // !SILVERLIGHT && !UNITY
2258122581
}
2258222582
}

test/MsgPack.UnitTest/Serialization/ArrayGenerationBasedAutoMessagePackSerializerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17434,7 +17434,7 @@ public void TestFullVersionConstructorArrayNull()
1743417434
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
1743517435
}
1743617436

17437-
#if !SILVERLIGHT
17437+
#if !SILVERLIGHT && !UNITY
1743817438
[Test]
1743917439
public void TestFILETIMEField()
1744017440
{
@@ -17447,7 +17447,7 @@ public void TestFILETIMEFieldArray()
1744717447
this.TestCoreWithAutoVerify( Enumerable.Repeat( ToFileTime( DateTime.UtcNow ), 2 ).ToArray(), GetSerializationContext() );
1744817448
}
1744917449

17450-
#endif // !SILVERLIGHT
17450+
#endif // !SILVERLIGHT && !UNITY
1745117451
[Test]
1745217452
public void TestTimeSpanField()
1745317453
{
@@ -18654,14 +18654,14 @@ private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context
1865418654
}
1865518655
}
1865618656

18657-
#if !SILVERLIGHT
18657+
#if !SILVERLIGHT && !UNITY
1865818658

1865918659
private static FILETIME ToFileTime( DateTime dateTime )
1866018660
{
1866118661
var fileTime = dateTime.ToFileTimeUtc();
1866218662
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
1866318663
}
1866418664

18665-
#endif // !SILVERLIGHT
18665+
#endif // !SILVERLIGHT && !UNITY
1866618666
}
1866718667
}

test/MsgPack.UnitTest/Serialization/ArrayReflectionBasedAutoMessagePackSerializerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21053,7 +21053,7 @@ public void TestFullVersionConstructorArrayNull()
2105321053
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2105421054
}
2105521055

21056-
#if !SILVERLIGHT
21056+
#if !SILVERLIGHT && !UNITY
2105721057
[Test]
2105821058
public void TestFILETIMEField()
2105921059
{
@@ -21066,7 +21066,7 @@ public void TestFILETIMEFieldArray()
2106621066
this.TestCoreWithAutoVerify( Enumerable.Repeat( ToFileTime( DateTime.UtcNow ), 2 ).ToArray(), GetSerializationContext() );
2106721067
}
2106821068

21069-
#endif // !SILVERLIGHT
21069+
#endif // !SILVERLIGHT && !UNITY
2107021070
[Test]
2107121071
public void TestTimeSpanField()
2107221072
{
@@ -22470,14 +22470,14 @@ private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context
2247022470
}
2247122471
}
2247222472

22473-
#if !SILVERLIGHT
22473+
#if !SILVERLIGHT && !UNITY
2247422474

2247522475
private static FILETIME ToFileTime( DateTime dateTime )
2247622476
{
2247722477
var fileTime = dateTime.ToFileTimeUtc();
2247822478
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
2247922479
}
2248022480

22481-
#endif // !SILVERLIGHT
22481+
#endif // !SILVERLIGHT && !UNITY
2248222482
}
2248322483
}

test/MsgPack.UnitTest/Serialization/AutoMessagePackSerializerTest.Types.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
#region -- License Terms --
33
//
44
// MessagePack for CLI
@@ -39,7 +39,11 @@
3939
#endif
4040
using System.Reflection;
4141
#if !SILVERLIGHT
42+
#if !UNITY || MP_UNITY_DESKTOP
4243
using System.Runtime.InteropServices.ComTypes;
44+
#else
45+
using FILETIME = System.DateTime; // For gen35 serializers which requires FILETIME properties and Unity compatibility which does not have FILETIME support in msgpack for cli.
46+
#endif // !UNITY
4347
#endif // !SILVERLIGHT
4448
using System.Text;
4549
using System.Text.RegularExpressions;
@@ -742,8 +746,12 @@ public ComplexTypeGenerated Initialize()
742746

743747
private static FILETIME ToFileTime( DateTime dateTime )
744748
{
749+
#if UNITY && !MP_UNITY_DESKTOP
750+
return dateTime;
751+
#else
745752
var fileTime = dateTime.ToFileTimeUtc();
746753
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
754+
#endif // UNITY
747755
}
748756

749757
#endif // !SILVERLIGHT
@@ -1174,7 +1182,7 @@ entry.Key is DateTime
11741182
}
11751183
#endif
11761184

1177-
#if !SILVERLIGHT
1185+
#if !SILVERLIGHT && !UNITY
11781186
if ( expected is FILETIME )
11791187
{
11801188
var expectedFileTime = ( FILETIME )( object )expected;
@@ -1185,7 +1193,7 @@ entry.Key is DateTime
11851193
);
11861194
return;
11871195
}
1188-
#endif // !SILVERLIGHT
1196+
#endif // !SILVERLIGHT && !UNITY
11891197

11901198
if ( expected.GetType().GetIsGenericType() && expected.GetType().GetGenericTypeDefinition() == typeof( KeyValuePair<,> ) )
11911199
{

test/MsgPack.UnitTest/Serialization/AutoMessagePackSerializerTest.Types.tt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#@ template debug="false" hostspecific="false" language="C#" #>
1+
<#@ template debug="false" hostspecific="false" language="C#" #>
22
<#@ output extension=".cs" #>
33
<#@ include file="AutoMessagePackSerializerTest.Polymorphism.ttinclude" #>
44
<#@ assembly name="System.Core.dll" #>
@@ -132,7 +132,7 @@ var notInSL =
132132
typeof( FILETIME )
133133
};
134134

135-
var notInSLWP =
135+
var notInSlwpNet35 =
136136
new HashSet<String>()
137137
{
138138
ToTypeName( typeof( KeyValuePair<string, Complex> ) ),
@@ -196,7 +196,11 @@ using System.Numerics;
196196
#endif
197197
using System.Reflection;
198198
#if !SILVERLIGHT
199+
#if !UNITY || MP_UNITY_DESKTOP
199200
using System.Runtime.InteropServices.ComTypes;
201+
#else
202+
using FILETIME = System.DateTime; // For gen35 serializers which requires FILETIME properties and Unity compatibility which does not have FILETIME support in msgpack for cli.
203+
#endif // !UNITY
200204
#endif // !SILVERLIGHT
201205
using System.Text;
202206
using System.Text.RegularExpressions;
@@ -261,7 +265,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
261265
}
262266
else if( notInNet35.Contains( typeName ) )
263267
{
264-
if(notInSLWP.Contains( typeName ) )
268+
if(notInSlwpNet35.Contains( typeName ) )
265269
{
266270
#>
267271
#if !NET35 && !WINDOWS_PHONE
@@ -304,7 +308,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
304308
}
305309
else if( notInNet35.Contains( typeName ) )
306310
{
307-
if(notInSLWP.Contains( typeName ) )
311+
if(notInSlwpNet35.Contains( typeName ) )
308312
{
309313
#>
310314
#endif // !NET35 && !WINDOWS_PHONE
@@ -349,7 +353,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
349353
}
350354
else if( notInNet35.Contains( typeName ) )
351355
{
352-
if(notInSLWP.Contains( typeName ) )
356+
if(notInSlwpNet35.Contains( typeName ) )
353357
{
354358
#>
355359
#if !NET35 && !WINDOWS_PHONE
@@ -379,7 +383,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
379383
}
380384
else if( notInNet35.Contains( typeName ) )
381385
{
382-
if(notInSLWP.Contains( typeName ) )
386+
if(notInSlwpNet35.Contains( typeName ) )
383387
{
384388
#>
385389
#endif // !NET35 && !WINDOWS_PHONE
@@ -407,8 +411,12 @@ foreach( Tuple<Object, string, string, bool> item in fields )
407411

408412
private static FILETIME ToFileTime( DateTime dateTime )
409413
{
414+
#if UNITY && !MP_UNITY_DESKTOP
415+
return dateTime;
416+
#else
410417
var fileTime = dateTime.ToFileTimeUtc();
411418
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
419+
#endif // UNITY
412420
}
413421

414422
#endif // !SILVERLIGHT
@@ -436,7 +444,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
436444
}
437445
else if( notInNet35.Contains( typeName ) )
438446
{
439-
if(notInSLWP.Contains( typeName ) )
447+
if(notInSlwpNet35.Contains( typeName ) )
440448
{
441449
#>
442450
#if !NET35 && !WINDOWS_PHONE
@@ -466,7 +474,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
466474
}
467475
else if( notInNet35.Contains( typeName ) )
468476
{
469-
if(notInSLWP.Contains( typeName ) )
477+
if(notInSlwpNet35.Contains( typeName ) )
470478
{
471479
#>
472480
#endif // !NET35 && !WINDOWS_PHONE
@@ -805,7 +813,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
805813
}
806814
#endif
807815

808-
#if !SILVERLIGHT
816+
#if !SILVERLIGHT && !UNITY
809817
if ( expected is FILETIME )
810818
{
811819
var expectedFileTime = ( FILETIME )( object )expected;
@@ -816,7 +824,7 @@ foreach( Tuple<Object, string, string, bool> item in fields )
816824
);
817825
return;
818826
}
819-
#endif // !SILVERLIGHT
827+
#endif // !SILVERLIGHT && !UNITY
820828

821829
if ( expected.GetType().GetIsGenericType() && expected.GetType().GetGenericTypeDefinition() == typeof( KeyValuePair<,> ) )
822830
{

0 commit comments

Comments
 (0)