summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDerek Bailey <derekbailey@google.com>2023-04-28 13:40:38 -0700
committerGitHub <noreply@github.com>2023-04-28 13:40:38 -0700
commit966aae2144e5cf8850eba0101016307d0ca58ee0 (patch)
treedff6d6bc6a90cbccfab199e708d267eaee6ddb6e /tests
parente7dc252b0e86c440c782975c03de309a42593250 (diff)
downloadflatbuffers-966aae2144e5cf8850eba0101016307d0ca58ee0.tar.gz
flatbuffers-966aae2144e5cf8850eba0101016307d0ca58ee0.tar.bz2
flatbuffers-966aae2144e5cf8850eba0101016307d0ca58ee0.zip
inject no long for FBS generation to remove logs in flattests (#7926)
* inject no long for FBS generation to remove logs in flattests * updated blaze rules
Diffstat (limited to 'tests')
-rw-r--r--tests/BUILD.bazel1
-rw-r--r--tests/proto_test.cpp25
-rw-r--r--tests/test_assert.h21
3 files changed, 37 insertions, 10 deletions
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index ee142724..8d815b52 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -113,6 +113,7 @@ cc_test(
":monster_test_cc_fbs",
":native_type_test_cc_fbs",
"//:flatbuffers",
+ "//src:generate_fbs",
],
)
diff --git a/tests/proto_test.cpp b/tests/proto_test.cpp
index b9fd10b0..6c98bc14 100644
--- a/tests/proto_test.cpp
+++ b/tests/proto_test.cpp
@@ -1,5 +1,7 @@
#include "proto_test.h"
+#include "flatbuffers/code_generator.h"
+#include "idl_gen_fbs.h"
#include "test_assert.h"
namespace flatbuffers {
@@ -15,7 +17,7 @@ void RunTest(const flatbuffers::IDLOptions &opts, const std::string &proto_path,
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
// Generate fbs.
- auto fbs = flatbuffers::GenerateFBS(parser, "test");
+ auto fbs = flatbuffers::GenerateFBS(parser, "test", true);
// Ensure generated file is parsable.
flatbuffers::Parser parser2;
@@ -25,7 +27,7 @@ void RunTest(const flatbuffers::IDLOptions &opts, const std::string &proto_path,
flatbuffers::Parser import_parser(opts);
TEST_EQ(import_parser.Parse(import_proto_file.c_str(), include_directories),
true);
- auto import_fbs = flatbuffers::GenerateFBS(import_parser, "test");
+ auto import_fbs = flatbuffers::GenerateFBS(import_parser, "test", true);
// Since `imported.fbs` isn't in the filesystem AbsolutePath can't figure it
// out by itself. We manually construct it so Parser works.
std::string imported_fbs = flatbuffers::PosixPath(
@@ -222,6 +224,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
std::string proto_file;
+ std::unique_ptr<CodeGenerator> fbs_generator = NewFBSCodeGenerator(true);
+
// Parse proto with non positive id.
{
flatbuffers::Parser parser(opts);
@@ -230,8 +234,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
- auto fbs = flatbuffers::GenerateFBS(parser, "test");
- TEST_EQ(fbs.empty(), true);
+ TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
+ CodeGenerator::Status::OK);
}
// Parse proto with twice id.
@@ -241,8 +245,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
- auto fbs = flatbuffers::GenerateFBS(parser, "test");
- TEST_EQ(fbs.empty(), true);
+ TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
+ CodeGenerator::Status::OK);
}
// Parse proto with using reserved id.
@@ -252,8 +256,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
- auto fbs = flatbuffers::GenerateFBS(parser, "test");
- TEST_EQ(fbs.empty(), true);
+ TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
+ CodeGenerator::Status::OK);
}
// Parse proto with error on gap.
@@ -264,8 +268,9 @@ void ParseCorruptedProto(const std::string &proto_path) {
&proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
- auto fbs = flatbuffers::GenerateFBS(parser, "test");
- TEST_EQ(fbs.empty(), true);
+
+ TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
+ CodeGenerator::Status::OK);
}
}
diff --git a/tests/test_assert.h b/tests/test_assert.h
index 9d5f7801..8b413382 100644
--- a/tests/test_assert.h
+++ b/tests/test_assert.h
@@ -17,6 +17,7 @@
#endif
#define TEST_EQ(exp, val) TestEq(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")
+#define TEST_NE(exp, val) TestNe(exp, val, "'" #exp "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_ASSERT(val) TestEq(true, !!(val), "'" "true" "' != '" #val "'", __FILE__, __LINE__, "")
#define TEST_NOTNULL(val) TestEq(true, (val) != nullptr, "'" "nullptr" "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_EQ_STR(exp, val) TestEqStr(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")
@@ -106,4 +107,24 @@ inline void TestEq<std::string, std::string>(std::string expval,
}
}
+template<typename T, typename U>
+void TestNe(T expval, U val, const char *exp, const char *file, int line,
+ const char *func) {
+ if (static_cast<U>(expval) == val) {
+ TestFail(flatbuffers::NumToString(scalar_as_underlying(expval)).c_str(),
+ flatbuffers::NumToString(scalar_as_underlying(val)).c_str(), exp,
+ file, line, func);
+ }
+}
+
+template<>
+inline void TestNe<std::string, std::string>(std::string expval,
+ std::string val, const char *exp,
+ const char *file, int line,
+ const char *func) {
+ if (expval == val) {
+ TestFail(expval.c_str(), val.c_str(), exp, file, line, func);
+ }
+}
+
#endif // !TEST_ASSERT_H