-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some bugs around nullness and children and added more tests.
- Loading branch information
1 parent
77ab7e9
commit 9fdebe7
Showing
18 changed files
with
176 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
using NUnit.Framework; | ||
|
||
using schema.binary; | ||
using schema.binary.attributes; | ||
using schema.binary.testing; | ||
|
||
|
||
namespace build { | ||
internal partial class PointerToOrNullTests { | ||
[BinarySchema] | ||
public partial class ParentImpl : IBinaryConvertible { | ||
public Child Child { get; } = new(); | ||
|
||
[RAtPositionOrNull(nameof(Child.FieldPointer), 123)] | ||
public int? Field { get; set; } | ||
} | ||
|
||
[BinarySchema] | ||
public partial class Child : IChildOf<ParentImpl>, IBinaryConvertible { | ||
public ParentImpl Parent { get; set; } | ||
|
||
[WPointerToOrNull(nameof(Parent.Field), 123)] | ||
public byte FieldPointer { get; set; } | ||
} | ||
|
||
|
||
[Test] | ||
public async Task TestReadNonnull() { | ||
var ms = new MemoryStream(new byte[] { 1, 12, 0, 0, 0 }); | ||
using var br = new SchemaBinaryReader(ms); | ||
|
||
var parent = br.ReadNew<ParentImpl>(); | ||
|
||
Assert.AreEqual(12, parent.Field.Value); | ||
} | ||
|
||
[Test] | ||
public async Task TestReadNull() { | ||
var ms = new MemoryStream(new byte[] { 123 }); | ||
using var br = new SchemaBinaryReader(ms); | ||
|
||
var parent = br.ReadNew<ParentImpl>(); | ||
|
||
Assert.IsNull(parent.Field); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task TestWriteNonnull() { | ||
var parent = new ParentImpl(); | ||
parent.Field = 12; | ||
|
||
var bw = new SchemaBinaryWriter(); | ||
parent.Write(bw); | ||
|
||
var bytes = await BinarySchemaAssert.GetEndianBinaryWriterBytes(bw); | ||
CollectionAssert.AreEqual(new byte[] { 1, 12, 0, 0, 0 }, bytes); | ||
} | ||
|
||
[Test] | ||
public async Task TestWriteNull() { | ||
var parent = new ParentImpl(); | ||
parent.Field = null; | ||
|
||
var bw = new SchemaBinaryWriter(); | ||
parent.Write(bw); | ||
|
||
var bytes = await BinarySchemaAssert.GetEndianBinaryWriterBytes(bw); | ||
CollectionAssert.AreEqual(new byte[] { 123 }, bytes); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace schema.binary.attributes { | ||
public interface IAtPositionAttribute { | ||
string OffsetName { get; } | ||
int? NullValue { get; } | ||
long? NullValue { get; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace schema.binary.attributes { | ||
public interface IPointerToAttribute { | ||
IChain<IAccessChainNode> AccessChainToOtherMember { get; } | ||
int? NullValue { get; } | ||
long? NullValue { get; } | ||
} | ||
} |
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
Oops, something went wrong.