/*
 * 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__)

struct struct_test;

@topic @final
struct struct_test {
  sequence<struct_test> u1;
  @key long u2;
};

#else

#include <string.h>
#include "dds/dds.h"
#include "test_struct_r.h"
#include "common.h"

const dds_topic_descriptor_t *desc = &struct_test_desc;

void init_sample (void *s)
{
  struct_test *t = (struct_test *) s;
  SEQA(t->u1, 1);
  t->u2 = 1;
  SEQA(t->u1._buffer[0].u1, 1);
  t->u1._buffer[0].u2 = 2;
  SEQA(t->u1._buffer[0].u1._buffer[0].u1, 1);
  t->u1._buffer[0].u1._buffer[0].u2 = 3;
  t->u1._buffer[0].u1._buffer[0].u1._buffer[0].u1._length = 0;
  t->u1._buffer[0].u1._buffer[0].u1._buffer[0].u1._buffer = NULL;
  t->u1._buffer[0].u1._buffer[0].u1._buffer[0].u2 = 4;
}

int cmp_sample (const void *sa, const void *sb)
{
  struct_test *a = (struct_test *) sa;
  struct_test *b = (struct_test *) sb;
  CMP(a, b, u2, 1);
  CMP(a, b, u1._buffer[0].u2, 2);
  CMP(a, b, u1._buffer[0].u1._buffer[0].u2, 3);
  CMP(a, b, u1._buffer[0].u1._buffer[0].u1._buffer[0].u2, 4);
  return 0;
}

int cmp_key (const void *sa, const void *sb)
{
  struct_test *a = (struct_test *) sa;
  struct_test *b = (struct_test *) sb;
  CMP(a, b, u2, 1);
  return 0;
}

#endif
