Skip to content

Commit 034ba5c

Browse files
Blind-StrikerAaronontheweb
authored andcommitted
WIP Communicate between framework mscorlib and core framework with Unit 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
1 parent 75c05f6 commit 034ba5c

19 files changed

+385
-8
lines changed

build-system/nightly-builds.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference
33

44
pool:
5-
vmImage: vs2017-win2016
5+
vmImage: windows-2019
66
demands: Cmd
77

88
trigger: none

build-system/pr-validation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
parameters:
1919
name: 'windows_pr'
2020
displayName: 'Windows PR Validation'
21-
vmImage: 'vs2017-win2016'
21+
vmImage: 'windows-2019'
2222
scriptFileName: build.cmd
2323
scriptArgs: all
2424
- template: azure-pipeline.template.yaml

build-system/windows-pr-validation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
- template: azure-pipeline.template.yaml
1818
parameters:
1919
name: Windows
20-
vmImage: 'vs2017-win2016'
20+
vmImage: 'windows-2019'
2121
scriptFileName: build.cmd
2222
scriptArgs: all

build-system/windows-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference
33

44
pool:
5-
vmImage: vs2017-win2016
5+
vmImage: windows-2019
66
demands: Cmd
77

88
trigger:

src/Hyperion.Tests.FSharpData/Hyperion.Tests.FSharpData.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
<Compile Include="Types.fs" />
99
</ItemGroup>
1010

