• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2021 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16set -e
17
18commandline="'$*'"
19
20if [[ $commandline == *"--cpp-std c++0x"* ]]; then
21  TEST_CPP_FLAGS="--cpp-std c++0x"
22else
23  # --cpp-std is defined by flatc default settings.
24  TEST_CPP_FLAGS=
25fi
26
27TEST_CPP_FLAGS="--gen-compare --cpp-ptr-type flatbuffers::unique_ptr $TEST_CPP_FLAGS"
28TEST_CS_FLAGS="--cs-gen-json-serializer"
29TEST_TS_FLAGS="--gen-name-strings"
30TEST_BASE_FLAGS="--reflect-names --gen-mutable --gen-object-api"
31TEST_RUST_FLAGS="$TEST_BASE_FLAGS --gen-name-strings"
32TEST_NOINCL_FLAGS="$TEST_BASE_FLAGS --no-includes"
33
34../flatc --binary --cpp --java --kotlin  --csharp --dart --go --lobster --lua --ts --php --grpc \
35$TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I include_test monster_test.fbs monsterdata_test.json
36../flatc --rust $TEST_RUST_FLAGS -I include_test monster_test.fbs monsterdata_test.json
37
38../flatc --python $TEST_BASE_FLAGS -I include_test monster_test.fbs monsterdata_test.json
39
40../flatc --cpp --java --kotlin --csharp --dart --go --binary --lobster --lua --ts --php --python \
41$TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_TS_FLAGS -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
42
43# For Rust we currently generate two independent schemas, with namespace_test2
44# duplicating the types in namespace_test1
45../flatc --rust --gen-all $TEST_RUST_FLAGS -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
46
47../flatc --cpp --java --kotlin --csharp --ts --php $TEST_BASE_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_TS_FLAGS -o union_vector ./union_vector/union_vector.fbs
48../flatc --ts --gen-name-strings --gen-mutable $TEST_BASE_FLAGS $TEST_TS_FLAGS -I include_test monster_test.fbs
49../flatc $TEST_BASE_FLAGS $TEST_TS_FLAGS -b -I include_test monster_test.fbs unicode_test.json
50../flatc --ts --gen-name-strings $TEST_BASE_FLAGS $TEST_TS_FLAGS -o union_vector union_vector/union_vector.fbs
51../flatc --rust -I include_test -o include_test include_test/include_test1.fbs
52../flatc --rust -I include_test -o include_test/sub include_test/sub/include_test2.fbs
53../flatc -b --schema --bfbs-comments --bfbs-builtins -I include_test monster_test.fbs
54../flatc --cpp --bfbs-comments --bfbs-builtins --bfbs-gen-embed $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS -I include_test monster_test.fbs
55../flatc -b --schema --bfbs-comments --bfbs-builtins -I include_test arrays_test.fbs
56../flatc --jsonschema --schema -I include_test monster_test.fbs
57../flatc --cpp --java --kotlin --csharp --python $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS monster_extra.fbs monsterdata_extra.json
58../flatc --cpp --java --csharp --jsonschema --rust $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS --scoped-enums arrays_test.fbs
59../flatc --python $TEST_BASE_FLAGS arrays_test.fbs
60../flatc --dart monster_extra.fbs
61
62# Generate optional scalar code for tests.
63../flatc --java --kotlin --lobster --ts optional_scalars.fbs
64../flatc --csharp --rust --gen-object-api optional_scalars.fbs
65../flatc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS --cpp optional_scalars.fbs
66
67# Generate string/vector default code for tests
68../flatc --rust --gen-object-api more_defaults.fbs
69
70# Generate the schema evolution tests
71../flatc --cpp --scoped-enums $TEST_CPP_FLAGS -o evolution_test ./evolution_test/evolution_v*.fbs
72
73working_dir=`pwd`
74cd FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests
75$working_dir/../flatc --swift --grpc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I ${working_dir}/include_test ${working_dir}/monster_test.fbs
76$working_dir/../flatc --swift $TEST_BASE_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS ${working_dir}/union_vector/union_vector.fbs
77$working_dir/../flatc --swift ${working_dir}/optional_scalars.fbs
78$working_dir/../flatc --swift --gen-object-api ${working_dir}/more_defaults.fbs
79cd $working_dir
80
81# Tests if the --filename-suffix and --filename-ext works and produces the same
82# outputs.
83../flatc --cpp --filename-suffix _suffix --filename-ext hpp $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS -I include_test monster_test.fbs
84if [ -f "monster_test_suffix.hpp" ]; then
85  if ! cmp -s "monster_test_suffix.hpp" "monster_test_generated.h"; then
86    echo "[Error] Filename suffix option did not produce identical results"
87  fi
88  rm "monster_test_suffix.hpp"
89else
90  echo "[Error] Filename suffix option did not produce a file"
91fi
92
93# Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914)  or higher.
94TEST_CPP17_FLAGS="--cpp --cpp-std c++17 --cpp-static-reflection -o ./cpp17/generated_cpp17 $TEST_NOINCL_FLAGS"
95../flatc $TEST_CPP17_FLAGS -I include_test monster_test.fbs
96../flatc $TEST_CPP17_FLAGS optional_scalars.fbs
97
98cd ../samples
99../flatc --cpp --rust --lobster $TEST_BASE_FLAGS $TEST_CPP_FLAGS monster.fbs
100../flatc -b --schema --bfbs-comments --bfbs-builtins monster.fbs
101cd ../reflection
102./generate_code.sh --cpp-std c++0x
103