// 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__)
@bit_bound(7)
enum e { E1, E2, E3 };
@nested @appendable
struct test_nested_app {
@key sequence<string> a1;
uint16 a2;
};
@nested @final
struct test_nested {
uint8 n1;
@key uint16 n2;
@key test_nested_app n3;
};
@topic @final
struct test_struct_keys {
uint16 f1;
@key e f2;
@key sequence<long> f3;
long f4;
@key sequence<test_nested> f5;
};
#else
#include "dds/dds.h"
#include "test_key_seq.h"
#include "common.h"
const dds_topic_descriptor_t *desc = &test_struct_keys_desc;
void init_sample (void *s)
{
test_struct_keys *s1 = (test_struct_keys *) s;
s1->f1 = 5;
s1->f2 = E2;
SEQA (s1->f3, 2);
for (int n = 0; n < 2; n++)
s1->f3._buffer[n] = 3 * n + 1;
s1->f4 = 2;
SEQA (s1->f5, 3);
for (int n = 0; n < 3; n++) {
s1->f5._buffer[n].n1 = 2 * n + 5;
s1->f5._buffer[n].n2 = 3 * n + 9;
SEQA (s1->f5._buffer[n].n3.a1, 2);
for (int m = 0; m < 2; m++)
STRA (s1->f5._buffer[n].n3.a1._buffer[m], STR128);
s1->f5._buffer[n].n3.a2 = 11;
}
}
int cmp_sample (const void *sa, const void *sb)
{
test_struct_keys *a = (test_struct_keys *) sa;
test_struct_keys *b = (test_struct_keys *) sb;
CMP (a, b, f1, 5);
CMP (a, b, f2, E2);
CMP (a, b, f3._length, 2);
for (int n = 0; n < 2; n++)
CMP (a, b, f3._buffer[n], 3 * n + 1);
CMP (a, b, f4, 2);
CMP (a, b, f5._length, 3);
for (int n = 0; n < 3; n++) {
CMP (a, b, f5._buffer[n].n1, 2 * n + 5);
CMP (a, b, f5._buffer[n].n2, 3 * n + 9);
CMP (a, b, f5._buffer[n].n3.a1._length, 2);
for (int m = 0; m < 2; m++)
CMPSTR (a, b, f5._buffer[n].n3.a1._buffer[m], STR128);
CMP (a, b, f5._buffer[n].n3.a2, 11);
}
return 0;
}
int cmp_key (const void *sa, const void *sb)
{
test_struct_keys *a = (test_struct_keys *) sa;
test_struct_keys *b = (test_struct_keys *) sb;
CMP (a, b, f2, E2);
CMP (a, b, f3._length, 2);
for (int n = 0; n < 2; n++)
CMP (a, b, f3._buffer[n], 3 * n + 1);
CMP (a, b, f5._length, 3);
for (int n = 0; n < 3; n++) {
CMP (a, b, f5._buffer[n].n2, 3 * n + 9);
CMP (a, b, f5._buffer[n].n3.a1._length, 2);
for (int m = 0; m < 2; m++)
CMPSTR (a, b, f5._buffer[n].n3.a1._buffer[m], STR128);
}
return 0;
}
#endif