mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +00:00
[C++] remove static_cast expression (#5440)
* [C++] remove static_cast expression
* [C++] Add unit test for native_type usage
* [C++] Add flatc compilation for native_type_test.fbs
* [C++] update CMakeLists to compile native_type_test.fbs properly
* Update BUILD file for bazel
* [C++] Add generated native_type_test_generated.h and fix arguments for flatc according to CMakeList
* [C++] remove "= default" from constructor to support old compilers
* Update BUILD file for bazel, attempt 2
* [C++] Workaround for MSVC 2010 for the issue with std::vector and explicitly aligned custom data types
* Update BUILD file for bazel, attempt 3
* Update BUILD file for bazel, attempt 4
* Update BUILD file for bazel, attempt 5
* Update BUILD file for bazel, attempt 6
* [C++] Workaround for MSVC 2010 for the issue with std::vector and explicitly aligned custom data types Part 2
* [C++] Keep only one optional parameter to compile_flatbuffers_schema_to_cpp_opt
* native_type_test.fbs style corrected
* [C++] Code style modifications
* [C++] Fix flatc arguments in CMakeLists
* [C++] Remove --gen-compare from default parameters for flatc in CMakeLists
* [C++] Change Vector3D fields from double to float, to have alignment eq. 4 (to support MSVC 2010), plus minor review fix
* [C++] Remove one more #if !defined
* [C++] Restore version with correct static_cast, add the same fix for SortedStructs
* Revert "[C++] Restore version with correct static_cast, add the same fix for SortedStructs"
This reverts commit d61f4d6628.
* [C++] Fix Android.mk
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
7de1a5e347
commit
2d5315ff0e
@@ -35,12 +35,15 @@
|
||||
#include "union_vector/union_vector_generated.h"
|
||||
#include "monster_extra_generated.h"
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1700
|
||||
# include "arrays_test_generated.h"
|
||||
#include "arrays_test_generated.h"
|
||||
#endif
|
||||
|
||||
#include "native_type_test_generated.h"
|
||||
#include "test_assert.h"
|
||||
|
||||
#include "flatbuffers/flexbuffers.h"
|
||||
|
||||
|
||||
// clang-format off
|
||||
// Check that char* and uint8_t* are interoperable types.
|
||||
// The reinterpret_cast<> between the pointers are used to simplify data loading.
|
||||
@@ -2867,6 +2870,29 @@ void FixedLengthArrayTest() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeTypeTest() {
|
||||
const int N = 3;
|
||||
|
||||
Geometry::ApplicationDataT src_data;
|
||||
src_data.vectors.reserve(N);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src_data.vectors.push_back (Native::Vector3D(10 * i + 0.1f, 10 * i + 0.2f, 10 * i + 0.3f));
|
||||
}
|
||||
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
fbb.Finish(Geometry::ApplicationData::Pack(fbb, &src_data));
|
||||
|
||||
auto dstDataT = Geometry::UnPackApplicationData(fbb.GetBufferPointer());
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
Native::Vector3D& v = dstDataT->vectors[i];
|
||||
TEST_EQ(v.x, 10 * i + 0.1f);
|
||||
TEST_EQ(v.y, 10 * i + 0.2f);
|
||||
TEST_EQ(v.z, 10 * i + 0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedLengthArrayJsonTest(bool binary) {
|
||||
// VS10 does not support typed enums, exclude from tests
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1700
|
||||
@@ -3011,6 +3037,7 @@ int FlatBufferTests() {
|
||||
InvalidFloatTest();
|
||||
TestMonsterExtraFloats();
|
||||
FixedLengthArrayTest();
|
||||
NativeTypeTest();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user