11+
<ItemGroup>
12+
<PackageReference Update="FSharp.Core" Version="4.6.2" />
13+
</ItemGroup>
14+
1115
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.IO;
2+
using Hyperion.Tests.Generator;
3+
using Xunit;
4+
5+
namespace Hyperion.Tests
6+
{
7+
public class CrossFrameworkSerializationTests
8+
{
9+
private readonly Serializer _serializer;
10+
private readonly CrossFrameworkClass _originalObject;
11+
12+
public CrossFrameworkSerializationTests()
13+
{
14+
_serializer = new Serializer();
15+
_originalObject = CrossFrameworkInitializer.Init();
16+
}
17+
18+
[Fact]
19+
public void CanSerializeCrossFramework()
20+
{
21+
const string defaultOutputPath = CrossFrameworkInitializer.DefaultOutputPath;
22+
var testFiles = Directory.GetFiles(defaultOutputPath, "*.tf");
23+
24+
Assert.NotEmpty(testFiles);
25+
26+
foreach (string testFile in testFiles)
27+
{
28+
using (var fileStream = new FileStream(testFile, FileMode.Open))
29+
{
30+
var crossFrameworkClass = _serializer.Deserialize<CrossFrameworkClass>(fileStream);
31+
32+
Assert.Equal(_originalObject, crossFrameworkClass);
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
3+
namespace Hyperion.Tests.Generator
4+
{
5+
public class CrossFrameworkClass
6+
{
7+
public sbyte Sbyte { get; set; }
8+
9+
public short Short { get; set; }
10+
11+
public int Int { get; set; }
12+
13+
public long Long { get; set; }
14+
15+
public byte Byte { get; set; }
16+
17+
public ushort UShort { get; set; }
18+
19+
public uint UInt { get; set; }
20+
21+
public ulong ULong { get; set; }
22+
23+
public char Char { get; set; }
24+
25+
public float Float { get; set; }
26+
27+
public double Double { get; set; }
28+
29+
public decimal Decimal { get; set; }
30+
31+
public bool Boolean { get; set; }
32+
33+
public string String { get; set; }
34+
35+
public DateTime DateTime { get; set; }
36+
37+
public Exception Exception { get; set; }
38+
39+
public CrossFrameworkEnum Enum { get; set; }
40+
41+
public CrossFrameworkStruct Struct { get; set; }
42+
43+
public override bool Equals(object obj)
44+
{
45+
if (!(obj is CrossFrameworkClass))
46+
{
47+
return false;
48+
}
49+
50+
var objectToCompare = (CrossFrameworkClass) obj;
51+
52+
53+
//return Sbyte == objectToCompare.Sbyte
54+
// && Short == objectToCompare.Short
55+
// && Int == objectToCompare.Int
56+
// && Long == objectToCompare.Long
57+
// && Byte == objectToCompare.Byte
58+
// && UShort == objectToCompare.UShort
59+
// && UInt == objectToCompare.UInt
60+
// && ULong == objectToCompare.ULong
61+
// && Char == objectToCompare.Char
62+
// && Math.Abs(Float - objectToCompare.Float) < float.Epsilon
63+
// && Math.Abs(Double - objectToCompare.Double) < double.Epsilon
64+
// && Decimal == objectToCompare.Decimal
65+
// && Boolean == objectToCompare.Boolean
66+
// && String == objectToCompare.String
67+
// && DateTime == objectToCompare.DateTime
68+
// && Exception == objectToCompare.Exception
69+
// && Enum == objectToCompare.Enum
70+
// && Struct.Equals(objectToCompare.Struct);
71+
72+
return Equals(objectToCompare);
73+
74+
}
75+
76+
public override int GetHashCode()
77+
{
78+
unchecked
79+
{
80+
int hashCode = Sbyte.GetHashCode();
81+
hashCode = (hashCode * 397) ^ Short.GetHashCode();
82+
hashCode = (hashCode * 397) ^ Int;
83+
hashCode = (hashCode * 397) ^ Long.GetHashCode();
84+
hashCode = (hashCode * 397) ^ Byte.GetHashCode();
85+
hashCode = (hashCode * 397) ^ UShort.GetHashCode();
86+
hashCode = (hashCode * 397) ^ (int) UInt;
87+
hashCode = (hashCode * 397) ^ ULong.GetHashCode();
88+
hashCode = (hashCode * 397) ^ Char.GetHashCode();
89+
hashCode = (hashCode * 397) ^ Float.GetHashCode();
90+
hashCode = (hashCode * 397) ^ Double.GetHashCode();
91+
hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
92+
hashCode = (hashCode * 397) ^ Boolean.GetHashCode();
93+
hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0);
94+
hashCode = (hashCode * 397) ^ DateTime.GetHashCode();
95+
hashCode = (hashCode * 397) ^ (Exception != null ? Exception.GetHashCode() : 0);
96+
hashCode = (hashCode * 397) ^ (int) Enum;
97+
hashCode = (hashCode * 397) ^ Struct.GetHashCode();
98+
return hashCode;
99+
}
100+
}
101+
102+
private bool Equals(CrossFrameworkClass other)
103+
{
104+
return Sbyte == other.Sbyte
105+
&& Short == other.Short
106+
&& Int == other.Int
107+
&& Long == other.Long
108+
&& Byte == other.Byte
109+
&& UShort == other.UShort
110+
&& UInt == other.UInt
111+
&& ULong == other.ULong
112+
&& Char == other.Char
113+
&& Math.Abs(Float - other.Float) < float.Epsilon
114+
&& Math.Abs(Double - other.Double) < double.Epsilon
115+
&& Decimal == other.Decimal
116+
&& Boolean == other.Boolean
117+
&& string.Equals(String, other.String)
118+
&& DateTime.Equals(other.DateTime)
119+
// && Equals(Exception, other.Exception)
120+
&& Exception.Message == other.Exception.Message
121+
&& Enum == other.Enum
122+
&& Struct.Equals(other.Struct);
123+
}
124+
}
125+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Hyperion.Tests.Generator
2+
{
3+
public enum CrossFrameworkEnum
4+
{
5+
ShortSword,
6+
LongSword,
7+
BastardSword,
8+
Claymore,
9+
Scimitar,
10+
Yatagan,
11+
Katana
12+
}
13+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
3+
namespace Hyperion.Tests.Generator
4+
{
5+
public static class CrossFrameworkInitializer
6+
{
7+
public const string DefaultOutputPath = "../../../testfiles";
8+
9+
public static CrossFrameworkClass Init()
10+
{
11+
return new CrossFrameworkClass()
12+
{
13+
Exception = new Exception("Test message", new ArgumentNullException("param", "Cannot be null")),
14+
DateTime = new DateTime(1944, 6, 6), // DDay
15+
Enum = CrossFrameworkEnum.Yatagan,
16+
String = "On June 6, 1944, more than 160,000 Allied troops landed along a 50-mile stretch of heavily-fortified French coastline",
17+
Struct = new CrossFrameworkStruct()
18+
{
19+
Boolean = true,
20+
Long = long.MaxValue,
21+
Decimal = decimal.MinusOne,
22+
Double = double.MaxValue,
23+
Int = int.MaxValue,
24+
Short = short.MaxValue,
25+
ULong = ulong.MinValue,
26+
Byte = byte.MaxValue,
27+
Char = char.MaxValue,
28+
Float = float.MinValue,
29+
UShort = ushort.MinValue,
30+
UInt = uint.MaxValue,
31+
Sbyte = sbyte.MaxValue
32+
},
33+
Decimal = decimal.MaxValue,
34+
Float = float.MaxValue,
35+
Long = long.MinValue,
36+
Int = int.MinValue,
37+
Double = double.Epsilon,
38+
Char = char.MaxValue,
39+
Byte = byte.MaxValue,
40+
Sbyte = sbyte.MaxValue,
41+
Short = short.MaxValue,
42+
UInt = uint.MaxValue,
43+
ULong = ulong.MaxValue,
44+
UShort = ushort.MaxValue,
45+
Boolean = true
46+
};
47+
}
48+
}
49+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
3+
namespace Hyperion.Tests.Generator
4+
{
5+
public struct CrossFrameworkStruct
6+
{
7+
public sbyte Sbyte { get; set; }
8+
9+
public short Short { get; set; }
10+
11+
public int Int { get; set; }
12+
13+
public long Long { get; set; }
14+
15+
public byte Byte { get; set; }
16+
17+
public ushort UShort { get; set; }
18+
19+
public uint UInt { get; set; }
20+
21+
public ulong ULong { get; set; }
22+
23+
public char Char { get; set; }
24+
25+
public float Float { get; set; }
26+
27+
public double Double { get; set; }
28+
29+
public decimal Decimal { get; set; }
30+
31+
public bool Boolean { get; set; }
32+
33+
public override bool Equals(object obj)
34+
{
35+
if (!(obj is CrossFrameworkStruct))
36+
{
37+
return false;
38+
}
39+
40+
var objectToCompare = (CrossFrameworkStruct)obj;
41+
42+
return Equals(objectToCompare);
43+
}
44+
45+
public override int GetHashCode()
46+
{
47+
unchecked
48+
{
49+
int hashCode = Sbyte.GetHashCode();
50+
hashCode = (hashCode * 397) ^ Short.GetHashCode();
51+
hashCode = (hashCode * 397) ^ Int;
52+
hashCode = (hashCode * 397) ^ Long.GetHashCode();
53+
hashCode = (hashCode * 397) ^ Byte.GetHashCode();
54+
hashCode = (hashCode * 397) ^ UShort.GetHashCode();
55+
hashCode = (hashCode * 397) ^ (int) UInt;
56+
hashCode = (hashCode * 397) ^ ULong.GetHashCode();
57+
hashCode = (hashCode * 397) ^ Char.GetHashCode();
58+
hashCode = (hashCode * 397) ^ Float.GetHashCode();
59+
hashCode = (hashCode * 397) ^ Double.GetHashCode();
60+
hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
61+
hashCode = (hashCode * 397) ^ Boolean.GetHashCode();
62+
return hashCode;
63+
}
64+
}
65+
66+
private bool Equals(CrossFrameworkStruct other)
67+
{
68+
return Sbyte == other.Sbyte
69+
&& Short == other.Short
70+
&& Int == other.Int
71+
&& Long == other.Long
72+
&& Byte == other.Byte
73+
&& UShort == other.UShort
74+
&& UInt == other.UInt
75+
&& ULong == other.ULong
76+
&& Char == other.Char
77+
&& Math.Abs(Float - other.Float) < float.Epsilon
78+
&& Math.Abs(Double - other.Double) < double.Epsilon
79+
&& Decimal == other.Decimal
80+
&& Boolean == other.Boolean;
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)