diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2016-01-20 13:46:49 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2016-01-20 13:46:49 -0800 |
commit | db0727e9430cac312b31d597be3360d626cc5ab5 (patch) | |
tree | 2e3cd9e1ccd3908450cc9ae7e7933fd6a3694a17 /tests | |
parent | abd6a1427e786508183bf9c4ac1f0737f820455d (diff) | |
parent | fff4590faf2a0dd57e741bb6ee4efbc7e7667a36 (diff) | |
download | flatbuffers-db0727e9430cac312b31d597be3360d626cc5ab5.tar.gz flatbuffers-db0727e9430cac312b31d597be3360d626cc5ab5.tar.bz2 flatbuffers-db0727e9430cac312b31d597be3360d626cc5ab5.zip |
Merge pull request #3734 from evolutional/cs-forcedefaults
Implemented ForceDefaults option on C# FlatBufferBuilder.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FlatBuffers.Test/FlatBufferBuilderTests.cs | 249 | ||||
-rw-r--r-- | tests/FlatBuffers.Test/FlatBuffers.Test.csproj | 1 |
2 files changed, 250 insertions, 0 deletions
diff --git a/tests/FlatBuffers.Test/FlatBufferBuilderTests.cs b/tests/FlatBuffers.Test/FlatBufferBuilderTests.cs new file mode 100644 index 00000000..529c813b --- /dev/null +++ b/tests/FlatBuffers.Test/FlatBufferBuilderTests.cs @@ -0,0 +1,249 @@ +/* + * Copyright 2016 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace FlatBuffers.Test +{ + [FlatBuffersTestClass] + public class FlatBufferBuilderTests + { + private FlatBufferBuilder CreateBuffer(bool forceDefaults = true) + { + var fbb = new FlatBufferBuilder(16) {ForceDefaults = forceDefaults}; + fbb.StartObject(1); + return fbb; + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddBool_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddBool(0, false, false); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(bool), endOffset-storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddSByte_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddSbyte(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(sbyte), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddByte_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddByte(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(byte), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddShort_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddShort(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(short), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddUShort_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddUshort(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(ushort), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddInt_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddInt(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(int), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddUInt_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddUint(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(uint), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddLong_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddLong(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(long), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddULong_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddUlong(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(ulong), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddFloat_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddFloat(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(float), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WithForceDefaults_WhenAddDouble_AndDefaultValue_OffsetIncreasesBySize() + { + var fbb = CreateBuffer(); + var storedOffset = fbb.Offset; + fbb.AddDouble(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(sizeof(double), endOffset - storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddBool_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddBool(0, false, false); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddSByte_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddSbyte(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddByte_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddByte(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddShort_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddShort(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddUShort_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddUshort(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddInt_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddInt(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddUInt_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddUint(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddLong_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddLong(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddULong_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddUlong(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddFloat_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddFloat(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + + [FlatBuffersTestMethod] + public void FlatBufferBuilder_WhenAddDouble_AndDefaultValue_OffsetIsUnchanged() + { + var fbb = CreateBuffer(false); + var storedOffset = fbb.Offset; + fbb.AddDouble(0, 0, 0); + var endOffset = fbb.Offset; + Assert.AreEqual(endOffset, storedOffset); + } + } +} diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj index 13b1faae..4055fa6a 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj @@ -91,6 +91,7 @@ </Compile> <Compile Include="Assert.cs" /> <Compile Include="ByteBufferTests.cs" /> + <Compile Include="FlatBufferBuilderTests.cs" /> <Compile Include="FlatBuffersFuzzTests.cs" /> <Compile Include="FlatBuffersTestClassAttribute.cs" /> <Compile Include="FlatBuffersTestMethodAttribute.cs" /> |