-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Communicate between framework mscorlib and core framework with Unit Tests #116
Changes from all commits
c0c1ad1
217aa61
d82a50a
b688a73
cd68375
98bc2b2
7653d1a
72a878a
9616faf
bcff54b
7b2b127
e5cfd40
5aa54b2
360b0a5
f3c3c05
305885c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, this the only way to do it - have to actually load the sucker and work the payloads on both ends. |
||
{ | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
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); | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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 | ||
}; | ||
} | ||
} | ||
} |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM - validates that all of the primitives are covered. |
||
{ | ||
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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM