diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2015-12-09 12:57:12 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2015-12-09 12:57:12 -0800 |
commit | c44bc6a71993e7147db1ece3f1ee84d7c829c2b3 (patch) | |
tree | 16f17186212d6a702cad27522fdbd5e8b20481bb /tests | |
parent | 6fba6b6e714c5b948e6b0c64d5157710668f302b (diff) | |
parent | 96cd275603573ebdea3b6c61d459ea438f3b1525 (diff) | |
download | flatbuffers-c44bc6a71993e7147db1ece3f1ee84d7c829c2b3.tar.gz flatbuffers-c44bc6a71993e7147db1ece3f1ee84d7c829c2b3.tar.bz2 flatbuffers-c44bc6a71993e7147db1ece3f1ee84d7c829c2b3.zip |
Merge branch 'master' of https://github.com/google/flatbuffers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FlatBuffers.Test/Assert.cs | 8 | ||||
-rw-r--r-- | tests/FlatBuffers.Test/FlatBuffersExampleTests.cs | 13 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.cs | 5 | ||||
-rw-r--r-- | tests/MyGame/Example/Stat.cs | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Test.cs | 1 | ||||
-rw-r--r-- | tests/MyGame/Example/TestSimpleTableWithEnum.cs | 1 | ||||
-rw-r--r-- | tests/MyGame/Example/Vec3.cs | 1 |
7 files changed, 31 insertions, 0 deletions
diff --git a/tests/FlatBuffers.Test/Assert.cs b/tests/FlatBuffers.Test/Assert.cs index 1bcf95f2..83344cf3 100644 --- a/tests/FlatBuffers.Test/Assert.cs +++ b/tests/FlatBuffers.Test/Assert.cs @@ -107,6 +107,14 @@ namespace FlatBuffers.Test } } + public static void IsFalse(bool value) + { + if (value) + { + throw new AssertFailedException(false, value); + } + } + public static void Throws<T>(Action action) where T : Exception { var caught = false; diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs index 53d74c39..43754c77 100644 --- a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs +++ b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs @@ -15,6 +15,7 @@ */ using System.IO; +using System.Text; using MyGame.Example; namespace FlatBuffers.Test @@ -184,6 +185,18 @@ namespace FlatBuffers.Test Assert.AreEqual("test2", monster.GetTestarrayofstring(1)); Assert.AreEqual(false, monster.Testbool); + + var nameBytes = monster.GetNameBytes().Value; + Assert.AreEqual("MyMonster", Encoding.UTF8.GetString(nameBytes.Array, nameBytes.Offset, nameBytes.Count)); + + if (0 == monster.TestarrayofboolsLength) + { + Assert.IsFalse(monster.GetTestarrayofboolsBytes().HasValue); + } + else + { + Assert.IsTrue(monster.GetTestarrayofboolsBytes().HasValue); + } } [FlatBuffersTestMethod] diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index c31bd7b5..b324a8d5 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -3,6 +3,7 @@ namespace MyGame.Example { +using System; using FlatBuffers; /// an example documentation comment: monster object @@ -19,8 +20,10 @@ public sealed class Monster : Table { public short Hp { get { int o = __offset(8); return o != 0 ? bb.GetShort(o + bb_pos) : (short)100; } } public bool MutateHp(short hp) { int o = __offset(8); if (o != 0) { bb.PutShort(o + bb_pos, hp); return true; } else { return false; } } public string Name { get { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; } } + public ArraySegment<byte>? GetNameBytes() { return __vector_as_arraysegment(10); } public byte GetInventory(int j) { int o = __offset(14); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; } public int InventoryLength { get { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } } + public ArraySegment<byte>? GetInventoryBytes() { return __vector_as_arraysegment(14); } public bool MutateInventory(int j, byte inventory) { int o = __offset(14); if (o != 0) { bb.Put(__vector(o) + j * 1, inventory); return true; } else { return false; } } public Color Color { get { int o = __offset(16); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : Color.Blue; } } public bool MutateColor(Color color) { int o = __offset(16); if (o != 0) { bb.PutSbyte(o + bb_pos, (sbyte)color); return true; } else { return false; } } @@ -41,6 +44,7 @@ public sealed class Monster : Table { public Monster GetEnemy(Monster obj) { int o = __offset(28); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } public byte GetTestnestedflatbuffer(int j) { int o = __offset(30); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; } public int TestnestedflatbufferLength { get { int o = __offset(30); return o != 0 ? __vector_len(o) : 0; } } + public ArraySegment<byte>? GetTestnestedflatbufferBytes() { return __vector_as_arraysegment(30); } public bool MutateTestnestedflatbuffer(int j, byte testnestedflatbuffer) { int o = __offset(30); if (o != 0) { bb.Put(__vector(o) + j * 1, testnestedflatbuffer); return true; } else { return false; } } public Stat Testempty { get { return GetTestempty(new Stat()); } } public Stat GetTestempty(Stat obj) { int o = __offset(32); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } @@ -64,6 +68,7 @@ public sealed class Monster : Table { public bool MutateTesthashu64Fnv1a(ulong testhashu64_fnv1a) { int o = __offset(50); if (o != 0) { bb.PutUlong(o + bb_pos, testhashu64_fnv1a); return true; } else { return false; } } public bool GetTestarrayofbools(int j) { int o = __offset(52); return o != 0 ? 0!=bb.Get(__vector(o) + j * 1) : false; } public int TestarrayofboolsLength { get { int o = __offset(52); return o != 0 ? __vector_len(o) : 0; } } + public ArraySegment<byte>? GetTestarrayofboolsBytes() { return __vector_as_arraysegment(52); } public bool MutateTestarrayofbools(int j, bool testarrayofbools) { int o = __offset(52); if (o != 0) { bb.Put(__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } } public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(25); } diff --git a/tests/MyGame/Example/Stat.cs b/tests/MyGame/Example/Stat.cs index 22a2e009..2b3f5375 100644 --- a/tests/MyGame/Example/Stat.cs +++ b/tests/MyGame/Example/Stat.cs @@ -3,6 +3,7 @@ namespace MyGame.Example { +using System; using FlatBuffers; public sealed class Stat : Table { @@ -11,6 +12,7 @@ public sealed class Stat : Table { public Stat __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } public string Id { get { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } } + public ArraySegment<byte>? GetIdBytes() { return __vector_as_arraysegment(4); } public long Val { get { int o = __offset(6); return o != 0 ? bb.GetLong(o + bb_pos) : (long)0; } } public bool MutateVal(long val) { int o = __offset(6); if (o != 0) { bb.PutLong(o + bb_pos, val); return true; } else { return false; } } public ushort Count { get { int o = __offset(8); return o != 0 ? bb.GetUshort(o + bb_pos) : (ushort)0; } } diff --git a/tests/MyGame/Example/Test.cs b/tests/MyGame/Example/Test.cs index 182c26b7..5bd2e58d 100644 --- a/tests/MyGame/Example/Test.cs +++ b/tests/MyGame/Example/Test.cs @@ -3,6 +3,7 @@ namespace MyGame.Example { +using System; using FlatBuffers; public sealed class Test : Struct { diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.cs b/tests/MyGame/Example/TestSimpleTableWithEnum.cs index f21441d1..daaa0b97 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.cs +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.cs @@ -3,6 +3,7 @@ namespace MyGame.Example { +using System; using FlatBuffers; public sealed class TestSimpleTableWithEnum : Table { diff --git a/tests/MyGame/Example/Vec3.cs b/tests/MyGame/Example/Vec3.cs index 56b9b475..e5fa2f67 100644 --- a/tests/MyGame/Example/Vec3.cs +++ b/tests/MyGame/Example/Vec3.cs @@ -3,6 +3,7 @@ namespace MyGame.Example { +using System; using FlatBuffers; public sealed class Vec3 : Struct { |