// Copyright(c) 2021 to 2022 ZettaScale Technology and others
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
// v. 1.0 which is available at
// http://www.eclipse.org/org/documents/edl-v10.php.
//
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

#if defined(__IDLC__)

@default_nested
module test {

  @appendable
  struct c {
    @key long c1;
  };

  @mutable
  struct struct_nested {
    string n1;
    short n2;
    c n3;
  };

  @appendable
  struct b : c {
    long b1;
    struct_nested b2;
  };

  @topic
  @appendable
  struct struct_inherit : b {
    long i1;
    long i2;
  };
}; // module

#else

#include <string.h>
#include "dds/dds.h"
#include "dds/cdr/dds_cdrstream.h"
#include "test_struct_inherit_appendable.h"
#include "common.h"

const dds_topic_descriptor_t *desc = &test_struct_inherit_desc;

void init_sample (void *s)
{
  test_struct_inherit *s1 = (test_struct_inherit *) s;
  s1->parent.b1 = 123;
  STRA (s1->parent.b2.n1, STR128);
  s1->parent.b2.n2 = 456;
  s1->parent.b2.n3.c1 = 789;
  s1->parent.parent.c1 = 321;
  s1->i1 = 654;
  s1->i2 = 987;
}

int cmp_sample (const void *sa, const void *sb)
{
  test_struct_inherit *a = (test_struct_inherit *) sa;
  test_struct_inherit *b = (test_struct_inherit *) sb;

  CMP (a, b, parent.b1, 123);
  CMPSTR (a, b, parent.b2.n1, STR128);
  CMP (a, b, parent.b2.n2, 456);
  CMP (a, b, parent.b2.n3.c1, 789);
  CMP (a, b, parent.parent.c1, 321);
  CMP (a, b, i1, 654);
  CMP (a, b, i2, 987);

  return 0;
}

int cmp_key (const void *sa, const void *sb)
{
  test_struct_inherit *a = (test_struct_inherit *) sa;
  test_struct_inherit *b = (test_struct_inherit *) sb;

  CMP (a, b, parent.parent.c1, 321);

  return 0;
}

#endif
