chromium/mojo/public/interfaces/bindings/tests/nullable_value_types.mojom

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

[JavaPackage="org.chromium.mojo.bindings.test.mojom.nullable_value_types"]
module mojo.test.nullable_value_types.mojom;

// Enumerator values intentionally selected to avoid overlap.
enum RegularEnum {
  kThisValue = 1,
  kThatValue = 2,
};

[Extensible]
enum ExtensibleEnum {
  [Default] kUnknown = 0,
};

enum TypemappedEnum {
  kThisOtherValue = 4,
  kThatOtherValue = 8,
};

struct StructWithEnums {
  RegularEnum? enum_value;
  TypemappedEnum? mapped_enum_value;
};

struct CompatibleStructWithEnums {
  bool has_enum_value;
  RegularEnum enum_value;
  bool has_mapped_enum_value;
  TypemappedEnum mapped_enum_value;
};

struct StructWithNumerics {
  bool? bool_value;
  uint8? u8_value;

  uint16? u16_value;
  uint32? u32_value;
  uint64? u64_value;

  int8? i8_value;
  int16? i16_value;
  int32? i32_value;
  int64? i64_value;

  float? float_value;
  double? double_value;
};

struct CompatibleStructWithNumerics {
  bool has_bool_value;
  bool bool_value;

  bool has_u8_value;
  uint8 u8_value;
  bool has_u16_value;
  uint16 u16_value;
  bool has_u32_value;
  uint32 u32_value;
  bool has_u64_value;
  uint64 u64_value;

  bool has_i8_value;
  int8 i8_value;
  bool has_i16_value;
  int16 i16_value;
  bool has_i32_value;
  int32 i32_value;
  bool has_i64_value;
  int64 i64_value;

  bool has_float_value;
  float float_value;
  bool has_double_value;
  double double_value;
};

// Structs for versioning tests. Usually this would be the same struct...
struct VersionedStructV1 {
};

struct VersionedStructV2 {
  [MinVersion=1] bool? bool_value;

  [MinVersion=1] uint8? u8_value;
  [MinVersion=1] uint16? u16_value;
  [MinVersion=1] uint32? u32_value;
  [MinVersion=1] uint64? u64_value;

  [MinVersion=1] int8? i8_value;
  [MinVersion=1] int16? i16_value;
  [MinVersion=1] int32? i32_value;
  [MinVersion=1] int64? i64_value;

  [MinVersion=1] float? float_value;
  [MinVersion=1] double? double_value;

  [MinVersion=1] RegularEnum? enum_value;
  [MinVersion=1] TypemappedEnum? mapped_enum_value;
};

// InterfaceV1 and InterfaceV2 should be wire compatible: V1 uses `bool` +
// `type` for each parameter, while V2 uses `type?`.
interface InterfaceV1 {
  MethodWithEnums@1(bool has_enum_value, RegularEnum enum_value,
                    bool has_mapped_enum_value,
                    TypemappedEnum mapped_enum_value)
      => (bool has_enum_value, RegularEnum enum_value,
          bool has_mapped_enum_value, TypemappedEnum mapped_enum_value);

  MethodWithStructWithEnums@2(CompatibleStructWithEnums in)
      => (CompatibleStructWithEnums out);

  MethodWithNumerics@3(
      bool has_bool_value,
      bool bool_value,
      bool has_u8_value,
      uint8 u8_value,
      bool has_u16_value,
      uint16 u16_value,
      bool has_u32_value,
      uint32 u32_value,
      bool has_u64_value,
      uint64 u64_value,
      bool has_i8_value,
      int8 i8_value,
      bool has_i16_value,
      int16 i16_value,
      bool has_i32_value,
      int32 i32_value,
      bool has_i64_value,
      int64 i64_value,
      bool has_float_value,
      float float_value,
      bool has_double_value,
      double double_value
  ) => (
      bool has_bool_value,
      bool bool_value,
      bool has_u8_value,
      uint8 u8_value,
      bool has_u16_value,
      uint16 u16_value,
      bool has_u32_value,
      uint32 u32_value,
      bool has_u64_value,
      uint64 u64_value,
      bool has_i8_value,
      int8 i8_value,
      bool has_i16_value,
      int16 i16_value,
      bool has_i32_value,
      int32 i32_value,
      bool has_i64_value,
      int64 i64_value,
      bool has_float_value,
      float float_value,
      bool has_double_value,
      double double_value
  );

