chromium/mojo/public/cpp/bindings/tests/enum_default_unittest.test-mojom

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module mojo.test.enum_default_unittest.mojom;

// Tests for transferring an extensible enum with and without a default
// enumerator value over Mojo IPC.
[Extensible]
enum ExtensibleEnumWithDefault {
  kZeroth = 0,
  [Default] kFirst = 1,
};

[Extensible]
enum ExtensibleEnumWithoutDefault {
  kZeroth = 0,
  kFirst = 1,
};

struct StructWithExtensibleEnumWithDefault {
  ExtensibleEnumWithDefault value;
};

struct StructWithExtensibleEnumWithoutDefault {
  ExtensibleEnumWithoutDefault value;
};

union UnionWithExtensibleEnumWithDefault {
  ExtensibleEnumWithDefault value;
};

union UnionWithExtensibleEnumWithoutDefault {
  ExtensibleEnumWithoutDefault value;
};

interface TestInterface {
  EchoWithDefault(ExtensibleEnumWithDefault in)
      => (ExtensibleEnumWithDefault out);
  EchoWithoutDefault(ExtensibleEnumWithoutDefault in)
      => (ExtensibleEnumWithoutDefault out);

  EchoStructWithDefault(StructWithExtensibleEnumWithDefault in)
      => (StructWithExtensibleEnumWithDefault out);
  EchoStructWithoutDefault(StructWithExtensibleEnumWithoutDefault in)
      => (StructWithExtensibleEnumWithoutDefault out);

  EchoUnionWithDefault(UnionWithExtensibleEnumWithDefault in)
      => (UnionWithExtensibleEnumWithDefault out);
  EchoUnionWithoutDefault(UnionWithExtensibleEnumWithoutDefault in)
      => (UnionWithExtensibleEnumWithoutDefault out);
};

// Tests for initializing enum fields of structs.
[Extensible]
enum EnumWithoutZeroValue {
  [Default] kFirst = 1,
  kSecond = 2,
};

struct StructWithoutInitializer {
  EnumWithoutZeroValue value;
};

struct StructWithInitializer {
  EnumWithoutZeroValue value = kSecond;
};