-
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.
Allowed multiple WLengthOf attributes on a single field/property.
- Loading branch information
1 parent
72ac6f4
commit a2eeb50
Showing
12 changed files
with
278 additions
and
49 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
Schema Build Tests/attributes/string/StringLengthSourceTests_Multiple.cs
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,57 @@ | ||
using System.IO; | ||
|
||
using schema.binary; | ||
using schema.binary.attributes; | ||
|
||
namespace build { | ||
public partial class StringLengthSourceTests { | ||
[BinarySchema] | ||
public partial class MultipleStringWrapper : IBinaryConvertible { | ||
[WLengthOfString(nameof(String1))] | ||
[WLengthOfString(nameof(String2))] | ||
private uint length_; | ||
|
||
[RStringLengthSource(nameof(length_))] | ||
public string String1 { get; set; } | ||
|
||
[RStringLengthSource(nameof(length_))] | ||
public string String2 { get; set; } | ||
|
||
public override bool Equals(object other) { | ||
if (other is MultipleStringWrapper otherStringWrapper) { | ||
return this.String1.Equals( | ||
otherStringWrapper.String1) && | ||
this.String2.Equals( | ||
otherStringWrapper.String2); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public override string ToString() | ||
=> $"{this.String1}, {this.String2}"; | ||
} | ||
|
||
[Test] | ||
public void TestWriteAndReadMultiple() { | ||
var expectedSw = new MultipleStringWrapper { | ||
String1 = "holy", | ||
String2 = "moly", | ||
}; | ||
|
||
var ms = new MemoryStream(); | ||
|
||
var endianness = Endianness.BigEndian; | ||
var ew = new EndianBinaryWriter(endianness); | ||
|
||
expectedSw.Write(ew); | ||
ew.CompleteAndCopyToDelayed(ms).Wait(); | ||
|
||
ms.Position = 0; | ||
var er = new EndianBinaryReader(ms, endianness); | ||
var actualSw = er.ReadNew<MultipleStringWrapper>(); | ||
|
||
Assert.AreEqual(expectedSw, actualSw); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.