  MethodWithStructWithNumerics@4(CompatibleStructWithNumerics in)
      => (CompatibleStructWithNumerics out);

  MethodWithVersionedArgs@5() => ();

  MethodWithVersionedStruct@6(VersionedStructV1 in) => (VersionedStructV1 out);
};

interface InterfaceV2 {
  MethodWithEnums@1(RegularEnum? enum_value, TypemappedEnum? mapped_enum_value)
      => (RegularEnum? enum_value, TypemappedEnum? mapped_enum_value);

  MethodWithStructWithEnums@2(StructWithEnums in) => (StructWithEnums out);

  MethodWithNumerics@3(
      bool? bool_value,
      uint8? u8_value,
      uint16? u16_value,
      uint32? u32_value,
      uint64? u64_value,
      int8? i8_value,
      int16? i16_value,
      int32? i32_value,
      int64? i64_value,
      float? float_value,
      double? double_value
  ) => (
      bool? bool_value,
      uint8? u8_value,
      uint16? u16_value,
      uint32? u32_value,
      uint64? u64_value,
      int8? i8_value,
      int16? i16_value,
      int32? i32_value,
      int64? i64_value,
      float? float_value,
      double? double_value
  );

  MethodWithStructWithNumerics@4(StructWithNumerics in)
      => (StructWithNumerics out);

  MethodWithVersionedArgs@5(
      [MinVersion=1] bool? bool_value,
      [MinVersion=1] uint8? u8_value,
      [MinVersion=1] uint16? u16_value,
      [MinVersion=1] uint32? u32_value,
      [MinVersion=1] uint64? u64_value,
      [MinVersion=1] int8? i8_value,
      [MinVersion=1] int16? i16_value,
      [MinVersion=1] int32? i32_value,
      [MinVersion=1] int64? i64_value,
      [MinVersion=1] float? float_value,
      [MinVersion=1] double? double_value,
      [MinVersion=1] RegularEnum? enum_value,
      [MinVersion=1] TypemappedEnum? mapped_enum_value
  ) => (
      [MinVersion=1] bool? bool_value,
      [MinVersion=1] uint8? u8_value,
      [MinVersion=1] uint16? u16_value,
      [MinVersion=1] uint32? u32_value,
      [MinVersion=1] uint64? u64_value,
      [MinVersion=1] int8? i8_value,
      [MinVersion=1] int16? i16_value,
      [MinVersion=1] int32? i32_value,
      [MinVersion=1] int64? i64_value,
      [MinVersion=1] float? float_value,
      [MinVersion=1] double? double_value,
      [MinVersion=1] RegularEnum? enum_value,
      [MinVersion=1] TypemappedEnum? mapped_enum_value
  );

  // Test method for versioned struct.
  MethodWithVersionedStruct@6(VersionedStructV2 in) => (VersionedStructV2 out);

  // Test method for containers of nullables.
  MethodWithContainers@7(
        array<bool?> bool_values,
        array<uint8?> u8_values,
        array<uint16?> u16_values,
        array<uint32?> u32_values,
        array<uint64?> u64_values,
        array<int8?> i8_values,
        array<int16?> i16_values,
        array<int32?> i32_values,
        array<int64?> i64_values,
        array<float?> float_values,
        array<double?> double_values,
        array<RegularEnum?> enum_value,
        array<ExtensibleEnum?> extensible_enum_values,
        map<int32, bool?> bool_map,
        map<int32, int32?> int_map
  ) => (
        array<bool?> bool_values,
        array<uint8?> u8_values,
        array<uint16?> u16_values,
        array<uint32?> u32_values,
        array<uint64?> u64_values,
        array<int8?> i8_values,
        array<int16?> i16_values,
        array<int32?> i32_values,
        array<int64?> i64_values,
        array<float?> float_values,
        array<double?> double_values,
        array<RegularEnum?> enum_value,
        array<ExtensibleEnum?> extensible_enum_values,
        map<int32, bool?> bool_map,
        map<int32, int32?> int_map
  );

  // C++ implementation will purposely send an unknown enum to exercise Java
  // unknown enum handling.
  // Result should be an array of a single unknown enum value followed by a null
  // value, i.e.: {[unknown enum value], null}.
  MethodToSendUnknownEnum@8() => (array<ExtensibleEnum?> out);
};