Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes #7986

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,17 @@ if(FLATBUFFERS_BUILD_TESTS)
# The flattest target needs some generated files
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
SET(FLATC_OPT_COMP ${FLATC_OPT};--gen-compare)
SET(FLATC_OPT_SCOPED_ENUMS ${FLATC_OPT_COMP};--scoped-enums)

compile_schema_for_test(tests/alignment_test.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_COMP};--scoped-enums")
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/64bit/evolution/v2.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_COMP}")
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")

if(FLATBUFFERS_CODE_SANITIZE)
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
Expand Down
10 changes: 10 additions & 0 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,16 @@ class Parser : public ParserState {
// These functions return nullptr on success, or an error string,
// which may happen if the flatbuffer cannot be encoded in JSON (e.g.,
// it contains non-UTF-8 byte arrays in String values).
extern bool GenerateTextFromTable(const Parser &parser,
const void *table,
const std::string &tablename,
std::string *text);
extern const char *GenerateText(const Parser &parser, const void *flatbuffer,
std::string *text);
extern const char *GenerateTextFile(const Parser &parser,
const std::string &path,
const std::string &file_name);

extern const char *GenTextFromTable(const Parser &parser, const void *table,
const std::string &tablename,
std::string *text);
Expand Down
20 changes: 20 additions & 0 deletions src/idl_gen_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ static const char *GenerateTextImpl(const Parser &parser, const Table *table,
return nullptr;
}

// Generate a text representation of a flatbuffer in JSON format.
// Deprecated: please use `GenTextFromTable`
bool GenerateTextFromTable(const Parser &parser, const void *table,
const std::string &table_name,
std::string *_text) {
return GenTextFromTable(parser, table, table_name, _text) != nullptr;
}

// Generate a text representation of a flatbuffer in JSON format.
const char *GenTextFromTable(const Parser &parser, const void *table,
const std::string &table_name, std::string *_text) {
Expand All @@ -392,6 +400,12 @@ const char *GenTextFromTable(const Parser &parser, const void *table,
return GenerateTextImpl(parser, root, *struct_def, _text);
}

// Deprecated: please use `GenText`
const char *GenerateText(const Parser &parser, const void *flatbuffer,
std::string *_text) {
return GenText(parser, flatbuffer, _text);
}

// Generate a text representation of a flatbuffer in JSON format.
const char *GenText(const Parser &parser, const void *flatbuffer,
std::string *_text) {
Expand All @@ -406,6 +420,12 @@ static std::string TextFileName(const std::string &path,
return path + file_name + ".json";
}

// Deprecated: please use `GenTextFile`
const char *GenerateTextFile(const Parser &parser, const std::string &path,
const std::string &file_name) {
return GenTextFile(parser, path, file_name);
}

const char *GenTextFile(const Parser &parser, const std::string &path,
const std::string &file_name) {
if (parser.opts.use_flexbuffers) {
Expand Down
3 changes: 2 additions & 1 deletion src/idl_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,8 @@ bool Parser::Supports64BitOffsets() const {
}

bool Parser::SupportsUnionUnderlyingType() const {
return (opts.lang_to_generate & ~(IDLOptions::kCpp | IDLOptions::kTs)) == 0;
return (opts.lang_to_generate & ~(IDLOptions::kCpp | IDLOptions::kTs |
IDLOptions::kBinary)) == 0;
}

Namespace *Parser::UniqueNamespace(Namespace *ns) {
Expand Down
2 changes: 1 addition & 1 deletion tests/alignment_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "alignment_test.h"

#include "alignment_test_generated.h"
#include "tests/alignment_test_generated.h"
#include "flatbuffers/flatbuffer_builder.h"
#include "test_assert.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/reflection_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "reflection_test.h"

#include "arrays_test_generated.h"
#include "tests/arrays_test_generated.h"
#include "flatbuffers/minireflect.h"
#include "flatbuffers/reflection.h"
#include "flatbuffers/reflection_generated.h"
Expand Down
22 changes: 16 additions & 6 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include <memory>
#include <string>

#if defined(__ANDRIOD__)
#define INCLUDE_64_BIT_TESTS 0
#else
#define INCLUDE_64_BIT_TESTS 1
#endif

#include "alignment_test.h"
#include "evolution_test.h"
#include "flatbuffers/flatbuffers.h"
Expand All @@ -38,12 +44,14 @@
#include "parser_test.h"
#include "proto_test.h"
#include "reflection_test.h"
#include "union_vector/union_vector_generated.h"
#include "tests/union_vector/union_vector_generated.h"
#include "union_underlying_type_test_generated.h"
#if !defined(_MSC_VER) || _MSC_VER >= 1700
# include "arrays_test_generated.h"
# include "tests/arrays_test_generated.h"
#endif
#if INCLUDE_64_BIT_TESTS
#include "tests/64bit/offset64_test.h"
#endif
#include "64bit/offset64_test.h"
#include "flexbuffers_test.h"
#include "is_quiet_nan.h"
#include "monster_test_bfbs_generated.h" // Generated using --bfbs-comments --bfbs-builtins --cpp --bfbs-gen-embed
Expand Down Expand Up @@ -1544,9 +1552,9 @@ void DoNotRequireEofTest(const std::string &tests_data_path) {
void UnionUnderlyingTypeTest() {
using namespace UnionUnderlyingType;
TEST_ASSERT(sizeof(ABC) == sizeof(uint32_t));
TEST_ASSERT(ABC::ABC_A == 555);
TEST_ASSERT(ABC::ABC_B == 666);
TEST_ASSERT(ABC::ABC_C == 777);
TEST_ASSERT(static_cast<int32_t>(ABC::A) == 555);
TEST_ASSERT(static_cast<int32_t>(ABC::B) == 666);
TEST_ASSERT(static_cast<int32_t>(ABC::C) == 777);

DT buffer;
AT a;
Expand Down Expand Up @@ -1577,6 +1585,7 @@ void UnionUnderlyingTypeTest() {
}

static void Offset64Tests() {
#if INCLUDE_64_BIT_TESTS
Offset64Test();
Offset64SerializedFirst();
Offset64NestedFlatBuffer();
Expand All @@ -1586,6 +1595,7 @@ static void Offset64Tests() {
Offset64SizePrefix();
Offset64ManyVectors();
Offset64ForceAlign();
#endif
}

int FlatBufferTests(const std::string &tests_data_path) {
Expand Down
Loading