Skip to content

Commit

Permalink
Add test of Option<None> enum using a future monster on the wire.
Browse files Browse the repository at this point in the history
  • Loading branch information
vglavnyy committed Nov 6, 2019
1 parent 486f657 commit f345fe9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tests/monsterdata_javascript_wire.mon
tests/monsterdata_lobster_wire.mon
tests/monsterdata_rust_wire.mon
tests/unicode_test.mon
tests/monsterdata_unknown.mon
tests/ts/
tests/php/
CMakeLists.txt.user
Expand Down
2 changes: 2 additions & 0 deletions tests/generate_code.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ IF NOT "%MONSTER_EXTRA%"=="skip" (
@echo monster_extra.fbs skipped (the strtod function from MSVC2013 or older doesn't support NaN/Inf arguments)
)

..\%buildtype%\flatc.exe --binary -I include_test monster_test.fbs monsterdata_unknown.json || goto FAIL

cd ../samples
..\%buildtype%\flatc.exe --cpp --lobster --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr monster.fbs || goto FAIL
..\%buildtype%\flatc.exe -b --schema --bfbs-comments --bfbs-builtins monster.fbs || goto FAIL
Expand Down
3 changes: 3 additions & 0 deletions tests/generate_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ set -e
../flatc --jsonschema --schema -I include_test monster_test.fbs
../flatc --cpp --java --kotlin --csharp --python --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes monster_extra.fbs monsterdata_extra.json
../flatc --cpp --java --csharp --python --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes --scoped-enums --jsonschema --cpp-ptr-type flatbuffers::unique_ptr arrays_test.fbs

../flatc --binary -I include_test monster_test.fbs monsterdata_unknown.json

cd ../samples
../flatc --cpp --lobster --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr monster.fbs
../flatc -b --schema --bfbs-comments --bfbs-builtins monster.fbs
Expand Down
5 changes: 5 additions & 0 deletions tests/monsterdata_unknown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
name: "FromFuture",
// Race=-127 is unknown Race, not defined in the monster_test.fbs schema.
signed_enum: -127,
}
11 changes: 11 additions & 0 deletions tests/rust_usage_test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,17 @@ fn write_example_wire_data_to_file() {
f.write_all(b.finished_data()).unwrap();
}

#[test]
fn binary_data_from_future_source() {
let bytes = load_file("../monsterdata_unknown.mon").expect("missing monsterdata_unknown.mon");
let correct = my_game::example::monster_buffer_has_identifier(&bytes);
assert!(correct);

let m = my_game::example::get_root_as_monster(&bytes);
assert_eq!(m.name(), "FromFuture");
assert!(m.signed_enum().is_none());
}

fn load_file(filename: &str) -> Result<Vec<u8>, std::io::Error> {
use std::io::Read;
let mut f = std::fs::File::open(filename)?;
Expand Down

0 comments on commit f345fe9

Please sign in to comment.