-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Communicate between framework mscorlib and core framework with Un…
…it Tests (#116) * Communicate between mscorlib and System.Private.CoreLib * Strict string match * Add a binary file generator for all .NET frameworks * Add generated serialized files to project as suggestted in #112 (comment) * Add unit tests to test cross framework serialization and deserialization * FullFramework or CoreNetFramework runtime check * Using Constants instead * Downgrade FSharp.Core 4.7.0 to 4.6.2 because 4.7.0 is not compatible with netstandard1.6 * Add generated serialized file for .NET Core 3.0 to project * Add netcoreapp2.2 support to Hyperion.Tests Update Windows vm image to windows-2019 * Remove netcoreapp2.2 from Hyperion.Tests
- Loading branch information
1 parent
75c05f6
commit 034ba5c
Showing
19 changed files
with
385 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.IO; | ||
using Hyperion.Tests.Generator; | ||
using Xunit; | ||
|
||
namespace Hyperion.Tests | ||
{ | ||
public class CrossFrameworkSerializationTests | ||
{ | ||
private readonly Serializer _serializer; | ||
private readonly CrossFrameworkClass _originalObject; | ||
|
||
public CrossFrameworkSerializationTests() | ||
{ | ||
_serializer = new Serializer(); | ||
_originalObject = CrossFrameworkInitializer.Init(); | ||
} | ||
|
||
[Fact] | ||
public void CanSerializeCrossFramework() | ||
{ | ||
const string defaultOutputPath = CrossFrameworkInitializer.DefaultOutputPath; | ||
var testFiles = Directory.GetFiles(defaultOutputPath, "*.tf"); | ||
|
||
Assert.NotEmpty(testFiles); | ||
|
||
foreach (string testFile in testFiles) | ||
{ | ||
using (var fileStream = new FileStream(testFile, FileMode.Open)) | ||
{ | ||
var crossFrameworkClass = _serializer.Deserialize<CrossFrameworkClass>(fileStream); | ||
|
||
Assert.Equal(_originalObject, crossFrameworkClass); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
|
||
namespace Hyperion.Tests.Generator | ||
{ | ||
public class CrossFrameworkClass | ||
{ | ||
public sbyte Sbyte { get; set; } | ||
|
||
public short Short { get; set; } | ||
|
||
public int Int { get; set; } | ||
|
||
public long Long { get; set; } | ||
|
||
public byte Byte { get; set; } | ||
|
||
public ushort UShort { get; set; } | ||
|
||
public uint UInt { get; set; } | ||
|
||
public ulong ULong { get; set; } | ||
|
||
public char Char { get; set; } | ||
|
||
public float Float { get; set; } | ||
|
||
public double Double { get; set; } | ||
|
||
public decimal Decimal { get; set; } | ||
|
||
public bool Boolean { get; set; } | ||
|
||
public string String { get; set; } | ||
|
||
public DateTime DateTime { get; set; } | ||
|
||
public Exception Exception { get; set; } | ||
|
||
public CrossFrameworkEnum Enum { get; set; } | ||
|
||
public CrossFrameworkStruct Struct { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is CrossFrameworkClass)) | ||
{ | ||
return false; | ||
} | ||
|
||
var objectToCompare = (CrossFrameworkClass) obj; | ||
|
||
|
||
//return Sbyte == objectToCompare.Sbyte | ||
// && Short == objectToCompare.Short | ||
// && Int == objectToCompare.Int | ||
// && Long == objectToCompare.Long | ||
// && Byte == objectToCompare.Byte | ||
// && UShort == objectToCompare.UShort | ||
// && UInt == objectToCompare.UInt | ||
// && ULong == objectToCompare.ULong | ||
// && Char == objectToCompare.Char | ||
// && Math.Abs(Float - objectToCompare.Float) < float.Epsilon | ||
// && Math.Abs(Double - objectToCompare.Double) < double.Epsilon | ||
// && Decimal == objectToCompare.Decimal | ||
// && Boolean == objectToCompare.Boolean | ||
// && String == objectToCompare.String | ||
// && DateTime == objectToCompare.DateTime | ||
// && Exception == objectToCompare.Exception | ||
// && Enum == objectToCompare.Enum | ||
// && Struct.Equals(objectToCompare.Struct); | ||
|
||
return Equals(objectToCompare); | ||
|
||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
int hashCode = Sbyte.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Short.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Int; | ||
hashCode = (hashCode * 397) ^ Long.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Byte.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ UShort.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (int) UInt; | ||
hashCode = (hashCode * 397) ^ ULong.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Char.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Float.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Double.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Decimal.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Boolean.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ DateTime.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (Exception != null ? Exception.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (int) Enum; | ||
hashCode = (hashCode * 397) ^ Struct.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
|
||
private bool Equals(CrossFrameworkClass other) | ||
{ | ||
return Sbyte == other.Sbyte | ||
&& Short == other.Short | ||
&& Int == other.Int | ||
&& Long == other.Long | ||
&& Byte == other.Byte | ||
&& UShort == other.UShort | ||
&& UInt == other.UInt | ||
&& ULong == other.ULong | ||
&& Char == other.Char | ||
&& Math.Abs(Float - other.Float) < float.Epsilon | ||
&& Math.Abs(Double - other.Double) < double.Epsilon | ||
&& Decimal == other.Decimal | ||
&& Boolean == other.Boolean | ||
&& string.Equals(String, other.String) | ||
&& DateTime.Equals(other.DateTime) | ||
// && Equals(Exception, other.Exception) | ||
&& Exception.Message == other.Exception.Message | ||
&& Enum == other.Enum | ||
&& Struct.Equals(other.Struct); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Hyperion.Tests.Generator | ||
{ | ||
public enum CrossFrameworkEnum | ||
{ | ||
ShortSword, | ||
LongSword, | ||
BastardSword, | ||
Claymore, | ||
Scimitar, | ||
Yatagan, | ||
Katana | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace Hyperion.Tests.Generator | ||
{ | ||
public static class CrossFrameworkInitializer | ||
{ | ||
public const string DefaultOutputPath = "../../../testfiles"; | ||
|
||
public static CrossFrameworkClass Init() | ||
{ | ||
return new CrossFrameworkClass() | ||
{ | ||
Exception = new Exception("Test message", new ArgumentNullException("param", "Cannot be null")), | ||
DateTime = new DateTime(1944, 6, 6), // DDay | ||
Enum = CrossFrameworkEnum.Yatagan, | ||
String = "On June 6, 1944, more than 160,000 Allied troops landed along a 50-mile stretch of heavily-fortified French coastline", | ||
Struct = new CrossFrameworkStruct() | ||
{ | ||
Boolean = true, | ||
Long = long.MaxValue, | ||
Decimal = decimal.MinusOne, | ||
Double = double.MaxValue, | ||
Int = int.MaxValue, | ||
Short = short.MaxValue, | ||
ULong = ulong.MinValue, | ||
Byte = byte.MaxValue, | ||
Char = char.MaxValue, | ||
Float = float.MinValue, | ||
UShort = ushort.MinValue, | ||
UInt = uint.MaxValue, | ||
Sbyte = sbyte.MaxValue | ||
}, | ||
Decimal = decimal.MaxValue, | ||
Float = float.MaxValue, | ||
Long = long.MinValue, | ||
Int = int.MinValue, | ||
Double = double.Epsilon, | ||
Char = char.MaxValue, | ||
Byte = byte.MaxValue, | ||
Sbyte = sbyte.MaxValue, | ||
Short = short.MaxValue, | ||
UInt = uint.MaxValue, | ||
ULong = ulong.MaxValue, | ||
UShort = ushort.MaxValue, | ||
Boolean = true | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
|
||
namespace Hyperion.Tests.Generator | ||
{ | ||
public struct CrossFrameworkStruct | ||
{ | ||
public sbyte Sbyte { get; set; } | ||
|
||
public short Short { get; set; } | ||
|
||
public int Int { get; set; } | ||
|
||
public long Long { get; set; } | ||
|
||
public byte Byte { get; set; } | ||
|
||
public ushort UShort { get; set; } | ||
|
||
public uint UInt { get; set; } | ||
|
||
public ulong ULong { get; set; } | ||
|
||
public char Char { get; set; } | ||
|
||
public float Float { get; set; } | ||
|
||
public double Double { get; set; } | ||
|
||
public decimal Decimal { get; set; } | ||
|
||
public bool Boolean { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is CrossFrameworkStruct)) | ||
{ | ||
return false; | ||
} | ||
|
||
var objectToCompare = (CrossFrameworkStruct)obj; | ||
|
||
return Equals(objectToCompare); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
int hashCode = Sbyte.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Short.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Int; | ||
hashCode = (hashCode * 397) ^ Long.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Byte.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ UShort.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (int) UInt; | ||
hashCode = (hashCode * 397) ^ ULong.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Char.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Float.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Double.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Decimal.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ Boolean.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
|
||
private bool Equals(CrossFrameworkStruct other) | ||
{ | ||
return Sbyte == other.Sbyte | ||
&& Short == other.Short | ||
&& Int == other.Int | ||
&& Long == other.Long | ||
&& Byte == other.Byte | ||
&& UShort == other.UShort | ||
&& UInt == other.UInt | ||
&& ULong == other.ULong | ||
&& Char == other.Char | ||
&& Math.Abs(Float - other.Float) < float.Epsilon | ||
&& Math.Abs(Double - other.Double) < double.Epsilon | ||
&& Decimal == other.Decimal | ||
&& Boolean == other.Boolean; | ||
} | ||
} | ||
} |
Oops, something went wrong.