blob: 0c257a763d35a6859c40c48361706f3d6ab6c9cc [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fstream>
#include <fidl/flat_ast.h>
#include <fidl/lexer.h>
#include <fidl/parser.h>
#include <fidl/source_file.h>
#include <unittest/unittest.h>
#include "examples.h"
#include "test_library.h"
namespace {
// We repeat each test in a loop in order to catch situations where memory layout
// determines what JSON is produced (this is often manifested due to using a std::map<Foo*,...>
// in compiler source code).
static const int kRepeatTestCount = 100;
static inline void trim(std::string& s) {
s.erase(s.begin(),
std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch) && ch != '\n'; }));
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch) && ch != '\n'; })
.base(),
s.end());
}
bool checkJSONGenerator(TestLibrary library, std::string expected_json) {
ASSERT_TRUE(library.Compile());
// actual
auto actual = library.GenerateJSON();
trim(actual);
// expected
trim(expected_json);
if (actual.compare(expected_json) == 0) {
return true;
}
// On error, we output both the actual and expected to allow simple
// diffing to debug the test.
std::ofstream output_actual("json_generator_tests_actual.txt");
output_actual << actual;
output_actual.close();
std::ofstream output_expected("json_generator_tests_expected.txt");
output_expected << expected_json;
output_expected.close();
return false;
}
bool checkJSONGenerator(std::string raw_source_code, std::string expected_json) {
return checkJSONGenerator(TestLibrary("json.fidl", raw_source_code), std::move(expected_json));
}
bool json_generator_test_struct() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
struct Simple {
uint8 f1;
bool f2;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [],
"service_declarations": [],
"struct_declarations": [
{
"name": "fidl.test.json/Simple",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 8
},
"anonymous": false,
"members": [
{
"type": {
"kind": "primitive",
"subtype": "uint8"
},
"name": "f1",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 11
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 0,
"max_handles": 0,
"field_shape_old": {
"offset": 0,
"padding": 0
},
"field_shape_v1": {
"offset": 0,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 0,
"padding": 0
}
},
{
"type": {
"kind": "primitive",
"subtype": "bool"
},
"name": "f2",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 10
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 1,
"max_handles": 0,
"field_shape_old": {
"offset": 1,
"padding": 0
},
"field_shape_v1": {
"offset": 1,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 1,
"padding": 0
}
}
],
"size": 2,
"max_out_of_line": 0,
"alignment": 1,
"max_handles": 0,
"has_padding": false,
"type_shape_old": {
"inline_size": 2,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 2,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 2,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/Simple"
],
"declarations": {
"fidl.test.json/Simple": "struct"
}
})JSON"));
}
END_TEST;
}
bool json_generator_test_empty_struct() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
struct Empty {
};
protocol EmptyProtocol {
Send(Empty e);
-> Receive (Empty e);
SendAndReceive(Empty e) -> (Empty e);
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [
{
"name": "fidl.test.json/EmptyProtocol",
"location": {
"filename": "json.fidl",
"line": 7,
"column": 10
},
"methods": [
{
"ordinal": 1227695175833223168,
"generated_ordinal": 550167292114688515,
"name": "Send",
"location": {
"filename": "json.fidl",
"line": 8,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Empty",
"nullable": false
},
"name": "e",
"location": {
"filename": "json.fidl",
"line": 8,
"column": 14
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 7
},
"field_shape_v1": {
"offset": 16,
"padding": 7
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 7
}
}
],
"maybe_request_size": 24,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": false,
"is_composed": false
},
{
"ordinal": 1669757317588975616,
"generated_ordinal": 7186107129703123093,
"name": "Receive",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 6
},
"has_request": false,
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Empty",
"nullable": false
},
"name": "e",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 21
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 7
},
"field_shape_v1": {
"offset": 16,
"padding": 7
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 7
}
}
],
"maybe_response_size": 24,
"maybe_response_alignment": 8,
"maybe_response_has_padding": true,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"is_composed": false
},
{
"ordinal": 8898209322824105984,
"generated_ordinal": 2187042876758414869,
"name": "SendAndReceive",
"location": {
"filename": "json.fidl",
"line": 10,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Empty",
"nullable": false
},
"name": "e",
"location": {
"filename": "json.fidl",
"line": 10,
"column": 24
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 7
},
"field_shape_v1": {
"offset": 16,
"padding": 7
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 7
}
}
],
"maybe_request_size": 24,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Empty",
"nullable": false
},
"name": "e",
"location": {
"filename": "json.fidl",
"line": 10,
"column": 37
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 7
},
"field_shape_v1": {
"offset": 16,
"padding": 7
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 7
}
}
],
"maybe_response_size": 24,
"maybe_response_alignment": 8,
"maybe_response_has_padding": true,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"is_composed": false
}
]
}
],
"service_declarations": [],
"struct_declarations": [
{
"name": "fidl.test.json/Empty",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 8
},
"anonymous": false,
"members": [],
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"max_handles": 0,
"has_padding": false,
"type_shape_old": {
"inline_size": 1,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 1,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 1,
"alignment": 1,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/Empty",
"fidl.test.json/EmptyProtocol"
],
"declarations": {
"fidl.test.json/EmptyProtocol": "interface",
"fidl.test.json/Empty": "struct"
}
}
)JSON"));
}
END_TEST;
}
// This targets a specific issue with identifier naming where the identifier
// library is incorrectly the current library name rather than the name of the
// identifiers own library.
bool json_generator_test_struct_default_value_enum_library_reference() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
SharedAmongstLibraries shared;
TestLibrary dependency("dependent.fidl", R"FIDL(
library dependent;
enum MyEnum : int32 {
A = 1;
};
)FIDL",
&shared);
ASSERT_TRUE(dependency.Compile());
TestLibrary library("example.fidl", R"FIDL(
library example;
using dependent;
struct Foo {
dependent.MyEnum field = dependent.MyEnum.A;
};
)FIDL",
&shared);
ASSERT_TRUE(library.AddDependentLibrary(std::move(dependency)));
ASSERT_TRUE(checkJSONGenerator(std::move(library),
R"JSON(
{
"version": "0.0.1",
"name": "example",
"library_dependencies": [
{
"name": "dependent",
"declarations": {
"dependent/MyEnum": "enum"
}
}
],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [],
"service_declarations": [],
"struct_declarations": [
{
"name": "example/Foo",
"location": {
"filename": "example.fidl",
"line": 6,
"column": 10
},
"anonymous": false,
"members": [
{
"type": {
"kind": "identifier",
"identifier": "dependent/MyEnum",
"nullable": false
},
"name": "field",
"location": {
"filename": "example.fidl",
"line": 7,
"column": 24
},
"maybe_default_value": {
"kind": "identifier",
"identifier": "dependent/MyEnum.A"
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0,
"max_handles": 0,
"field_shape_old": {
"offset": 0,
"padding": 0
},
"field_shape_v1": {
"offset": 0,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 0,
"padding": 0
}
}
],
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"max_handles": 0,
"has_padding": false,
"type_shape_old": {
"inline_size": 4,
"alignment": 4,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 4,
"alignment": 4,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 4,
"alignment": 4,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"example/Foo"
],
"declarations": {
"example/Foo": "struct"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_table() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
table Simple {
1: uint8 f1;
2: bool f2;
3: reserved;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [],
"service_declarations": [],
"struct_declarations": [],
"table_declarations": [
{
"name": "fidl.test.json/Simple",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 7
},
"members": [
{
"ordinal": 1,
"reserved": false,
"type": {
"kind": "primitive",
"subtype": "uint8"
},
"name": "f1",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 14
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"max_handles": 0
},
{
"ordinal": 2,
"reserved": false,
"type": {
"kind": "primitive",
"subtype": "bool"
},
"name": "f2",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 13
},
"size": 1,
"max_out_of_line": 0,
"alignment": 1,
"max_handles": 0
},
{
"ordinal": 3,
"reserved": true,
"location": {
"filename": "json.fidl",
"line": 7,
"column": 5
}
}
],
"size": 16,
"max_out_of_line": 48,
"alignment": 8,
"max_handles": 0,
"strict": false,
"type_shape_old": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 48,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 48,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 48,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
}
}
],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/Simple"
],
"declarations": {
"fidl.test.json/Simple": "table"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_union() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
struct Pizza {
vector<string:16> toppings;
};
struct Pasta {
string:16 sauce;
};
union PizzaOrPasta {
1: Pizza pizza;
2: Pasta pasta;
};
union ExplicitPizzaOrPasta {
3: reserved;
2: reserved;
1: Pizza pizza;
4: Pasta pasta;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [],
"service_declarations": [],
"struct_declarations": [
{
"name": "fidl.test.json/Pizza",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 8
},
"anonymous": false,
"members": [
{
"type": {
"kind": "vector",
"element_type": {
"kind": "string",
"maybe_element_count": 16,
"nullable": false
},
"nullable": false
},
"name": "toppings",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 23
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0,
"max_handles": 0,
"field_shape_old": {
"offset": 0,
"padding": 0
},
"field_shape_v1": {
"offset": 0,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 0,
"padding": 0
}
}
],
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"has_padding": true,
"type_shape_old": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 16,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
}
},
{
"name": "fidl.test.json/Pasta",
"location": {
"filename": "json.fidl",
"line": 8,
"column": 8
},
"anonymous": false,
"members": [
{
"type": {
"kind": "string",
"maybe_element_count": 16,
"nullable": false
},
"name": "sauce",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 15
},
"size": 16,
"max_out_of_line": 16,
"alignment": 8,
"offset": 0,
"max_handles": 0,
"field_shape_old": {
"offset": 0,
"padding": 0
},
"field_shape_v1": {
"offset": 0,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 0,
"padding": 0
}
}
],
"size": 16,
"max_out_of_line": 16,
"alignment": 8,
"max_handles": 0,
"has_padding": true,
"type_shape_old": {
"inline_size": 16,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 16,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 16,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 16,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 16,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 16,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"table_declarations": [],
"union_declarations": [
{
"name": "fidl.test.json/PizzaOrPasta",
"location": {
"filename": "json.fidl",
"line": 12,
"column": 7
},
"members": [
{
"xunion_ordinal": 1,
"reserved": false,
"name": "pizza",
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Pizza",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 13,
"column": 14
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 8
},
{
"xunion_ordinal": 2,
"reserved": false,
"name": "pasta",
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Pasta",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 14,
"column": 14
},
"size": 16,
"max_out_of_line": 16,
"alignment": 8,
"offset": 8
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 3,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 3,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
}
},
{
"name": "fidl.test.json/ExplicitPizzaOrPasta",
"location": {
"filename": "json.fidl",
"line": 17,
"column": 7
},
"members": [
{
"xunion_ordinal": 1,
"reserved": false,
"name": "pizza",
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Pizza",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 20,
"column": 12
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 8
},
{
"xunion_ordinal": 2,
"reserved": true,
"location": {
"filename": "json.fidl",
"line": 19,
"column": 3
}
},
{
"xunion_ordinal": 3,
"reserved": true,
"location": {
"filename": "json.fidl",
"line": 18,
"column": 3
}
},
{
"xunion_ordinal": 4,
"reserved": false,
"name": "pasta",
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Pasta",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 21,
"column": 12
},
"size": 16,
"max_out_of_line": 16,
"alignment": 8,
"offset": 8
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 3,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 3,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
}
}
],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/Pizza",
"fidl.test.json/Pasta",
"fidl.test.json/PizzaOrPasta",
"fidl.test.json/ExplicitPizzaOrPasta"
],
"declarations": {
"fidl.test.json/Pizza": "struct",
"fidl.test.json/Pasta": "struct",
"fidl.test.json/PizzaOrPasta": "union",
"fidl.test.json/ExplicitPizzaOrPasta": "union"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_xunion() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
xunion FlexibleFoo {
string s;
int32 i;
};
strict xunion StrictFoo {
string s;
int32 i;
};
xunion ExplicitFoo {
2: string s;
1: int32 i;
3: reserved;
};
strict xunion ExplicitStrictFoo {
1: reserved;
3: string s;
2: int32 i;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [],
"service_declarations": [],
"struct_declarations": [],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [
{
"name": "fidl.test.json/FlexibleFoo",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 8
},
"members": [
{
"ordinal": 1056421836,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 5,
"column": 10
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 1911600824,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 6,
"column": 9
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": false,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
}
},
{
"name": "fidl.test.json/StrictFoo",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 15
},
"members": [
{
"ordinal": 215696753,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 10,
"column": 10
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 2063855467,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 11,
"column": 9
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": true,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
}
},
{
"name": "fidl.test.json/ExplicitFoo",
"location": {
"filename": "json.fidl",
"line": 14,
"column": 8
},
"members": [
{
"ordinal": 2,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 15,
"column": 13
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 1,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 16,
"column": 12
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
},
{
"ordinal": 3,
"reserved": true,
"location": {
"filename": "json.fidl",
"line": 17,
"column": 3
}
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": false,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
}
},
{
"name": "fidl.test.json/ExplicitStrictFoo",
"location": {
"filename": "json.fidl",
"line": 20,
"column": 15
},
"members": [
{
"ordinal": 1,
"reserved": true,
"location": {
"filename": "json.fidl",
"line": 21,
"column": 3
}
},
{
"ordinal": 3,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 22,
"column": 13
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 2,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 23,
"column": 12
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": true,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/StrictFoo",
"fidl.test.json/FlexibleFoo",
"fidl.test.json/ExplicitStrictFoo",
"fidl.test.json/ExplicitFoo"
],
"declarations": {
"fidl.test.json/FlexibleFoo": "xunion",
"fidl.test.json/StrictFoo": "xunion",
"fidl.test.json/ExplicitFoo": "xunion",
"fidl.test.json/ExplicitStrictFoo": "xunion"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_request_flexible_envelope() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
xunion FlexibleFoo {
string s;
int32 i;
};
strict xunion StrictFoo {
string s;
int32 i;
};
protocol Protocol {
RequestStrictResponseFlexible(StrictFoo s) -> (FlexibleFoo f);
RequestFlexibleResponseStrict(FlexibleFoo s) -> (StrictFoo f);
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [
{
"name": "fidl.test.json/Protocol",
"location": {
"filename": "json.fidl",
"line": 14,
"column": 10
},
"methods": [
{
"ordinal": 1244088344447549440,
"generated_ordinal": 8264567585134801538,
"name": "RequestStrictResponseFlexible",
"location": {
"filename": "json.fidl",
"line": 15,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/StrictFoo",
"nullable": false
},
"name": "s",
"location": {
"filename": "json.fidl",
"line": 15,
"column": 43
},
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_request_size": 40,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/FlexibleFoo",
"nullable": false
},
"name": "f",
"location": {
"filename": "json.fidl",
"line": 15,
"column": 62
},
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_response_size": 40,
"maybe_response_alignment": 8,
"maybe_response_has_padding": true,
"experimental_maybe_response_has_flexible_envelope": true,
"maybe_response_type_shape_old": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"is_composed": false
},
{
"ordinal": 3546214166840737792,
"generated_ordinal": 4801763909694511442,
"name": "RequestFlexibleResponseStrict",
"location": {
"filename": "json.fidl",
"line": 16,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/FlexibleFoo",
"nullable": false
},
"name": "s",
"location": {
"filename": "json.fidl",
"line": 16,
"column": 45
},
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_request_size": 40,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": true,
"maybe_request_type_shape_old": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/StrictFoo",
"nullable": false
},
"name": "f",
"location": {
"filename": "json.fidl",
"line": 16,
"column": 62
},
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_response_size": 40,
"maybe_response_alignment": 8,
"maybe_response_has_padding": true,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 40,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"is_composed": false
}
]
}
],
"service_declarations": [],
"struct_declarations": [],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [
{
"name": "fidl.test.json/FlexibleFoo",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 8
},
"members": [
{
"ordinal": 1056421836,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 5,
"column": 10
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 1911600824,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 6,
"column": 9
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": false,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": true,
"contains_union": false
}
},
{
"name": "fidl.test.json/StrictFoo",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 15
},
"members": [
{
"ordinal": 215696753,
"reserved": false,
"name": "s",
"type": {
"kind": "string",
"nullable": false
},
"location": {
"filename": "json.fidl",
"line": 10,
"column": 10
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 0
},
{
"ordinal": 2063855467,
"reserved": false,
"name": "i",
"type": {
"kind": "primitive",
"subtype": "int32"
},
"location": {
"filename": "json.fidl",
"line": 11,
"column": 9
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 0
}
],
"size": 24,
"max_out_of_line": 4294967295,
"alignment": 8,
"max_handles": 0,
"strict": true,
"type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 2,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
}
}
],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/StrictFoo",
"fidl.test.json/FlexibleFoo",
"fidl.test.json/Protocol"
],
"declarations": {
"fidl.test.json/Protocol": "interface",
"fidl.test.json/FlexibleFoo": "xunion",
"fidl.test.json/StrictFoo": "xunion"
}
}
)JSON"));
}
END_TEST;
}
// This test ensures that inherited methods have the same ordinal / signature /
// etc as the method from which they are inheriting.
bool json_generator_test_inheritance() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
[FragileBase]
protocol super {
foo(string s) -> (int64 y);
};
protocol sub {
compose super;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [
{
"name": "fidl.test.json/super",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 10
},
"maybe_attributes": [
{
"name": "FragileBase",
"value": ""
}
],
"methods": [
{
"ordinal": 3393112382468259840,
"generated_ordinal": 5722958650322615442,
"name": "foo",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 4
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "string",
"nullable": false
},
"name": "s",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 15
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_request_size": 32,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "primitive",
"subtype": "int64"
},
"name": "y",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 28
},
"size": 8,
"max_out_of_line": 0,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_response_size": 24,
"maybe_response_alignment": 8,
"maybe_response_has_padding": false,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"is_composed": false
}
]
},
{
"name": "fidl.test.json/sub",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 10
},
"methods": [
{
"ordinal": 3393112382468259840,
"generated_ordinal": 5722958650322615442,
"name": "foo",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 4
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "string",
"nullable": false
},
"name": "s",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 15
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_request_size": 32,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "primitive",
"subtype": "int64"
},
"name": "y",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 28
},
"size": 8,
"max_out_of_line": 0,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_response_size": 24,
"maybe_response_alignment": 8,
"maybe_response_has_padding": false,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": false,
"has_flexible_envelope": false,
"contains_union": false
},
"is_composed": true
}
]
}
],
"service_declarations": [],
"struct_declarations": [],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/super",
"fidl.test.json/sub"
],
"declarations": {
"fidl.test.json/super": "interface",
"fidl.test.json/sub": "interface"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_inheritance_with_recursive_decl() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
[FragileBase]
protocol Parent {
First(request<Parent> request);
};
protocol Child {
compose Parent;
Second(request<Parent> request);
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [
{
"name": "fidl.test.json/Parent",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 10
},
"maybe_attributes": [
{
"name": "FragileBase",
"value": ""
}
],
"methods": [
{
"ordinal": 7397547062406938624,
"generated_ordinal": 2566928499103139852,
"name": "First",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "request",
"subtype": "fidl.test.json/Parent",
"nullable": false
},
"name": "request",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 25
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 16,
"max_handles": 1,
"field_shape_old": {
"offset": 16,
"padding": 4
},
"field_shape_v1": {
"offset": 16,
"padding": 4
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 4
}
}
],
"maybe_request_size": 24,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": false,
"is_composed": false
}
]
},
{
"name": "fidl.test.json/Child",
"location": {
"filename": "json.fidl",
"line": 9,
"column": 10
},
"methods": [
{
"ordinal": 7397547062406938624,
"generated_ordinal": 2566928499103139852,
"name": "First",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "request",
"subtype": "fidl.test.json/Parent",
"nullable": false
},
"name": "request",
"location": {
"filename": "json.fidl",
"line": 6,
"column": 25
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 16,
"max_handles": 1,
"field_shape_old": {
"offset": 16,
"padding": 4
},
"field_shape_v1": {
"offset": 16,
"padding": 4
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 4
}
}
],
"maybe_request_size": 24,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": false,
"is_composed": true
},
{
"ordinal": 82204669023092736,
"generated_ordinal": 2628306304378964143,
"name": "Second",
"location": {
"filename": "json.fidl",
"line": 11,
"column": 3
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "request",
"subtype": "fidl.test.json/Parent",
"nullable": false
},
"name": "request",
"location": {
"filename": "json.fidl",
"line": 11,
"column": 26
},
"size": 4,
"max_out_of_line": 0,
"alignment": 4,
"offset": 16,
"max_handles": 1,
"field_shape_old": {
"offset": 16,
"padding": 4
},
"field_shape_v1": {
"offset": 16,
"padding": 4
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 4
}
}
],
"maybe_request_size": 24,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 24,
"alignment": 8,
"depth": 0,
"max_handles": 1,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": false,
"is_composed": false
}
]
}
],
"service_declarations": [],
"struct_declarations": [],
"table_declarations": [],
"union_declarations": [],
"xunion_declarations": [],
"type_alias_declarations": [],
"declaration_order": [
"fidl.test.json/Parent",
"fidl.test.json/Child"
],
"declarations": {
"fidl.test.json/Parent": "interface",
"fidl.test.json/Child": "interface"
}
}
)JSON"));
}
END_TEST;
}
bool json_generator_test_error() {
BEGIN_TEST;
for (int i = 0; i < kRepeatTestCount; i++) {
ASSERT_TRUE(checkJSONGenerator(R"FIDL(
library fidl.test.json;
protocol Example {
foo(string s) -> (int64 y) error uint32;
};
)FIDL",
R"JSON(
{
"version": "0.0.1",
"name": "fidl.test.json",
"library_dependencies": [],
"bits_declarations": [],
"const_declarations": [],
"enum_declarations": [],
"interface_declarations": [
{
"name": "fidl.test.json/Example",
"location": {
"filename": "json.fidl",
"line": 4,
"column": 10
},
"methods": [
{
"ordinal": 5882788358547046400,
"generated_ordinal": 841977834905137819,
"name": "foo",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 4
},
"has_request": true,
"maybe_request": [
{
"type": {
"kind": "string",
"nullable": false
},
"name": "s",
"location": {
"filename": "json.fidl",
"line": 5,
"column": 15
},
"size": 16,
"max_out_of_line": 4294967295,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_request_size": 32,
"maybe_request_alignment": 8,
"maybe_request_has_padding": true,
"experimental_maybe_request_has_flexible_envelope": false,
"maybe_request_type_shape_old": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"maybe_request_type_shape_v1_no_ee": {
"inline_size": 32,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 4294967295,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": false
},
"has_response": true,
"maybe_response": [
{
"type": {
"kind": "identifier",
"identifier": "fidl.test.json/Example_foo_Result",
"nullable": false
},
"name": "result",
"location": {
"filename": "generated",
"line": 6,
"column": 1
},
"size": 16,
"max_out_of_line": 0,
"alignment": 8,
"offset": 16,
"max_handles": 0,
"field_shape_old": {
"offset": 16,
"padding": 0
},
"field_shape_v1": {
"offset": 16,
"padding": 0
},
"field_shape_v1_no_ee": {
"offset": 16,
"padding": 0
}
}
],
"maybe_response_size": 32,
"maybe_response_alignment": 8,
"maybe_response_has_padding": true,
"experimental_maybe_response_has_flexible_envelope": false,
"maybe_response_type_shape_old": {
"inline_size": 32,
"alignment": 8,
"depth": 0,
"max_handles": 0,
"max_out_of_line": 0,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"maybe_response_type_shape_v1": {
"inline_size": 40,
"alignment": 8,
"depth": 1,
"max_handles": 0,
"max_out_of_line": 8,
"has_padding": true,
"has_flexible_envelope": false,
"contains_union": true
},
"maybe_response_type_shape_v1_no_ee": {
"inline_size": 40,