blob: 297d85582c69b6d37bc6f36775586de1e8b0bd60 [file] [log] [blame]
#include <zxtest/zxtest.h>
#include <conformance/cpp/natural_types.h>
#include <cts/tests/pkg/fidl/cpp/test/test_util.h>
#ifdef __Fuchsia__
#include <cts/tests/pkg/fidl/cpp/test/handle_util.h>
#include <zircon/syscalls.h>
#endif
TEST(Conformance, GoldenBoolStruct_V1_Encode) {
conformance::GoldenBoolStruct v1;
v1.v = true;
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenBoolStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenIntStruct_V1_Encode) {
conformance::GoldenIntStruct v1;
v1.v = 1ull;
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenIntStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenUintStruct_V1_Encode) {
conformance::GoldenUintStruct v1;
v1.v = 1ull;
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenUintStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenFloatStruct_V1_Encode) {
conformance::GoldenFloatStruct v1;
v1.v = 0;
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenFloatStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenDoubleStruct_V1_Encode) {
conformance::GoldenDoubleStruct v1;
v1.v = 0;
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenDoubleStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenStringStruct_V1_Encode) {
conformance::GoldenStringStruct v1;
v1.v = std::string("abcd", 4);
const auto expected_bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenStringStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableStringStructNonNull_V1_Encode) {
conformance::GoldenNullableStringStruct v1;
v1.v = ::fidl::StringPtr("abcd", 4);
const auto expected_bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableStringStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableStringStructNull_V1_Encode) {
conformance::GoldenNullableStringStruct v1;
v1.v = ::fidl::StringPtr();
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableStringStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenEnumStruct_V1_Encode) {
conformance::GoldenEnumStruct v1;
v1.v = conformance::GoldenEnum(1ull);
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenEnumStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenBitsStruct_V1_Encode) {
conformance::GoldenBitsStruct v1;
v1.v = conformance::GoldenBits(1ull);
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenBitsStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenTableStruct_V1_Encode) {
conformance::GoldenTableStruct v1;
conformance::GoldenTable v2;
v2.set_v(1ull);
v1.v = std::move(v2);
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenTableStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenUnionStruct_V1_Encode) {
conformance::GoldenUnionStruct v1;
conformance::GoldenUnion v2;
v2.set_v(1ull);
v1.v = std::move(v2);
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenUnionStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableUnionStructNonNull_V1_Encode) {
conformance::GoldenNullableUnionStruct v1;
std::unique_ptr<conformance::GoldenUnion> v2 = std::make_unique<conformance::GoldenUnion>();
v2->set_v(1ull);
v1.v = std::move(v2);
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableUnionStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableUnionStructNull_V1_Encode) {
conformance::GoldenNullableUnionStruct v1;
v1.v = std::unique_ptr<conformance::GoldenUnion>();
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableUnionStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenByteArrayStruct_V1_Encode) {
conformance::GoldenByteArrayStruct v1;
v1.v = std::array<uint8_t, 4>{1ull, 2ull, 3ull, 4ull};
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenByteArrayStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenStructArrayStruct_V1_Encode) {
conformance::GoldenStructArrayStruct v1;
conformance::GoldenIntStruct v2;
v2.v = 1ull;
conformance::GoldenIntStruct v3;
v3.v = 2ull;
v1.v = std::array<conformance::GoldenIntStruct, 2>{std::move(v2), std::move(v3)};
const auto expected_bytes = std::vector<uint8_t>{
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenStructArrayStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenByteVectorStruct_V1_Encode) {
conformance::GoldenByteVectorStruct v1;
v1.v = std::vector<uint8_t>{1ull, 2ull, 3ull, 4ull};
const auto expected_bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenByteVectorStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenStructVectorStruct_V1_Encode) {
conformance::GoldenStructVectorStruct v1;
conformance::GoldenIntStruct v2;
v2.v = 1ull;
conformance::GoldenIntStruct v3;
v3.v = 2ull;
std::vector<conformance::GoldenIntStruct> v4;
v4.push_back(std::move(v2));
v4.push_back(std::move(v3));
v1.v = std::move(v4);
const auto expected_bytes = std::vector<uint8_t>{
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenStructVectorStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableStructNonNull_V1_Encode) {
conformance::GoldenNullableStruct v1;
std::unique_ptr<conformance::GoldenBoolStruct> v2 = std::make_unique<conformance::GoldenBoolStruct>();
v2->v = true;
v1.v = std::move(v2);
const auto expected_bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
TEST(Conformance, GoldenNullableStructNull_V1_Encode) {
conformance::GoldenNullableStruct v1;
v1.v = std::unique_ptr<conformance::GoldenBoolStruct>();
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
#ifdef __Fuchsia__
TEST(Conformance, GoldenHandleBasicRightsStruct_V1_Encode) {
const auto handle_defs = std::vector<zx_handle_t>{
fidl::test::util::CreateChannel(61454), // #0
};
conformance::GoldenHandleBasicRightsStruct v1;
v1.v = zx::event(handle_defs[0]);
const auto expected_bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{
{
.operation = ZX_HANDLE_OP_MOVE,
.handle = handle_defs[0],
.type = 5,
.rights = 49155,
.result = ZX_OK,
},};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenHandleBasicRightsStruct>(
std::move(v1), expected_bytes, expected_handles, true);
EXPECT_TRUE(result);
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
TEST(Conformance, GoldenNullableHandleStructNonNull_V1_Encode) {
const auto handle_defs = std::vector<zx_handle_t>{
fidl::test::util::CreateEvent(2147483648), // #0
};
conformance::GoldenNullableHandleStruct v1;
v1.v = zx::handle(handle_defs[0]);
const auto expected_bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{
{
.operation = ZX_HANDLE_OP_MOVE,
.handle = handle_defs[0],
.type = 0,
.rights = 2147483648,
.result = ZX_OK,
},};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableHandleStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
TEST(Conformance, GoldenNullableHandleStructNull_V1_Encode) {
conformance::GoldenNullableHandleStruct v1;
v1.v = zx::handle();
const auto expected_bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const auto expected_handles = std::vector<zx_handle_disposition_t>{};
const auto result =
fidl::test::util::ValueToBytes<conformance::GoldenNullableHandleStruct>(
std::move(v1), expected_bytes, expected_handles, false);
EXPECT_TRUE(result);
}
#endif // __Fuchsia__
TEST(Conformance, GoldenBoolStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenBoolStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, bool(true));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenIntStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenIntStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, int16_t(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenUintStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenUintStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, uint16_t(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenFloatStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenFloatStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, float(0));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenDoubleStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenDoubleStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, double(0));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenStringStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenStringStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_STR_EQ(f1.v, "abcd");
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableStringStructNonNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableStringStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_STR_EQ((*f1.v), "abcd");
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableStringStructNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableStringStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_NULL(f1.v);
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenEnumStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenEnumStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, conformance::GoldenEnum(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenBitsStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenBitsStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_EQ(f1.v, static_cast<conformance::GoldenBits>(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenTableStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenTableStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_TRUE(f2.has_v());
ASSERT_EQ(f2.v(), int16_t(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenUnionStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenUnionStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2.Which(), conformance::GoldenUnion::Tag::kV);
ASSERT_EQ(f2.v(), int16_t(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableUnionStructNonNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableUnionStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2->Which(), conformance::GoldenUnion::Tag::kV);
ASSERT_EQ(f2->v(), int16_t(1ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableUnionStructNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableUnionStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_NULL(f1.v);
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenByteArrayStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenByteArrayStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2[0], uint8_t(1ull));
ASSERT_EQ(f2[1], uint8_t(2ull));
ASSERT_EQ(f2[2], uint8_t(3ull));
ASSERT_EQ(f2[3], uint8_t(4ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenStructArrayStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenStructArrayStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
[[maybe_unused]] auto& f3 = f2[0];
ASSERT_EQ(f3.v, int16_t(1ull));
[[maybe_unused]] auto& f4 = f2[1];
ASSERT_EQ(f4.v, int16_t(2ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenByteVectorStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenByteVectorStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2.size(), 4);
ASSERT_EQ(f2[0], uint8_t(1ull));
ASSERT_EQ(f2[1], uint8_t(2ull));
ASSERT_EQ(f2[2], uint8_t(3ull));
ASSERT_EQ(f2[3], uint8_t(4ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenStructVectorStruct_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenStructVectorStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2.size(), 2);
[[maybe_unused]] auto& f3 = f2[0];
ASSERT_EQ(f3.v, int16_t(1ull));
[[maybe_unused]] auto& f4 = f2[1];
ASSERT_EQ(f4.v, int16_t(2ull));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableStructNonNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
ASSERT_EQ(f2->v, bool(true));
fidl::test::util::ForgetHandles(std::move(value));
}
TEST(Conformance, GoldenNullableStructNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_NULL(f1.v);
fidl::test::util::ForgetHandles(std::move(value));
}
#ifdef __Fuchsia__
TEST(Conformance, GoldenHandleBasicRightsStruct_V1_Decode) {
const auto handle_defs = std::vector<zx_handle_info_t>{
// #0
zx_handle_info_t{
.handle = fidl::test::util::CreateEvent(53251),
.type = ZX_OBJ_TYPE_EVENT,
.rights = 53251,
.unused = 0u,
},
};
std::vector<zx_koid_t> handle_koids;
for (zx_handle_info_t def : handle_defs) {
zx_info_handle_basic_t info;
ASSERT_OK(zx_object_get_info(def.handle, ZX_INFO_HANDLE_BASIC, &info, sizeof(info), nullptr, nullptr));
handle_koids.push_back(info.koid);
}
auto bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{
handle_defs[0],};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenHandleBasicRightsStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
zx_info_handle_basic_t f3_info;
ASSERT_OK(zx_object_get_info(f2.get(), ZX_INFO_HANDLE_BASIC, &f3_info, sizeof(f3_info), nullptr, nullptr));
ASSERT_EQ(f3_info.koid, handle_koids[0]);
ASSERT_TRUE(f3_info.type == 0 || 0 == ZX_OBJ_TYPE_NONE);
ASSERT_TRUE(f3_info.rights == 49155 || 49155 == ZX_RIGHT_SAME_RIGHTS);
fidl::test::util::ForgetHandles(std::move(value));
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
TEST(Conformance, GoldenNullableHandleStructNonNull_V1_Decode) {
const auto handle_defs = std::vector<zx_handle_info_t>{
// #0
zx_handle_info_t{
.handle = fidl::test::util::CreateEvent(2147483648),
.type = ZX_OBJ_TYPE_EVENT,
.rights = 2147483648,
.unused = 0u,
},
};
std::vector<zx_koid_t> handle_koids;
for (zx_handle_info_t def : handle_defs) {
zx_info_handle_basic_t info;
ASSERT_OK(zx_object_get_info(def.handle, ZX_INFO_HANDLE_BASIC, &info, sizeof(info), nullptr, nullptr));
handle_koids.push_back(info.koid);
}
auto bytes = std::vector<uint8_t>{
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{
handle_defs[0],};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableHandleStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
[[maybe_unused]] auto& f2 = f1.v;
zx_info_handle_basic_t f3_info;
ASSERT_OK(zx_object_get_info(f2.get(), ZX_INFO_HANDLE_BASIC, &f3_info, sizeof(f3_info), nullptr, nullptr));
ASSERT_EQ(f3_info.koid, handle_koids[0]);
ASSERT_TRUE(f3_info.type == 0 || 0 == ZX_OBJ_TYPE_NONE);
ASSERT_TRUE(f3_info.rights == 2147483648 || 2147483648 == ZX_RIGHT_SAME_RIGHTS);
fidl::test::util::ForgetHandles(std::move(value));
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
TEST(Conformance, GoldenNullableHandleStructNull_V1_Decode) {
auto bytes = std::vector<uint8_t>{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
auto value =
fidl::test::util::DecodedBytes<conformance::GoldenNullableHandleStruct>(std::move(bytes), std::move(handles));
[[maybe_unused]] auto& f1 = value;
ASSERT_FALSE(f1.v.is_valid());
fidl::test::util::ForgetHandles(std::move(value));
}
#endif // __Fuchsia__
TEST(Conformance, GoldenStringWithMaxSize2_V1_Encode_Failure) {
conformance::GoldenStringWithMaxSize2 v1;
v1.s = std::string("abc", 3);
fidl::test::util::CheckEncodeFailure<conformance::GoldenStringWithMaxSize2>(
std::move(v1), ZX_ERR_INVALID_ARGS);
}
TEST(Conformance, GoldenStringStructNullBody_V1_Decode_Failure) {
auto bytes = std::vector<uint8_t>{
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
auto handles = std::vector<zx_handle_info_t>{};
fidl::test::util::CheckDecodeFailure<conformance::GoldenStringStruct>(std::move(bytes), std::move(handles), ZX_ERR_INVALID_ARGS);
}