summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2014-09-23 11:55:42 -0700
committerWouter van Oortmerssen <wvo@google.com>2014-09-23 17:25:50 -0700
commit7b8053570e4407cedfde8d32f6a3c59e5585ef7b (patch)
tree4eb0b036c80e76a341953a13724fcec00a22ec6c /tests
parent85c9c83844b494b5422e6ad2fbe8ec1a183d96be (diff)
downloadflatbuffers-7b8053570e4407cedfde8d32f6a3c59e5585ef7b.tar.gz
flatbuffers-7b8053570e4407cedfde8d32f6a3c59e5585ef7b.tar.bz2
flatbuffers-7b8053570e4407cedfde8d32f6a3c59e5585ef7b.zip
Enums in C++ are now strongly typed.
Accessors and constructors now take enum types rather than ints. Bug: 16570507 Change-Id: I4b50fd64ad2e662ea2481bc0ccea784326fb31c0 Tested: on Linux and Windows.
Diffstat (limited to 'tests')
-rw-r--r--tests/FlatBuffers.Test/FlatBuffersExampleTests.cs4
-rwxr-xr-xtests/JavaTest.java4
-rwxr-xr-xtests/monster_test.fbs2
-rwxr-xr-xtests/monster_test_generated.h26
-rw-r--r--tests/monsterdata_test.golden2
-rwxr-xr-xtests/monsterdata_test.json2
-rw-r--r--tests/monsterdata_test.monbin256 -> 256 bytes
-rw-r--r--tests/test.cpp2
8 files changed, 21 insertions, 21 deletions
diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
index d81a3956..4fcc83ea 100644
--- a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
+++ b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
@@ -68,7 +68,7 @@ namespace FlatBuffers.Test
Monster.StartMonster(fbb);
Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
- (sbyte)4, (short)5, (sbyte)6));
+ Color.Green, (short)5, (sbyte)6));
Monster.AddHp(fbb, (short)80);
Monster.AddName(fbb, str);
Monster.AddInventory(fbb, inv);
@@ -105,7 +105,7 @@ namespace FlatBuffers.Test
Assert.AreEqual(3.0f, pos.Z());
Assert.AreEqual(3.0f, pos.Test1());
- Assert.AreEqual((sbyte)4, pos.Test2());
+ Assert.AreEqual(Color.Green, pos.Test2());
var t = pos.Test3();
Assert.AreEqual((short)5, t.A());
Assert.AreEqual((sbyte)6, t.B());
diff --git a/tests/JavaTest.java b/tests/JavaTest.java
index 60956c7b..f6dfb6ab 100755
--- a/tests/JavaTest.java
+++ b/tests/JavaTest.java
@@ -72,7 +72,7 @@ class JavaTest {
Monster.startMonster(fbb);
Monster.addPos(fbb, Vec3.createVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
- (byte)4, (short)5, (byte)6));
+ Color.Green, (short)5, (byte)6));
Monster.addHp(fbb, (short)80);
Monster.addName(fbb, str);
Monster.addInventory(fbb, inv);
@@ -135,7 +135,7 @@ class JavaTest {
TestEq(pos.y(), 2.0f);
TestEq(pos.z(), 3.0f);
TestEq(pos.test1(), 3.0);
- TestEq(pos.test2(), (byte)4);
+ TestEq(pos.test2(), Color.Green);
Test t = pos.test3();
TestEq(t.a(), (short)5);
TestEq(t.b(), (byte)6);
diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs
index 5035252d..8de9c033 100755
--- a/tests/monster_test.fbs
+++ b/tests/monster_test.fbs
@@ -15,7 +15,7 @@ struct Vec3 (force_align: 16) {
y:float;
z:float;
test1:double;
- test2:byte;
+ test2:Color;
test3:Test;
}
diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h
index f7d351ef..6345a764 100755
--- a/tests/monster_test_generated.h
+++ b/tests/monster_test_generated.h
@@ -18,7 +18,7 @@ struct Test;
struct Vec3;
struct Monster;
-enum {
+enum Color {
Color_Red = 1,
Color_Green = 2,
Color_Blue = 8
@@ -29,9 +29,9 @@ inline const char **EnumNamesColor() {
return names;
}
-inline const char *EnumNameColor(int e) { return EnumNamesColor()[e - Color_Red]; }
+inline const char *EnumNameColor(Color e) { return EnumNamesColor()[e - Color_Red]; }
-enum {
+enum Any {
Any_NONE = 0,
Any_Monster = 1
};
@@ -41,7 +41,7 @@ inline const char **EnumNamesAny() {
return names;
}
-inline const char *EnumNameAny(int e) { return EnumNamesAny()[e]; }
+inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; }
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);
@@ -73,14 +73,14 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 {
int16_t __padding2;
public:
- Vec3(float x, float y, float z, double test1, int8_t test2, const Test &test3)
- : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)), __padding0(0), test1_(flatbuffers::EndianScalar(test1)), test2_(flatbuffers::EndianScalar(test2)), __padding1(0), test3_(test3), __padding2(0) { (void)__padding0; (void)__padding1; (void)__padding2; }
+ Vec3(float x, float y, float z, double test1, Color test2, const Test &test3)
+ : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)), __padding0(0), test1_(flatbuffers::EndianScalar(test1)), test2_(flatbuffers::EndianScalar(static_cast<int8_t>(test2))), __padding1(0), test3_(test3), __padding2(0) { (void)__padding0; (void)__padding1; (void)__padding2; }
float x() const { return flatbuffers::EndianScalar(x_); }
float y() const { return flatbuffers::EndianScalar(y_); }
float z() const { return flatbuffers::EndianScalar(z_); }
double test1() const { return flatbuffers::EndianScalar(test1_); }
- int8_t test2() const { return flatbuffers::EndianScalar(test2_); }
+ Color test2() const { return static_cast<Color>(flatbuffers::EndianScalar(test2_)); }
const Test &test3() const { return test3_; }
};
STRUCT_END(Vec3, 32);
@@ -91,8 +91,8 @@ struct Monster : private flatbuffers::Table {
int16_t hp() const { return GetField<int16_t>(8, 100); }
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(10); }
const flatbuffers::Vector<uint8_t> *inventory() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(14); }
- int8_t color() const { return GetField<int8_t>(16, 8); }
- uint8_t test_type() const { return GetField<uint8_t>(18, 0); }
+ Color color() const { return static_cast<Color>(GetField<int8_t>(16, 8)); }
+ Any test_type() const { return static_cast<Any>(GetField<uint8_t>(18, 0)); }
const void *test() const { return GetPointer<const void *>(20); }
const flatbuffers::Vector<const Test *> *test4() const { return GetPointer<const flatbuffers::Vector<const Test *> *>(22); }
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *testarrayofstring() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(24); }
@@ -141,8 +141,8 @@ struct MonsterBuilder {
void add_hp(int16_t hp) { fbb_.AddElement<int16_t>(8, hp, 100); }
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(10, name); }
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) { fbb_.AddOffset(14, inventory); }
- void add_color(int8_t color) { fbb_.AddElement<int8_t>(16, color, 8); }
- void add_test_type(uint8_t test_type) { fbb_.AddElement<uint8_t>(18, test_type, 0); }
+ void add_color(Color color) { fbb_.AddElement<int8_t>(16, static_cast<int8_t>(color), 8); }
+ void add_test_type(Any test_type) { fbb_.AddElement<uint8_t>(18, static_cast<uint8_t>(test_type), 0); }
void add_test(flatbuffers::Offset<void> test) { fbb_.AddOffset(20, test); }
void add_test4(flatbuffers::Offset<flatbuffers::Vector<const Test *>> test4) { fbb_.AddOffset(22, test4); }
void add_testarrayofstring(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> testarrayofstring) { fbb_.AddOffset(24, testarrayofstring); }
@@ -165,8 +165,8 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
int16_t hp = 100,
flatbuffers::Offset<flatbuffers::String> name = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
- int8_t color = 8,
- uint8_t test_type = 0,
+ Color color = Color_Blue,
+ Any test_type = Any_NONE,
flatbuffers::Offset<void> test = 0,
flatbuffers::Offset<flatbuffers::Vector<const Test *>> test4 = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> testarrayofstring = 0,
diff --git a/tests/monsterdata_test.golden b/tests/monsterdata_test.golden
index 9e410342..a79095a1 100644
--- a/tests/monsterdata_test.golden
+++ b/tests/monsterdata_test.golden
@@ -4,7 +4,7 @@
y: 2,
z: 3,
test1: 3,
- test2: 4,
+ test2: Green,
test3: {
a: 5,
b: 6
diff --git a/tests/monsterdata_test.json b/tests/monsterdata_test.json
index 9e410342..a79095a1 100755
--- a/tests/monsterdata_test.json
+++ b/tests/monsterdata_test.json
@@ -4,7 +4,7 @@
y: 2,
z: 3,
test1: 3,
- test2: 4,
+ test2: Green,
test3: {
a: 5,
b: 6
diff --git a/tests/monsterdata_test.mon b/tests/monsterdata_test.mon
index f92ed267..e20e1a98 100644
--- a/tests/monsterdata_test.mon
+++ b/tests/monsterdata_test.mon
Binary files differ
diff --git a/tests/test.cpp b/tests/test.cpp
index f90f3a44..963eabd7 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -63,7 +63,7 @@ void lcg_reset() { lcg_seed = 48271; }
std::string CreateFlatBufferTest() {
flatbuffers::FlatBufferBuilder builder;
- auto vec = Vec3(1, 2, 3, 0, 0, Test(10, 20));
+ auto vec = Vec3(1, 2, 3, 0, Color_Red, Test(10, 20));
auto name = builder.CreateString("MyMonster");