Initial contribution

This commit is contained in:
Michiel Beemster 2018-04-10 17:03:59 +02:00
parent 7b5cc4fa59
commit 11d9ce37aa
580 changed files with 155133 additions and 162 deletions

View file

@ -0,0 +1,33 @@
#
# Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
#
include(Criterion)
idlc_generate(RoundTrip RoundTrip.idl)
idlc_generate(Space Space.idl)
idlc_generate(TypesArrayKey TypesArrayKey.idl)
add_criterion_executable(criterion_ddsc .)
target_include_directories(criterion_ddsc PRIVATE
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src/include/>")
target_link_libraries(criterion_ddsc RoundTrip Space TypesArrayKey ddsc OSAPI)
# Setup environment for config-tests
set(Criterion_ddsc_config_simple_udp_file "${CMAKE_CURRENT_LIST_DIR}/config_simple_udp.xml")
set(Criterion_ddsc_config_simple_udp_uri "file://${Criterion_ddsc_config_simple_udp_file}")
set(Criterion_ddsc_config_simple_udp_max_participants "0")
set_tests_properties(
Criterion_ddsc_config_simple_udp
PROPERTIES
REQUIRED_FILES ${Criterion_ddsc_config_simple_udp_file}
ENVIRONMENT "${CMAKE_PROJECT_NAME_CAPS}_URI=${Criterion_ddsc_config_simple_udp_uri};MAX_PARTICIPANTS=${Criterion_ddsc_config_simple_udp_max_participants}"
)
configure_file("config_env.h.in" "config_env.h")

View file

@ -0,0 +1,26 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
module RoundTripModule
{
struct DataType
{
sequence<octet> payload;
};
#pragma keylist DataType
struct Address
{
string ip;
long port;
};
#pragma keylist Address ip port
};

View file

@ -0,0 +1,40 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
module Space {
struct Type1 {
long long_1; //@Key
long long_2;
long long_3;
};
#pragma keylist Type1 long_1
struct Type2 {
long long_1; //@Key
long long_2;
long long_3;
};
#pragma keylist Type2 long_1
struct simpletypes {
long l;
long long ll;
unsigned short us;
unsigned long ul;
unsigned long long ull;
float f;
double d;
char c;
boolean b;
octet o;
string s; //@Key
};
#pragma keylist simpletypes s
};

View file

@ -0,0 +1,81 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
module TypesArrayKey {
struct long_arraytypekey {
long key[20]; //@Key
};
#pragma keylist long_arraytypekey key
typedef long long longlong;
struct longlong_arraytypekey {
longlong key[20]; //@Key
};
#pragma keylist longlong_arraytypekey key
typedef unsigned short unsignedshort;
struct unsignedshort_arraytypekey {
unsignedshort key[20]; //@Key
};
#pragma keylist unsignedshort_arraytypekey key
typedef unsigned long unsignedlong;
struct unsignedlong_arraytypekey {
unsignedlong key[20]; //@Key
};
#pragma keylist unsignedlong_arraytypekey key
typedef unsigned long long unsignedlonglong;
struct unsignedlonglong_arraytypekey {
unsignedlonglong key[20]; //@Key
};
#pragma keylist unsignedlonglong_arraytypekey key
struct float_arraytypekey {
float key[20]; //@Key
};
#pragma keylist float_arraytypekey key
struct double_arraytypekey {
double key[20]; //@Key
};
#pragma keylist double_arraytypekey key
struct char_arraytypekey {
char key[128]; //@Key
};
#pragma keylist char_arraytypekey key
struct boolean_arraytypekey {
boolean key[128]; //@Key
};
#pragma keylist boolean_arraytypekey key
struct octet_arraytypekey {
octet key[128]; //@Key
};
#pragma keylist octet_arraytypekey key
struct alltypeskey {
long l;
long long ll;
unsigned short us;
unsigned long ul;
unsigned long long ull;
float f;
double d;
char c;
boolean b;
octet o;
string s; //@Key
};
#pragma keylist alltypeskey l ll us ul ull f d c b o s
};

View file

@ -0,0 +1,28 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
Test(ddsc_basic, test)
{
dds_entity_t participant;
dds_return_t status;
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
/* TODO: CHAM-108: Add some simple read/write test(s). */
status = dds_delete(participant);
cr_assert_eq(status, DDS_RETCODE_OK);
}

View file

@ -0,0 +1,842 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "RoundTrip.h"
#include "Space.h"
#include "ddsc/dds.h"
#include "os/os.h"
#include "test-common.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
static dds_entity_t g_participant = 0;
static dds_entity_t g_subscriber = 0;
static dds_entity_t g_publisher = 0;
static dds_entity_t g_topic = 0;
#define MAX_SAMPLES 1
static dds_sample_info_t g_info[MAX_SAMPLES];
static struct DDS_UserDataQosPolicy g_pol_userdata;
static struct DDS_TopicDataQosPolicy g_pol_topicdata;
static struct DDS_GroupDataQosPolicy g_pol_groupdata;
static struct DDS_DurabilityQosPolicy g_pol_durability;
static struct DDS_HistoryQosPolicy g_pol_history;
static struct DDS_ResourceLimitsQosPolicy g_pol_resource_limits;
static struct DDS_PresentationQosPolicy g_pol_presentation;
static struct DDS_LifespanQosPolicy g_pol_lifespan;
static struct DDS_DeadlineQosPolicy g_pol_deadline;
static struct DDS_LatencyBudgetQosPolicy g_pol_latency_budget;
static struct DDS_OwnershipQosPolicy g_pol_ownership;
static struct DDS_OwnershipStrengthQosPolicy g_pol_ownership_strength;
static struct DDS_LivelinessQosPolicy g_pol_liveliness;
static struct DDS_TimeBasedFilterQosPolicy g_pol_time_based_filter;
static struct DDS_PartitionQosPolicy g_pol_partition;
static struct DDS_ReliabilityQosPolicy g_pol_reliability;
static struct DDS_TransportPriorityQosPolicy g_pol_transport_priority;
static struct DDS_DestinationOrderQosPolicy g_pol_destination_order;
static struct DDS_WriterDataLifecycleQosPolicy g_pol_writer_data_lifecycle;
static struct DDS_ReaderDataLifecycleQosPolicy g_pol_reader_data_lifecycle;
static struct DDS_DurabilityServiceQosPolicy g_pol_durability_service;
static const char* c_userdata = "user_key";
static const char* c_topicdata = "topic_key";
static const char* c_groupdata = "group_key";
static const char* c_partitions[] = {"Partition1", "Partition2"};
static dds_qos_t *g_qos = NULL;
static void
qos_init(void)
{
g_qos = dds_qos_create();
cr_assert_not_null(g_qos);
g_pol_userdata.value._buffer = dds_alloc(strlen(c_userdata) + 1);
g_pol_userdata.value._length = (uint32_t)strlen(c_userdata) + 1;
g_pol_userdata.value._release = true;
g_pol_userdata.value._maximum = 0;
g_pol_topicdata.value._buffer = dds_alloc(strlen(c_topicdata) + 1);
g_pol_topicdata.value._length = (uint32_t)strlen(c_topicdata) + 1;
g_pol_topicdata.value._release = true;
g_pol_topicdata.value._maximum = 0;
g_pol_groupdata.value._buffer = dds_alloc(strlen(c_groupdata) + 1);
g_pol_groupdata.value._length = (uint32_t)strlen(c_groupdata) + 1;
g_pol_groupdata.value._release = true;
g_pol_groupdata.value._maximum = 0;
g_pol_history.kind = DDS_KEEP_LAST_HISTORY_QOS;
g_pol_history.depth = 1;
g_pol_resource_limits.max_samples = 1;
g_pol_resource_limits.max_instances = 1;
g_pol_resource_limits.max_samples_per_instance = 1;
g_pol_presentation.access_scope = DDS_INSTANCE_PRESENTATION_QOS;
g_pol_presentation.coherent_access = true;
g_pol_presentation.ordered_access = true;
g_pol_lifespan.duration.sec = 10000;
g_pol_lifespan.duration.nanosec = 11000;
g_pol_deadline.period.sec = 20000;
g_pol_deadline.period.nanosec = 220000;
g_pol_latency_budget.duration.sec = 30000;
g_pol_latency_budget.duration.nanosec = 33000;
g_pol_ownership.kind = DDS_EXCLUSIVE_OWNERSHIP_QOS;
g_pol_ownership_strength.value = 10;
g_pol_liveliness.kind = DDS_AUTOMATIC_LIVELINESS_QOS;
g_pol_liveliness.lease_duration.sec = 40000;
g_pol_liveliness.lease_duration.nanosec = 44000;
g_pol_time_based_filter.minimum_separation.sec = 50000;
g_pol_time_based_filter.minimum_separation.nanosec = 55000;
g_pol_partition.name._buffer = (char**)c_partitions;
g_pol_partition.name._length = 2;
g_pol_reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
g_pol_reliability.max_blocking_time.sec = 60000;
g_pol_reliability.max_blocking_time.nanosec = 66000;
g_pol_transport_priority.value = 42;
g_pol_destination_order.kind = DDS_BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
g_pol_writer_data_lifecycle.autodispose_unregistered_instances = true;
g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay.sec = 70000;
g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay.nanosec= 77000;
g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay.sec = 80000;
g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay.nanosec = 88000;
g_pol_durability_service.history_depth = 1;
g_pol_durability_service.history_kind = DDS_KEEP_LAST_HISTORY_QOS;
g_pol_durability_service.max_samples = 2;
g_pol_durability_service.max_instances = 3;
g_pol_durability_service.max_samples_per_instance = 4;
g_pol_durability_service.service_cleanup_delay.sec = 90000;
g_pol_durability_service.service_cleanup_delay.nanosec = 99000;
}
static void
qos_fini(void)
{
dds_qos_delete(g_qos);
dds_free(g_pol_userdata.value._buffer);
dds_free(g_pol_groupdata.value._buffer);
dds_free(g_pol_topicdata.value._buffer);
}
static void
setup(void)
{
qos_init();
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
g_subscriber = dds_create_subscriber(g_participant, NULL, NULL);
cr_assert_gt(g_subscriber, 0, "Failed to create prerequisite g_subscriber");
g_publisher = dds_create_publisher(g_participant, NULL, NULL);
cr_assert_gt(g_publisher, 0, "Failed to create prerequisite g_publisher");
}
static void
teardown(void)
{
qos_fini();
dds_delete(g_participant);
}
#define T_MILLISECOND 1000000ll
#define T_SECOND (1000 * T_MILLISECOND)
int64_t from_ddsi_duration (DDS_Duration_t x)
{
int64_t t;
t = x.sec * 10^9 + x.nanosec;
return t;
}
static void
check_default_qos_of_builtin_entity(dds_entity_t entity)
{
dds_return_t ret;
int64_t deadline;
int64_t liveliness_lease_duration;
int64_t minimum_separation;
int64_t max_blocking_time;
int64_t autopurge_nowriter_samples_delay;
int64_t autopurge_disposed_samples_delay;
dds_durability_kind_t durability_kind;
dds_presentation_access_scope_kind_t presentation_access_scope_kind;
dds_ownership_kind_t ownership_kind;
dds_liveliness_kind_t liveliness_kind;
dds_reliability_kind_t reliability_kind;
dds_destination_order_kind_t destination_order_kind;
dds_history_kind_t history_kind;
char **partitions;
uint32_t plen;
dds_qos_t *qos = dds_qos_create();
cr_assert_not_null(qos);
ret = dds_get_qos(entity, qos);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to get QOS of builtin entity");
dds_qget_durability(qos, &durability_kind);
dds_qget_presentation(qos, &presentation_access_scope_kind, &g_pol_presentation.coherent_access, &g_pol_presentation.ordered_access);
dds_qget_deadline(qos, &deadline);
dds_qget_ownership(qos, &ownership_kind);
dds_qget_liveliness(qos, &liveliness_kind, &liveliness_lease_duration);
dds_qget_time_based_filter(qos, &minimum_separation);
dds_qget_reliability(qos, &reliability_kind, &max_blocking_time);
dds_qget_destination_order(qos, &destination_order_kind);
dds_qget_history(qos, &history_kind, &g_pol_history.depth);
dds_qget_resource_limits(qos, &g_pol_resource_limits.max_samples, &g_pol_resource_limits.max_instances, &g_pol_resource_limits.max_samples_per_instance);
dds_qget_reader_data_lifecycle(qos, &autopurge_nowriter_samples_delay, &autopurge_disposed_samples_delay);
dds_qget_partition(qos, &plen, &partitions);
// no getter for ENTITY_FACTORY
if ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) {
cr_expect_eq(plen, 1);
if (plen > 0) {
cr_expect_str_eq(partitions[0], "__BUILT-IN PARTITION__");
}
} else if ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) {
cr_expect_eq(durability_kind, DDS_DURABILITY_TRANSIENT_LOCAL);
cr_expect_eq(presentation_access_scope_kind, DDS_PRESENTATION_TOPIC);
cr_expect_eq(g_pol_presentation.coherent_access, false);
cr_expect_eq(g_pol_presentation.ordered_access, false);
cr_expect_eq(deadline, DDS_INFINITY);
cr_expect_eq(ownership_kind, DDS_OWNERSHIP_SHARED);
cr_expect_eq(liveliness_kind, DDS_LIVELINESS_AUTOMATIC);
cr_expect_eq(minimum_separation, 0);
cr_expect_eq(reliability_kind, DDS_RELIABILITY_RELIABLE);
cr_expect_eq(max_blocking_time, DDS_MSECS(100));
cr_expect_eq(destination_order_kind, DDS_DESTINATIONORDER_BY_RECEPTION_TIMESTAMP);
cr_expect_eq(history_kind, DDS_HISTORY_KEEP_LAST);
cr_expect_eq(g_pol_history.depth, 1);
cr_expect_eq(g_pol_resource_limits.max_instances, DDS_LENGTH_UNLIMITED);
cr_expect_eq(g_pol_resource_limits.max_samples, DDS_LENGTH_UNLIMITED);
cr_expect_eq(g_pol_resource_limits.max_samples_per_instance, DDS_LENGTH_UNLIMITED);
cr_expect_eq(autopurge_nowriter_samples_delay, DDS_INFINITY);
cr_expect_eq(autopurge_disposed_samples_delay, DDS_INFINITY);
} else {
cr_assert_fail("Unsupported entity kind %s", entity_kind_str(entity));
}
if (plen > 0) {
for (uint32_t i = 0; i < plen; i++) {
dds_free(partitions[i]);
}
dds_free(partitions);
}
dds_qos_delete(qos);
}
static dds_entity_t builtin_topic_handles[10];
Test(ddsc_builtin_topics, types_allocation)
{
#define TEST_ALLOC(type) do { \
DDS_##type##BuiltinTopicData *data = DDS_##type##BuiltinTopicData__alloc(); \
cr_expect_not_null(data, "Failed to allocate DDS_" #type "BuiltinTopicData"); \
DDS_##type##BuiltinTopicData_free(data, DDS_FREE_ALL); \
} while(0)
TEST_ALLOC(Participant);
TEST_ALLOC(CMParticipant);
TEST_ALLOC(Type);
TEST_ALLOC(Topic);
TEST_ALLOC(Publication);
TEST_ALLOC(CMPublisher);
TEST_ALLOC(Subscription);
TEST_ALLOC(CMSubscriber);
TEST_ALLOC(CMDataWriter);
TEST_ALLOC(CMDataReader);
#undef TEST_ALLOC
}
Test(ddsc_builtin_topics, availability_builtin_topics, .init = setup, .fini = teardown)
{
dds_entity_t topic;
topic = dds_find_topic(g_participant, "DCPSParticipant");
cr_assert_gt(topic, 0);
dds_delete(topic);
topic = dds_find_topic(g_participant, "DCPSTopic");
cr_assert_lt(topic, 0);
//TODO CHAM-347: dds_delete(topic);
topic = dds_find_topic(g_participant, "DCPSType");
cr_assert_lt(topic, 0);
//TODO CHAM-347: dds_delete(topic);
topic = dds_find_topic(g_participant, "DCPSSubscription");
cr_assert_lt(topic, 0);
//TODO CHAM-347: dds_delete(topic);
topic = dds_find_topic(g_participant, "DCSPPublication");
cr_assert_lt(topic, 0);
//TODO CHAM-347: dds_delete(topic);
}
Test(ddsc_builtin_topics, read_publication_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_PublicationBuiltinTopicData *data;
#endif
void *samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSPUBLICATION.");
samples[0] = DDS_PublicationBuiltinTopicData__alloc();
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples DCPSPublication");
data = (DDS_PublicationBuiltinTopicData *)samples;
cr_assert_str_eq(data->topic_name, "DCPSPublication");
#endif
DDS_PublicationBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, create_reader)
{
dds_entity_t participant;
dds_entity_t t1;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/*
* The topics are created by the middleware as soon as a participant
* is created.
*/
#define TEST_FIND(p, t) do { \
t1 = dds_find_topic(p, t); \
cr_expect_gt(t1, 0, "dds_find_topic(\"" t "\") returned a valid handle"); \
dds_delete(t1); \
} while(0);
/* A builtin-topic proxy is created 'on demand' and should not exist before a reader is created for it */
TEST_FIND(participant, "DCPSParticipant");
TEST_FIND(participant, "CMParticipant");
#undef TEST_FIND
/*
* TODO CHAM-347: Not all builtin topics are created at the start.
*/
#define TEST_NOTFOUND(p, t) do { \
t1 = dds_find_topic(p, t); \
cr_expect_lt(t1, 0, "dds_find_topic(\"" t "\") returned a valid handle"); \
} while(0);
/* A builtin-topic proxy is created 'on demand' and should not exist before a reader is created for it */
TEST_NOTFOUND(participant, "DCPSType");
TEST_NOTFOUND(participant, "DCPSTopic");
TEST_NOTFOUND(participant, "DCPSPublication");
TEST_NOTFOUND(participant, "CMPublisher");
TEST_NOTFOUND(participant, "DCPSSubscription");
TEST_NOTFOUND(participant, "CMSubscriber");
TEST_NOTFOUND(participant, "CMDataWriter");
TEST_NOTFOUND(participant, "CMDataReader");
#undef TEST_NOTFOUND
/* A reader is created by providing a special builtin-topic handle */
{
dds_entity_t readers[10];
dds_entity_t builtin_subscriber, s;
builtin_topic_handles[0] = DDS_BUILTIN_TOPIC_DCPSPARTICIPANT;
builtin_topic_handles[1] = DDS_BUILTIN_TOPIC_CMPARTICIPANT;
builtin_topic_handles[2] = DDS_BUILTIN_TOPIC_DCPSTYPE;
builtin_topic_handles[3] = DDS_BUILTIN_TOPIC_DCPSTOPIC;
builtin_topic_handles[4] = DDS_BUILTIN_TOPIC_DCPSPUBLICATION;
builtin_topic_handles[5] = DDS_BUILTIN_TOPIC_CMPUBLISHER;
builtin_topic_handles[6] = DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION;
builtin_topic_handles[7] = DDS_BUILTIN_TOPIC_CMSUBSCRIBER;
builtin_topic_handles[8] = DDS_BUILTIN_TOPIC_CMDATAWRITER;
builtin_topic_handles[9] = DDS_BUILTIN_TOPIC_CMDATAREADER;
for (int i = 0; i < 10; i++) {
readers[i] = dds_create_reader(participant, builtin_topic_handles[i], NULL, NULL);
cr_expect_gt(readers[i], 0, "Failed to created reader for builtin topic handle %d", builtin_topic_handles[i]);
if (i == 0) {
/* Check the parent of reader is a subscriber */
builtin_subscriber = dds_get_parent(readers[i]);
cr_assert_gt(builtin_subscriber, 0, "Failed to get parent of first builtin-reader (%s)", dds_err_str(builtin_subscriber));
cr_assert_eq(builtin_subscriber & DDS_ENTITY_KIND_MASK, DDS_KIND_SUBSCRIBER, "Parent is not a subscriber");
} else {
/* Check the parent of reader equals parent of first reader */
s = dds_get_parent(readers[i]);
cr_assert_gt(s, 0, "Failed to get parent of builtin-reader (%s)", dds_err_str(s));
cr_assert_eq(s, builtin_subscriber, "Parent subscriber of reader(%d) doesn't equal builtin-subscriber", i);
//dds_delete(s);
}
}
}
#define TEST_FOUND(p, t) do { \
t1 = dds_find_topic(p, t); \
cr_expect_gt(t1, 0, "dds_find_topic(\"" t "\") returned an invalid handle (%s)", dds_err_str(t1)); \
if (t1 > 0) { \
dds_delete(t1); \
} \
} while(0);
/* Builtin-topics proxies should now be created */
TEST_FOUND(participant, "DCPSParticipant");
TEST_FOUND(participant, "CMParticipant");
TEST_FOUND(participant, "DCPSType");
TEST_FOUND(participant, "DCPSTopic");
TEST_FOUND(participant, "DCPSPublication");
TEST_FOUND(participant, "CMPublisher");
TEST_FOUND(participant, "DCPSSubscription");
TEST_FOUND(participant, "CMSubscriber");
TEST_FOUND(participant, "CMDataWriter");
TEST_FOUND(participant, "CMDataReader");
#undef TEST_FOUND
dds_delete(participant);
}
Test(ddsc_builtin_topics, read_subscription_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
#if 0 /* not supported yet */
dds_return_t ret;
DDS_SubscriptionBuiltinTopicData *data;
#endif
void * samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION.");
samples[0] = DDS_SubscriptionBuiltinTopicData__alloc();
#if 0 /* not supported yet */
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples DCPSSubscription");
data = (DDS_SubscriptionBuiltinTopicData *)samples;
cr_assert_str_eq(data->topic_name, "DCPSSubscription");
#endif
DDS_SubscriptionBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, read_participant_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
dds_return_t ret;
void * samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSPARTICIPANT.");
samples[0] = DDS_ParticipantBuiltinTopicData__alloc();
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples DCPSParticipant");
{
DDS_ParticipantBuiltinTopicData *data = (DDS_ParticipantBuiltinTopicData*)samples[0];
cr_log_info("Participant.key: %x.%x.%x\n", data->key[0], data->key[1], data->key[2]);
cr_log_info("Participant.userdata: %s\n", data->user_data.value._buffer);
}
DDS_ParticipantBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, read_cmparticipant_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
dds_return_t ret;
void * samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_CMPARTICIPANT, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSPARTICIPANT.");
samples[0] = DDS_CMParticipantBuiltinTopicData__alloc();
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples CMParticipant");
{
DDS_CMParticipantBuiltinTopicData *data = (DDS_CMParticipantBuiltinTopicData*)samples[0];
cr_log_info("CMParticipant.key: %x.%x.%x\n", data->key[0], data->key[1], data->key[2]);
cr_log_info("CMParticipant.product: %s\n", data->product.value);
}
DDS_CMParticipantBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, read_topic_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_TopicBuiltinTopicData *data;
#endif
void * samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSTOPIC, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSTOPIC.");
samples[0] = DDS_TopicBuiltinTopicData__alloc();
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples DCPSTopic");
data = (DDS_TopicBuiltinTopicData *)samples;
cr_assert_str_eq(data->name, "DCPSSubscription");
#endif
DDS_ParticipantBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, read_type_data, .init = setup, .fini = teardown)
{
dds_entity_t reader;
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_TypeBuiltinTopicData *data;
#endif
void * samples[MAX_SAMPLES];
reader = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSTYPE, NULL, NULL);
cr_assert_gt(reader, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSTYPE.");
samples[0] = DDS_TypeBuiltinTopicData__alloc();
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(reader, samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read samples DCPSType");
data = (DDS_TypeBuiltinTopicData *)samples;
cr_assert_str_eq(data->name, "DCPSType");
#endif
DDS_TypeBuiltinTopicData_free(samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, same_subscriber, .init = setup, .fini = teardown)
{
dds_entity_t subscription_rdr;
dds_entity_t subscription_subscriber;
dds_entity_t publication_rdr;
dds_entity_t publication_subscriber;
dds_entity_t participant_rdr;
dds_entity_t participant_subscriber;
dds_entity_t topic_rdr;
dds_entity_t topic_subscriber;
dds_entity_t type_rdr;
dds_entity_t type_subscriber;
subscription_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL);
cr_assert_gt(subscription_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION.");
subscription_subscriber = dds_get_parent(subscription_rdr);
cr_assert_gt(subscription_subscriber, 0, "Could not find builtin subscriber for DSCPSSubscription-reader.");
publication_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL);
cr_assert_gt(publication_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSPUBLICATION.");
publication_subscriber = dds_get_parent(publication_rdr);
cr_assert_gt(publication_subscriber, 0, "Could not find builtin subscriber for DSCPSPublication-reader.");
cr_assert_eq(subscription_subscriber, publication_subscriber);
participant_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL);
cr_assert_gt(participant_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSPARTICIPANT.");
participant_subscriber = dds_get_parent(participant_rdr);
cr_assert_gt(participant_subscriber, 0, "Could not find builtin subscriber for DSCPSParticipant-reader.");
cr_assert_eq(publication_subscriber, participant_subscriber);
topic_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSTOPIC, NULL, NULL);
cr_assert_gt(topic_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSTOPIC.");
topic_subscriber = dds_get_parent(topic_rdr);
cr_assert_gt(topic_subscriber, 0, "Could not find builtin subscriber for DSCPSTopic-reader.");
cr_assert_eq(participant_subscriber, topic_subscriber);
type_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSTYPE, NULL, NULL);
cr_assert_gt(type_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSTYPE.");
type_subscriber = dds_get_parent(type_rdr);
cr_assert_gt(type_subscriber, 0, "Could not find builtin subscriber for DSCPSType-reader.");
cr_assert_eq(topic_subscriber, type_subscriber);
}
Test(ddsc_builtin_topics, builtin_qos, .init = setup, .fini = teardown)
{
dds_entity_t dds_sub_rdr;
dds_entity_t dds_sub_subscriber;
dds_sub_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL);
cr_assert_gt(dds_sub_rdr, 0, "Failed to create a data reader for DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION.");
check_default_qos_of_builtin_entity(dds_sub_rdr);
dds_sub_subscriber = dds_get_parent(dds_sub_rdr);
cr_assert_gt(dds_sub_subscriber, 0, "Could not find builtin subscriber for DSCPSSubscription-reader.");
check_default_qos_of_builtin_entity(dds_sub_subscriber);
}
Test(ddsc_builtin_topics, datareader_qos, .init = setup, .fini = teardown)
{
dds_entity_t rdr;
dds_entity_t subscription_rdr;
void * subscription_samples[MAX_SAMPLES];
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_SubscriptionBuiltinTopicData *subscription_data;
#endif
// Set some qos' which differ from the default
dds_qset_durability(g_qos, (dds_durability_kind_t)g_pol_durability.kind);
dds_qset_deadline(g_qos, from_ddsi_duration(g_pol_deadline.period));
dds_qset_latency_budget(g_qos, from_ddsi_duration(g_pol_latency_budget.duration));
dds_qset_liveliness(g_qos, (dds_liveliness_kind_t)g_pol_liveliness.kind, from_ddsi_duration(g_pol_liveliness.lease_duration));
dds_qset_reliability(g_qos, (dds_reliability_kind_t)g_pol_reliability.kind, from_ddsi_duration(g_pol_reliability.max_blocking_time));
dds_qset_ownership(g_qos, (dds_ownership_kind_t)g_pol_ownership.kind);
dds_qset_destination_order(g_qos, (dds_destination_order_kind_t)g_pol_destination_order.kind);
dds_qset_userdata(g_qos, g_pol_userdata.value._buffer, g_pol_userdata.value._length);
dds_qset_time_based_filter(g_qos, from_ddsi_duration(g_pol_time_based_filter.minimum_separation));
dds_qset_presentation(g_qos, g_pol_presentation.access_scope, g_pol_presentation.coherent_access, g_pol_presentation.ordered_access);
dds_qset_partition(g_qos, g_pol_partition.name._length, c_partitions);
dds_qset_topicdata(g_qos, g_pol_topicdata.value._buffer, g_pol_topicdata.value._length);
dds_qset_groupdata(g_qos, g_pol_groupdata.value._buffer, g_pol_groupdata.value._length);
rdr = dds_create_reader(g_subscriber, g_topic, g_qos, NULL);
subscription_samples[0] = DDS_SubscriptionBuiltinTopicData__alloc();
subscription_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL);
cr_assert_gt(subscription_rdr, 0, "Failed to retrieve built-in datareader for DCPSSubscription");
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(subscription_rdr, subscription_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read Subscription data");
// Check the QOS settings of the 'remote' qos'
subscription_data = (DDS_SubscriptionBuiltinTopicData *)subscription_samples[0];
cr_assert_str_eq(subscription_data->topic_name, "RoundTrip");
cr_assert_str_eq(subscription_data->type_name, "RoundTripModule::DataType");
cr_assert_eq(subscription_data->durability.kind, g_pol_durability.kind);
cr_assert_eq(subscription_data->deadline.period.sec, g_pol_deadline.period.sec);
cr_assert_eq(subscription_data->deadline.period.nanosec, g_pol_deadline.period.nanosec);
cr_assert_eq(subscription_data->latency_budget.duration.sec, g_pol_latency_budget.duration.sec);
cr_assert_eq(subscription_data->latency_budget.duration.nanosec, g_pol_latency_budget.duration.nanosec);
cr_assert_eq(subscription_data->liveliness.kind, g_pol_liveliness.kind);
cr_assert_eq(subscription_data->liveliness.lease_duration.sec, g_pol_liveliness.lease_duration.sec);
cr_assert_eq(subscription_data->liveliness.lease_duration.nanosec, g_pol_liveliness.lease_duration.nanosec);
cr_assert_eq(subscription_data->reliability.kind, g_pol_reliability.kind);
cr_assert_eq(subscription_data->reliability.max_blocking_time.sec, g_pol_reliability.max_blocking_time.sec);
cr_assert_eq(subscription_data->reliability.max_blocking_time.nanosec, g_pol_reliability.max_blocking_time.nanosec);
cr_assert_eq(subscription_data->ownership.kind, g_pol_ownership.kind);
cr_assert_eq(subscription_data->destination_order.kind, g_pol_destination_order.kind);
cr_assert_eq(subscription_data->user_data.value._buffer, g_pol_userdata.value._buffer);
cr_assert_eq(subscription_data->user_data.value._length, g_pol_userdata.value._length);
cr_assert_eq(subscription_data->time_based_filter.minimum_separation.sec, g_pol_time_based_filter.minimum_separation.sec);
cr_assert_eq(subscription_data->time_based_filter.minimum_separation.nanosec, g_pol_time_based_filter.minimum_separation.nanosec);
cr_assert_eq(subscription_data->presentation.access_scope, g_pol_presentation.access_scope);
cr_assert_eq(subscription_data->presentation.coherent_access, g_pol_presentation.coherent_access);
cr_assert_eq(subscription_data->presentation.ordered_access, g_pol_presentation.ordered_access);
cr_assert_eq(subscription_data->partition.name._length, g_pol_partition.name._length);
for (uint32_t i = 0; i < subscription_data->partition.name._length; ++i)
{
cr_assert_str_eq(subscription_data->partition.name._buffer[i], c_partitions[i]);
}
cr_assert_str_eq(subscription_data->topic_data.value._buffer, g_pol_topicdata.value._buffer);
cr_assert_eq(subscription_data->topic_data.value._length, g_pol_topicdata.value._length);
cr_assert_str_eq(subscription_data->group_data.value._buffer, g_pol_groupdata.value._buffer);
cr_assert_eq(subscription_data->group_data.value._length, g_pol_groupdata.value._length);
#endif
DDS_SubscriptionBuiltinTopicData_free(subscription_samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, datawriter_qos, .init = setup, .fini = teardown)
{
dds_entity_t wrtr;
dds_entity_t publication_rdr;
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_PublicationBuiltinTopicData *publication_data;
#endif
void * publication_samples[MAX_SAMPLES];
dds_qset_durability(g_qos, g_pol_durability.kind);
dds_qset_deadline(g_qos, from_ddsi_duration(g_pol_deadline.period));
dds_qset_latency_budget(g_qos, from_ddsi_duration(g_pol_latency_budget.duration));
dds_qset_liveliness(g_qos, (dds_liveliness_kind_t)g_pol_liveliness.kind, from_ddsi_duration(g_pol_liveliness.lease_duration));
dds_qset_reliability(g_qos, (dds_reliability_kind_t)g_pol_reliability.kind, from_ddsi_duration(g_pol_reliability.max_blocking_time));
dds_qset_lifespan(g_qos, from_ddsi_duration(g_pol_lifespan.duration));
dds_qset_destination_order(g_qos, (dds_destination_order_kind_t)g_pol_destination_order.kind);
dds_qset_userdata(g_qos, g_pol_userdata.value._buffer, g_pol_userdata.value._length);
dds_qset_ownership(g_qos, (dds_ownership_kind_t)g_pol_ownership.kind);
dds_qset_ownership_strength(g_qos, g_pol_ownership_strength.value);
dds_qset_presentation(g_qos, g_pol_presentation.access_scope, g_pol_presentation.coherent_access, g_pol_presentation.ordered_access);
dds_qset_partition(g_qos, g_pol_partition.name._length, c_partitions);
dds_qset_topicdata(g_qos, g_pol_topicdata.value._buffer, g_pol_topicdata.value._length);
wrtr = dds_create_writer(g_publisher, g_topic, g_qos, NULL);
publication_samples[0] = DDS_PublicationBuiltinTopicData__alloc();
publication_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL);
cr_assert_gt(publication_rdr, 0, "Failed to retrieve built-in datareader for DCPSPublication");
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(publication_rdr, publication_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read Publication data");
// Check the QOS settings of the 'remote' qos'
publication_data = (DDS_PublicationBuiltinTopicData *)publication_samples[0];
cr_assert_str_eq(publication_data->topic_name, "RoundTrip");
cr_assert_str_eq(publication_data->type_name, "RoundTripModule::DataType");
cr_assert_eq(publication_data->durability.kind, g_pol_durability.kind);
cr_assert_eq(publication_data->deadline.period.sec, g_pol_deadline.period.sec);
cr_assert_eq(publication_data->deadline.period.nanosec, g_pol_deadline.period.nanosec);
cr_assert_eq(publication_data->latency_budget.duration.sec, g_pol_latency_budget.duration.sec);
cr_assert_eq(publication_data->latency_budget.duration.nanosec, g_pol_latency_budget.duration.nanosec);
cr_assert_eq(publication_data->liveliness.kind, g_pol_liveliness.kind);
cr_assert_eq(publication_data->liveliness.lease_duration.sec, g_pol_liveliness.lease_duration.sec);
cr_assert_eq(publication_data->liveliness.lease_duration.nanosec, g_pol_liveliness.lease_duration.nanosec);
cr_assert_eq(publication_data->reliability.kind, g_pol_reliability.kind);
cr_assert_eq(publication_data->reliability.max_blocking_time.sec, g_pol_reliability.max_blocking_time.sec);
cr_assert_eq(publication_data->reliability.max_blocking_time.nanosec, g_pol_reliability.max_blocking_time.nanosec);
cr_assert_eq(publication_data->lifespan.duration.sec, g_pol_lifespan.duration.sec);
cr_assert_eq(publication_data->lifespan.duration.nanosec, g_pol_lifespan.duration.nanosec);
cr_assert_eq(publication_data->destination_order.kind, g_pol_destination_order.kind);
cr_assert_eq(publication_data->user_data.value._buffer, g_pol_userdata.value._buffer);
cr_assert_eq(publication_data->user_data.value._length, g_pol_userdata.value._length);
cr_assert_eq(publication_data->ownership.kind, g_pol_ownership.kind);
cr_assert_eq(publication_data->ownership_strength.value, g_pol_ownership_strength.value);
cr_assert_eq(publication_data->presentation.access_scope, g_pol_presentation.access_scope);
cr_assert_eq(publication_data->presentation.coherent_access, g_pol_presentation.coherent_access);
cr_assert_eq(publication_data->presentation.ordered_access, g_pol_presentation.ordered_access);
cr_assert_eq(publication_data->partition.name._length, g_pol_partition.name._length);
for (uint32_t i = 0; i < publication_data->partition.name._length; ++i)
{
cr_assert_str_eq(publication_data->partition.name._buffer[i], c_partitions[i]);
}
cr_assert_str_eq(publication_data->topic_data.value._buffer, g_pol_topicdata.value._buffer);
cr_assert_eq(publication_data->topic_data.value._length, g_pol_topicdata.value._length);
cr_assert_str_eq(publication_data->group_data.value._buffer, g_pol_groupdata.value._buffer);
cr_assert_eq(publication_data->group_data.value._length, g_pol_groupdata.value._length);
#endif
DDS_PublicationBuiltinTopicData_free(publication_samples[0], DDS_FREE_ALL);
}
Test(ddsc_builtin_topics, topic_qos, .init = setup, .fini = teardown)
{
dds_entity_t tpc;
dds_entity_t topic_rdr;
#if 0 /* disabled pending CHAM-347 */
dds_return_t ret;
DDS_TopicBuiltinTopicData *topic_data;
#endif
void * topic_samples[MAX_SAMPLES];
dds_qset_durability(g_qos, g_pol_durability.kind);
dds_qset_durability_service(g_qos,
from_ddsi_duration(g_pol_durability_service.service_cleanup_delay),
(dds_history_kind_t)g_pol_durability_service.history_kind,
g_pol_durability_service.history_depth,
g_pol_durability_service.max_samples,
g_pol_durability_service.max_instances,
g_pol_durability_service.max_samples_per_instance);
dds_qset_deadline(g_qos, from_ddsi_duration(g_pol_deadline.period));
dds_qset_latency_budget(g_qos, from_ddsi_duration(g_pol_latency_budget.duration));
dds_qset_liveliness(g_qos, (dds_liveliness_kind_t)g_pol_liveliness.kind, from_ddsi_duration(g_pol_liveliness.lease_duration));
dds_qset_reliability(g_qos, (dds_reliability_kind_t)g_pol_reliability.kind, from_ddsi_duration(g_pol_reliability.max_blocking_time));
dds_qset_transport_priority(g_qos, g_pol_transport_priority.value);
dds_qset_lifespan(g_qos, from_ddsi_duration(g_pol_lifespan.duration));
dds_qset_destination_order(g_qos, (dds_destination_order_kind_t)g_pol_destination_order.kind);
dds_qset_history(g_qos, (dds_history_kind_t)g_pol_history.kind, g_pol_history.depth);
dds_qset_resource_limits(g_qos, g_pol_resource_limits.max_samples, g_pol_resource_limits.max_instances,
g_pol_resource_limits.max_samples_per_instance);
dds_qset_ownership(g_qos, (dds_ownership_kind_t)g_pol_ownership.kind);
dds_qset_topicdata(g_qos, g_pol_topicdata.value._buffer, g_pol_topicdata.value._length);
tpc = dds_create_topic(g_participant, &Space_Type1_desc, "SpaceType1", g_qos, NULL);
topic_samples[0] = DDS_PublicationBuiltinTopicData__alloc();
topic_rdr = dds_create_reader(g_participant, DDS_BUILTIN_TOPIC_DCPSTOPIC, NULL, NULL);
cr_assert_gt(topic_rdr, 0, "Failed to retrieve built-in datareader for DCPSPublication");
#if 0 /* disabled pending CHAM-347 */
ret = dds_read(topic_rdr, topic_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed to read Topic data");
topic_data = (DDS_TopicBuiltinTopicData *)topic_samples[0];
cr_assert_str_eq(topic_data->name, "SpaceType1");
cr_assert_str_eq(topic_data->type_name, "RoundTripModule::DataType");
cr_assert_eq(topic_data->durability.kind, g_pol_durability.kind);
cr_assert_eq(topic_data->durability_service.service_cleanup_delay.sec, g_pol_durability_service.service_cleanup_delay.sec);
cr_assert_eq(topic_data->durability_service.service_cleanup_delay.nanosec, g_pol_durability_service.service_cleanup_delay.nanosec);
cr_assert_eq(topic_data->durability_service.history_kind, g_pol_durability_service.history_kind);
cr_assert_eq(topic_data->durability_service.history_depth, g_pol_durability_service.history_depth);
cr_assert_eq(topic_data->durability_service.max_samples, g_pol_durability_service.max_samples);
cr_assert_eq(topic_data->durability_service.max_instances, g_pol_durability_service.max_instances);
cr_assert_eq(topic_data->durability_service.max_samples_per_instance, g_pol_durability_service.max_samples_per_instance);
cr_assert_eq(topic_data->deadline.period.sec, g_pol_deadline.period.sec);
cr_assert_eq(topic_data->deadline.period.nanosec, g_pol_deadline.period.nanosec);
cr_assert_eq(topic_data->latency_budget.duration.sec, g_pol_latency_budget.duration.sec);
cr_assert_eq(topic_data->latency_budget.duration.nanosec, g_pol_latency_budget.duration.nanosec);
cr_assert_eq(topic_data->liveliness.kind, g_pol_liveliness.kind);
cr_assert_eq(topic_data->liveliness.lease_duration.sec, g_pol_liveliness.lease_duration.sec);
cr_assert_eq(topic_data->liveliness.lease_duration.nanosec, g_pol_liveliness.lease_duration.nanosec);
cr_assert_eq(topic_data->reliability.kind, g_pol_reliability.kind);
cr_assert_eq(topic_data->reliability.max_blocking_time.sec, g_pol_reliability.max_blocking_time.sec);
cr_assert_eq(topic_data->reliability.max_blocking_time.nanosec, g_pol_reliability.max_blocking_time.nanosec);
cr_assert_eq(topic_data->transport_priority.value, g_pol_transport_priority.value);
cr_assert_eq(topic_data->lifespan.duration.sec, g_pol_lifespan.duration.sec);
cr_assert_eq(topic_data->lifespan.duration.nanosec, g_pol_lifespan.duration.nanosec);
cr_assert_eq(topic_data->destination_order.kind, g_pol_destination_order.kind);
cr_assert_eq(topic_data->history.kind, g_pol_history.kind);
cr_assert_eq(topic_data->history.depth, g_pol_history.depth);
cr_assert_eq(topic_data->resource_limits.max_samples, g_pol_resource_limits.max_samples);
cr_assert_eq(topic_data->resource_limits.max_instances, g_pol_resource_limits.max_instances);
cr_assert_eq(topic_data->resource_limits.max_samples_per_instance, g_pol_resource_limits.max_samples_per_instance);
cr_assert_eq(topic_data->ownership.kind, g_pol_ownership.kind);
cr_assert_str_eq(topic_data->topic_data.value._buffer, g_pol_topicdata.value._buffer);
cr_assert_eq(topic_data->topic_data.value._length, g_pol_topicdata.value._length);
#endif
DDS_TopicBuiltinTopicData_free(topic_samples[0], DDS_FREE_ALL);
}

View file

@ -0,0 +1,79 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include "os/os.h"
#include "config_env.h"
#include "ddsc/ddsc_project.h"
#define FORCE_ENV
#define URI_VARIABLE DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI"
#define MAX_PARTICIPANTS_VARIABLE "MAX_PARTICIPANTS"
static void config__check_env(
_In_z_ const char * env_variable,
_In_z_ const char * expected_value)
{
const char * env_uri = os_getenv(env_variable);
const char * const env_not_set = "Environment variable '%s' isn't set. This needs to be set to '%s' for this test to run.";
const char * const env_not_as_expected = "Environment variable '%s' has an unexpected value: '%s' (expected: '%s')";
#ifdef FORCE_ENV
{
bool env_ok;
if ( env_uri == NULL ) {
cr_log_info(env_not_set, env_variable, expected_value);
env_ok = false;
} else if ( strncmp(env_uri, expected_value, strlen(expected_value)) != 0 ) {
cr_log_info(env_not_as_expected, env_variable, env_uri, expected_value);
env_ok = false;
} else {
env_ok = true;
}
if ( !env_ok ) {
os_result r;
char *envstr;
envstr = os_malloc(strlen(env_variable) + strlen("=") + strlen(expected_value) + 1);
(void) sprintf(envstr, "%s=%s", env_variable, expected_value);
r = os_putenv(envstr);
cr_assert_eq(r, os_resultSuccess, "Invoking os_putenv(\"%s\") failed", envstr);
cr_log_warn("Environment variable '%s' set to expected value '%s'", env_variable, expected_value);
os_free(envstr);
}
}
#else
cr_assert_not_null(env_uri, env_not_set, env_variable, expected_value);
cr_assert_str_eq(env_uri, expected_value, env_not_as_expected, env_variable, env_uri, expected_value);
#endif /* FORCE_ENV */
}
Test(ddsc_config, simple_udp, .init = os_osInit, .fini = os_osExit) {
dds_entity_t participant;
config__check_env(URI_VARIABLE, CONFIG_ENV_SIMPLE_UDP);
config__check_env(MAX_PARTICIPANTS_VARIABLE, CONFIG_ENV_MAX_PARTICIPANTS);
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_create_participant");
dds_delete(participant);
}

View file

@ -0,0 +1,18 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#ifndef CONFIG_ENV_H
#define CONFIG_ENV_H
#define CONFIG_ENV_SIMPLE_UDP "@Criterion_ddsc_config_simple_udp_uri@"
#define CONFIG_ENV_MAX_PARTICIPANTS "@Criterion_ddsc_config_simple_udp_max_participants@"
#endif /* CONFIG_ENV_H */

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
-->
<CycloneDDS>
<!-- Simple config-file for testing whether a config-file can be picked up
correctly. -->
<Domain>
<Id>3</Id>
</Domain>
<Lease>
<ExpiryTime update_factor="2e-1"/>
</Lease>
<DDSI2E>
<General>
<NetworkInterfaceAddress>127.0.0.1</NetworkInterfaceAddress>
<AllowMulticast>true</AllowMulticast>
<EnableMulticastLoopback>true</EnableMulticastLoopback>
<EnableLoopback>false</EnableLoopback>
</General>
<Compatibility>
<StandardsConformance>lax</StandardsConformance>
</Compatibility>
<Tracing>
<Verbosity>warning</Verbosity>
<OutputFile>&#118;&#x6F;rtexdds-<![CDATA[trace]]>.${NON_EXISTENT_ENV_VARIABLE:-l}${CYCLONEDDS_URI:+o}g </OutputFile>
</Tracing>
<Internal>
<MaxParticipants>${MAX_PARTICIPANTS}</MaxParticipants>
<HeartbeatInterval max="10 s"> 100 ms </HeartbeatInterval>
<RediscoveryBlacklistDuration></RediscoveryBlacklistDuration>
</Internal>
</DDSI2E>
</CycloneDDS>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,365 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
/* We are deliberately testing some bad arguments that SAL will complain about.
* So, silence SAL regarding these issues. */
#pragma warning(push)
#pragma warning(disable: 6387 28020)
/* Add --verbose command line argument to get the cr_log_info traces (if there are any). */
static dds_entity_t entity = -1;
#define cr_assert_status_eq(s1, s2, ...) cr_assert_eq(dds_err_nr(s1), s2, __VA_ARGS__)
/* Fixture to create prerequisite entity */
void create_entity(void)
{
cr_assert_eq(entity, -1, "entity already created pre create_entity fixture");
entity = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(entity, 0, "create_entity fixture failed");
}
/* Fixture to delete prerequisite entity */
void delete_entity(void)
{
cr_assert_gt(entity, 0, "entity not created pre delete_entity fixture");
dds_return_t ret = dds_delete(entity);
cr_assert_status_eq(ret, DDS_RETCODE_OK, "delete_entity fixture failed (ret: %d)", dds_err_nr(ret));
entity = -1;
}
Test(ddsc_entity, create, .fini = delete_entity)
{
/* Use participant as entity in the tests. */
entity = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(entity, 0, "dds_create_participant");
}
Test(ddsc_entity, enable, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
/* Check enabling with bad parameters. */
status = dds_enable(0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_enable (NULL)");
/* Check actual enabling. */
/* TODO: CHAM-96: Check enabling.
status = dds_enable(&entity);
cr_assert_status_eq(status, dds_err_nr(DDS_RETCODE_OK), "dds_enable (delayed enable)");
*/
/* Check re-enabling (should be a noop). */
status = dds_enable(entity);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_enable (already enabled)");
}
void entity_qos_get_set(dds_entity_t e, const char* info)
{
dds_return_t status;
dds_qos_t *qos = dds_qos_create();
/* Get QoS. */
status = dds_get_qos (e, qos);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_qos(e, qos) ret: %d, %s", dds_err_nr(status), info);
status = dds_set_qos (e, qos); /* Doesn't change anything, so no need to forbid. But we return NOT_SUPPORTED anyway for now*/
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_set_qos(entity, qos) %s", info);
dds_qos_delete(qos);
}
Test(ddsc_entity, qos, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
dds_qos_t *qos = dds_qos_create();
/* Don't check inconsistent and immutable policies. That's a job
* for the specific entity children, not for the generic part. */
/* Check getting QoS with bad parameters. */
status = dds_get_qos (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_qos(NULL, NULL)");
status = dds_get_qos (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_qos(entity, NULL)");
status = dds_get_qos (0, qos);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_qos(NULL, qos)");
/* Check setting QoS with bad parameters. */
status = dds_set_qos (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_set_qos(NULL, NULL)");
status = dds_set_qos (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_set_qos(entity, NULL)");
status = dds_set_qos (0, qos);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_set_qos(NULL, qos)");
/* Check set/get with entity without initial qos. */
entity_qos_get_set(entity, "{without initial qos}");
/* Check set/get with entity with initial qos. */
{
dds_entity_t par = dds_create_participant (DDS_DOMAIN_DEFAULT, qos, NULL);
entity_qos_get_set(par, "{with initial qos}");
dds_delete(par);
}
/* Delete qos. */
dds_qos_delete(qos);
}
Test(ddsc_entity, listener, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
dds_listener_t *l1 = dds_listener_create(NULL);
dds_listener_t *l2 = dds_listener_create(NULL);
void *cb1;
void *cb2;
/* Don't check actual workings of the listeners. That's a job
* for the specific entity children, not for the generic part. */
/* Set some random values for the l2 listener callbacks.
* I know for sure that these will not be called within this test.
* Otherwise, the following would let everything crash.
* We just set them to know for sure that we got what we set. */
dds_lset_liveliness_changed(l2, (dds_on_liveliness_changed_fn) 1234);
dds_lset_requested_deadline_missed(l2, (dds_on_requested_deadline_missed_fn) 5678);
dds_lset_requested_incompatible_qos(l2, (dds_on_requested_incompatible_qos_fn) 8765);
dds_lset_publication_matched(l2, (dds_on_publication_matched_fn) 4321);
/* Check getting Listener with bad parameters. */
status = dds_get_listener (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_listener(NULL, NULL)");
status = dds_get_listener (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_listener(entity, NULL)");
status = dds_get_listener (0, l1);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_listener(NULL, listener)");
/* Get Listener, which should be unset. */
status = dds_get_listener (entity, l1);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_listener(entity, listener)");
dds_lget_liveliness_changed (l1, (dds_on_liveliness_changed_fn*)&cb1);
cr_assert_eq(cb1, DDS_LUNSET, "Listener not initialized to NULL");
dds_lget_requested_deadline_missed (l1, (dds_on_requested_deadline_missed_fn*)&cb1);
cr_assert_eq(cb1, DDS_LUNSET, "Listener not initialized to NULL");
dds_lget_requested_incompatible_qos (l1, (dds_on_requested_incompatible_qos_fn*)&cb1);
cr_assert_eq(cb1, DDS_LUNSET, "Listener not initialized to NULL");
dds_lget_publication_matched (l1, (dds_on_publication_matched_fn*)&cb1);
cr_assert_eq(cb1, DDS_LUNSET, "Listener not initialized to NULL");
/* Check setting Listener with bad parameters. */
status = dds_set_listener (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_set_listener(NULL, NULL)");
status = dds_set_listener (0, l2);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_set_listener(NULL, listener)");
/* Getting after setting should return set listener. */
status = dds_set_listener (entity, l2);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_set_listener(entity, listener)");
status = dds_get_listener (entity, l1);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_listener(entity, listener)");
dds_lget_liveliness_changed (l1, (dds_on_liveliness_changed_fn*)&cb1);
dds_lget_liveliness_changed (l2, (dds_on_liveliness_changed_fn*)&cb2);
cr_assert_eq(cb1, cb2, "Listeners are not equal");
dds_lget_requested_deadline_missed (l1, (dds_on_requested_deadline_missed_fn*)&cb1);
dds_lget_requested_deadline_missed (l2, (dds_on_requested_deadline_missed_fn*)&cb2);
cr_assert_eq(cb1, cb2, "Listeners are not equal");
dds_lget_requested_incompatible_qos (l1, (dds_on_requested_incompatible_qos_fn*)&cb1);
dds_lget_requested_incompatible_qos (l2, (dds_on_requested_incompatible_qos_fn*)&cb2);
cr_assert_eq(cb1, cb2, "Listeners are not equal");
dds_lget_publication_matched (l1, (dds_on_publication_matched_fn*)&cb1);
dds_lget_publication_matched (l2, (dds_on_publication_matched_fn*)&cb2);
cr_assert_eq(cb1, cb2, "Listeners are not equal");
/* Reset listener. */
status = dds_set_listener (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_set_listener(entity, NULL)");
status = dds_get_listener (entity, l2);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_listener(entity, listener)");
dds_lget_liveliness_changed (l2, (dds_on_liveliness_changed_fn*)&cb2);
cr_assert_eq(cb2, DDS_LUNSET, "Listener not reset");
dds_lget_requested_deadline_missed (l2, (dds_on_requested_deadline_missed_fn*)&cb2);
cr_assert_eq(cb2, DDS_LUNSET, "Listener not reset");
dds_lget_requested_incompatible_qos (l2, (dds_on_requested_incompatible_qos_fn*)&cb2);
cr_assert_eq(cb2, DDS_LUNSET, "Listener not reset");
dds_lget_publication_matched (l2, (dds_on_publication_matched_fn*)&cb2);
cr_assert_eq(cb2, DDS_LUNSET, "Listener not reset");
dds_free(l2);
dds_free(l1);
}
Test(ddsc_entity, status, .init = create_entity, .fini = delete_entity)
{
dds_return_t status1;
uint32_t s1 = 0;
/* Don't check actual bad statuses. That's a job
* for the specific entity children, not for the generic part. */
/* Check getting Status with bad parameters. */
status1 = dds_get_enabled_status (0, NULL);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_enabled_status(NULL, NULL)");
status1 = dds_get_enabled_status (entity, NULL);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_enabled_status(entity, NULL)");
status1 = dds_get_enabled_status (0, &s1);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_enabled_status(NULL, status)");
/* Get Status, which should be 0 for a participant. */
status1 = dds_get_enabled_status (entity, &s1);
cr_assert_status_eq(status1, DDS_RETCODE_OK, "dds_get_enabled_status(entity, status)");
cr_assert_eq(s1, 0, "Enabled status mask is not 0");
/* Check setting Status with bad parameters. */
status1 = dds_set_enabled_status (0, 0);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_set_enabled_status(NULL, 0)");
/* I shouldn't be able to set statuses on a participant. */
status1 = dds_set_enabled_status (entity, 0);
cr_assert_status_eq(status1, DDS_RETCODE_OK, "dds_set_enabled_status(entity, 0) %d", dds_err_nr(status1));
status1 = dds_set_enabled_status (entity, DDS_DATA_AVAILABLE_STATUS);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_set_enabled_status(entity, status)");
/* Check getting Status changes with bad parameters. */
status1 = dds_get_status_changes (0, NULL);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_status_changes(NULL, NULL)");
status1 = dds_get_status_changes (entity, NULL);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_status_changes(entity, NULL)");
status1 = dds_get_status_changes (0, &s1);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_get_status_changes(NULL, status)");
status1 = dds_get_status_changes (entity, &s1);
cr_assert_status_eq(status1, DDS_RETCODE_OK, "dds_get_status_changes(entity, status)");
/* Status read and take shouldn't work either. */
status1 = dds_read_status (0, &s1, 0);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_read_status(NULL, status, 0)");
status1 = dds_read_status (entity, &s1, 0);
cr_assert_status_eq(status1, DDS_RETCODE_OK, "dds_read_status(entity, status, 0)");
status1 = dds_take_status (0, &s1, 0);
cr_assert_status_eq(status1, DDS_RETCODE_BAD_PARAMETER, "dds_take_status(NULL, status, 0)");
status1 = dds_take_status (entity, &s1, 0);
cr_assert_status_eq(status1, DDS_RETCODE_OK, "dds_take_status(entity, status, 0)");
}
Test(ddsc_entity, instance_handle, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
dds_instance_handle_t hdl;
/* Don't check actual handle contents. That's a job
* for the specific entity children, not for the generic part. */
/* Check getting Handle with bad parameters. */
status = dds_get_instance_handle (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_instancehandle_get(NULL, NULL)");
status = dds_get_instance_handle (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_instancehandle_get(entity, NULL)");
status = dds_get_instance_handle (0, &hdl);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_instancehandle_get(NULL, handle)");
/* Get Instance Handle, which should not be 0 for a participant. */
status = dds_get_instance_handle (entity, &hdl);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_instancehandle_get(entity, handle)");
cr_assert_neq(hdl, 0, "Entity instance handle is 0");
}
Test(ddsc_entity, get_entities, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
dds_entity_t par;
dds_entity_t child;
/* ---------- Get Parent ------------ */
/* Check getting Parent with bad parameters. */
par = dds_get_parent (0);
cr_assert_eq(dds_err_nr(par), DDS_RETCODE_BAD_PARAMETER, "Parent was returned (despite of bad parameter)");
/* Get Parent, a participant doesn't have a parent. */
par = dds_get_parent (entity);
cr_assert_eq(dds_err_nr(par), DDS_ENTITY_NIL, "Parent was returned (despite of it being a participant)");
/* ---------- Get Participant ------------ */
/* Check getting Participant with bad parameters. */
par = dds_get_participant (0);
cr_assert_eq(dds_err_nr(par), DDS_RETCODE_BAD_PARAMETER, "Participant was returned (despite of bad parameter)");
/* Get Participant, a participants' participant is itself. */
par = dds_get_participant (entity);
cr_assert_eq(par, entity, "Returned participant was not expected");
/* ---------- Get Children ------------ */
/* Check getting Children with bad parameters. */
status = dds_get_children (0, &child, 1);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_children(NULL, child, 1)");
status = dds_get_children (entity, NULL, 1);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_children(entity, NULL, 1)");
status = dds_get_children (entity, &child, 0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_children(entity, child, 0)");
status = dds_get_children (0, NULL, 1);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_children(NULL, NULL, 1)");
status = dds_get_children (0, &child, 0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_children(NULL, child, 0)");
/* Get Children, of which there are currently none. */
status = dds_get_children (entity, NULL, 0);
if (status > 0) {
cr_assert("dds_get_children(entity, NULL, 0) un-expectantly found children");
} else {
cr_assert_eq(status, 0, "dds_get_children(entity, NULL, 0) failed");
}
status = dds_get_children (entity, &child, 1);
if (status > 0) {
cr_assert("dds_get_children(entity, child, 1) un-expectantly returned children");
} else {
cr_assert_eq(status, 0, "dds_get_children(entity, child, 1) failed");
}
}
Test(ddsc_entity, get_domainid, .init = create_entity, .fini = delete_entity)
{
dds_return_t status;
dds_domainid_t id;
/* Check getting ID with bad parameters. */
status = dds_get_domainid (0, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_domainid(NULL, NULL)");
status = dds_get_domainid (entity, NULL);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_domainid(entity, NULL)");
status = dds_get_domainid (0, &id);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_get_domainid(NULL, id)");
/* Get and check the domain id. */
status = dds_get_domainid (entity, &id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(entity, id)");
cr_assert_eq(id, 0, "Different domain_id was returned than expected");
}
Test(ddsc_entity, delete, .init = create_entity)
{
dds_return_t status;
status = dds_delete(0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_delete(NULL)");
status = dds_delete(entity);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_delete(entity)");
entity = 0;
}
#pragma warning(pop)

View file

@ -0,0 +1,995 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include "os/os.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/theories.h>
#include "RoundTrip.h"
/* Add --verbose command line argument to get the cr_log_info traces (if there are any). */
/**************************************************************************************************
*
* Test fixtures
*
*************************************************************************************************/
static dds_entity_t g_keep = 0;
static dds_entity_t g_participant = 0;
static dds_entity_t g_topic = 0;
static dds_entity_t g_subscriber = 0;
static dds_entity_t g_publisher = 0;
static dds_entity_t g_reader = 0;
static dds_entity_t g_writer = 0;
static dds_entity_t g_readcond = 0;
static dds_entity_t g_querycond = 0;
/* Dummy query condition callback. */
static bool
accept_all(const void * sample)
{
return true;
}
static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;
}
static void
hierarchy_init(void)
{
uint32_t mask = DDS_ANY_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE;
char name[100];
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_hierarchy_test", name, sizeof name), NULL, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
g_publisher = dds_create_publisher(g_participant, NULL, NULL);
cr_assert_gt(g_publisher, 0, "Failed to create prerequisite g_publisher");
g_subscriber = dds_create_subscriber(g_participant, NULL, NULL);
cr_assert_gt(g_subscriber, 0, "Failed to create prerequisite g_subscriber");
g_writer = dds_create_writer(g_publisher, g_topic, NULL, NULL);
cr_assert_gt(g_writer, 0, "Failed to create prerequisite g_writer");
g_reader = dds_create_reader(g_subscriber, g_topic, NULL, NULL);
cr_assert_gt(g_reader, 0, "Failed to create prerequisite g_reader");
g_readcond = dds_create_readcondition(g_reader, mask);
cr_assert_gt(g_readcond, 0, "Failed to create prerequisite g_readcond");
g_querycond = dds_create_querycondition(g_reader, mask, accept_all);
cr_assert_gt(g_querycond, 0, "Failed to create prerequisite g_querycond");
/* The deletion of the last participant will close down every thing. This
* means that the API will react differently after that. Because the
* testing we're doing here is quite generic, we'd like to not close down
* everything when we delete our participant. For that, we create a second
* participant, which will keep everything running.
*/
g_keep = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_keep, 0, "Failed to create prerequisite g_keep");
}
static void
hierarchy_fini(void)
{
dds_delete(g_querycond);
dds_delete(g_readcond);
dds_delete(g_reader);
dds_delete(g_writer);
dds_delete(g_subscriber);
dds_delete(g_publisher);
dds_delete(g_topic);
dds_delete(g_participant);
dds_delete(g_keep);
}
#if 0
#else
/**************************************************************************************************
*
* These will check the recursive deletion.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_delete, recursive, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_domainid_t id;
dds_return_t ret;
/* First be sure that 'dds_get_domainid' returns ok. */
ret = dds_get_domainid(g_participant, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_topic, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_publisher, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_subscriber, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_writer, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_reader, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_readcond, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
ret = dds_get_domainid(g_querycond, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
/* Deleting the top dog (participant) should delete all children. */
ret = dds_delete(g_participant);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
/* Check if all the entities are deleted now. */
ret = dds_get_domainid(g_participant, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_topic, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_publisher, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_subscriber, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_writer, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_reader, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_readcond, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_querycond, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_delete, recursive_with_deleted_topic)
{
dds_domainid_t id;
dds_return_t ret;
char name[100];
/* Internal handling of topic is different from all the other entities.
* It's very interesting if this recursive deletion still works and
* doesn't crash when the topic is already deleted (CHAM-424). */
/* First, create a topic and a writer with that topic. */
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_hierarchy_test", name, 100), NULL, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
g_writer = dds_create_writer(g_participant, g_topic, NULL, NULL);
cr_assert_gt(g_writer, 0, "Failed to create prerequisite g_writer");
g_keep = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_keep, 0, "Failed to create prerequisite g_keep");
/* Second, delete the topic to make sure that the writer holds the last
* reference to the topic and thus will delete it when it itself is
* deleted. */
ret = dds_delete(g_topic);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
/* Third, deleting the participant should delete all children of which
* the writer with the last topic reference is one. */
ret = dds_delete(g_participant);
/* Before the CHAM-424 fix, we would not get here because of a crash,
* or it (incidentally) continued but returned an error. */
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
/* Check if the entities are actually deleted. */
ret = dds_get_domainid(g_participant, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "%s", dds_err_str(ret));
ret = dds_get_domainid(g_topic, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
ret = dds_get_domainid(g_writer, &id);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
dds_delete(g_keep);
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_participant in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_participant, valid_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *entity), ddsc_entity_get_participant, valid_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t participant;
participant = dds_get_participant(*entity);
cr_assert_eq(participant, g_participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_participant, deleted_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *entity), ddsc_entity_get_participant, deleted_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t participant;
dds_delete(*entity);
participant = dds_get_participant(*entity);
cr_assert_eq(dds_err_nr(participant), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(participant));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_participant, invalid_entities) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_participant, invalid_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t participant;
participant = dds_get_participant(entity);
cr_assert_eq(dds_err_nr(participant), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(participant), dds_err_nr(exp));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_parent in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_parent, conditions) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond),
};
Theory((dds_entity_t *entity), ddsc_entity_get_parent, conditions, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
parent = dds_get_parent(*entity);
cr_assert_eq(parent, g_reader);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_parent, reader, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
parent = dds_get_parent(g_reader);
cr_assert_eq(parent, g_subscriber);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_parent, writer, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
parent = dds_get_parent(g_writer);
cr_assert_eq(parent, g_publisher);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_parent, pubsubtop) = {
DataPoints(dds_entity_t*, &g_publisher, &g_subscriber, &g_topic),
};
Theory((dds_entity_t *entity), ddsc_entity_get_parent, pubsubtop, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
parent = dds_get_parent(*entity);
cr_assert_eq(parent, g_participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_parent, participant, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
parent = dds_get_parent(g_participant);
cr_assert_eq(dds_err_nr(parent), DDS_ENTITY_NIL, "returned %d", dds_err_nr(parent));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_parent, deleted_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *entity), ddsc_entity_get_parent, deleted_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t parent;
dds_delete(*entity);
parent = dds_get_parent(*entity);
cr_assert_eq(dds_err_nr(parent), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_parent, invalid_entities) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_parent, invalid_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t parent;
parent = dds_get_parent(entity);
cr_assert_eq(dds_err_nr(parent), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(parent), dds_err_nr(exp));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_children in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, null, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
ret = dds_get_children(g_participant, NULL, 0);
cr_assert_eq(ret, 3);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, invalid_size, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t child;
ret = dds_get_children(g_participant, &child, INT32_MAX);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, too_small, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t children[2];
ret = dds_get_children(g_participant, children, 2);
cr_assert_eq(ret, 3);
cr_assert((children[0] == g_publisher) || (children[0] == g_subscriber) || (children[0] == g_topic));
cr_assert((children[1] == g_publisher) || (children[1] == g_subscriber) || (children[1] == g_topic));
cr_assert_neq(children[0], children[1]);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, participant, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t children[4];
ret = dds_get_children(g_participant, children, 4);
cr_assert_eq(ret, 3);
cr_assert((children[0] == g_publisher) || (children[0] == g_subscriber) || (children[0] == g_topic));
cr_assert((children[1] == g_publisher) || (children[1] == g_subscriber) || (children[1] == g_topic));
cr_assert((children[2] == g_publisher) || (children[2] == g_subscriber) || (children[2] == g_topic));
cr_assert_neq(children[0], children[1]);
cr_assert_neq(children[0], children[2]);
cr_assert_neq(children[1], children[2]);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, topic, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t child;
ret = dds_get_children(g_topic, &child, 1);
cr_assert_eq(ret, 0);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, publisher, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t child;
ret = dds_get_children(g_publisher, &child, 1);
cr_assert_eq(ret, 1);
cr_assert_eq(child, g_writer);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, subscriber, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t children[2];
ret = dds_get_children(g_subscriber, children, 2);
cr_assert_eq(ret, 1);
cr_assert_eq(children[0], g_reader);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, writer, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
ret = dds_get_children(g_writer, NULL, 0);
cr_assert_eq(ret, 0);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, reader, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t children[2];
ret = dds_get_children(g_reader, children, 2);
cr_assert_eq(ret, 2);
cr_assert((children[0] == g_readcond) || (children[0] == g_querycond));
cr_assert((children[1] == g_readcond) || (children[1] == g_querycond));
cr_assert_neq(children[0], children[1]);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_children, conditions) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond),
};
Theory((dds_entity_t *entity), ddsc_entity_get_children, conditions, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t child;
ret = dds_get_children(*entity, &child, 1);
cr_assert_eq(ret, 0);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_children, deleted_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *entity), ddsc_entity_get_children, deleted_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_return_t ret;
dds_entity_t children[4];
dds_delete(*entity);
ret = dds_get_children(*entity, children, 4);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_children, invalid_entities) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_children, invalid_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t children[4];
dds_return_t ret;
ret = dds_get_children(entity, children, 4);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_topic in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_topic, data_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_writer),
};
Theory((dds_entity_t *entity), ddsc_entity_get_topic, data_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t topic;
topic = dds_get_topic(*entity);
cr_assert_eq(topic, g_topic );
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_topic, deleted_entities) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader, &g_writer),
};
Theory((dds_entity_t *entity), ddsc_entity_get_topic, deleted_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t topic;
dds_delete(*entity);
topic = dds_get_topic(*entity);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_topic, invalid_entities) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_topic, invalid_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t topic;
topic = dds_get_topic(entity);
cr_assert_eq(dds_err_nr(topic), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(topic), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_topic, non_data_entities) = {
DataPoints(dds_entity_t*, &g_subscriber, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *entity), ddsc_entity_get_topic, non_data_entities, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t topic;
topic = dds_get_topic(*entity);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(topic));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_publisher in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_publisher, writer, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t publisher;
publisher = dds_get_publisher(g_writer);
cr_assert_eq(publisher, g_publisher);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_publisher, deleted_writer, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t publisher;
dds_delete(g_writer);
publisher = dds_get_publisher(g_writer);
cr_assert_eq(dds_err_nr(publisher), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_publisher, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_publisher, invalid_writers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t publisher;
publisher = dds_get_publisher(entity);
cr_assert_eq(dds_err_nr(publisher), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(publisher), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_publisher, non_writers) = {
DataPoints(dds_entity_t*, &g_publisher, &g_reader, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *cond), ddsc_entity_get_publisher, non_writers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t publisher;
publisher = dds_get_publisher(*cond);
cr_assert_eq(dds_err_nr(publisher), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(publisher));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_subscriber in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_subscriber, readers) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader),
};
Theory((dds_entity_t *entity), ddsc_entity_get_subscriber, readers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t subscriber;
subscriber = dds_get_subscriber(*entity);
cr_assert_eq(subscriber, g_subscriber);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_subscriber, deleted_readers) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond, &g_reader),
};
Theory((dds_entity_t *entity), ddsc_entity_get_subscriber, deleted_readers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t subscriber;
dds_delete(*entity);
subscriber = dds_get_subscriber(*entity);
cr_assert_eq(dds_err_nr(subscriber), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_subscriber, invalid_readers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t entity), ddsc_entity_get_subscriber, invalid_readers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t subscriber;
subscriber = dds_get_subscriber(entity);
cr_assert_eq(dds_err_nr(subscriber), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(subscriber), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_subscriber, non_readers) = {
DataPoints(dds_entity_t*, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *cond), ddsc_entity_get_subscriber, non_readers, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t subscriber;
subscriber = dds_get_subscriber(*cond);
cr_assert_eq(dds_err_nr(subscriber), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(subscriber));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_get_datareader in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_datareader, conditions) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond),
};
Theory((dds_entity_t *cond), ddsc_entity_get_datareader, conditions, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t reader;
reader = dds_get_datareader(*cond);
cr_assert_eq(reader, g_reader);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_datareader, deleted_conds) = {
DataPoints(dds_entity_t*, &g_readcond, &g_querycond),
};
Theory((dds_entity_t *cond), ddsc_entity_get_datareader, deleted_conds, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t reader;
dds_delete(*cond);
reader = dds_get_datareader(*cond);
cr_assert_eq(dds_err_nr(reader), DDS_RETCODE_ALREADY_DELETED);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_datareader, invalid_conds) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t cond), ddsc_entity_get_datareader, invalid_conds, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_entity_t reader;
reader = dds_get_datareader(cond);
cr_assert_eq(dds_err_nr(reader), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(reader), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_entity_get_datareader, non_conds) = {
DataPoints(dds_entity_t*, &g_reader, &g_subscriber, &g_writer, &g_publisher, &g_topic, &g_participant),
};
Theory((dds_entity_t *cond), ddsc_entity_get_datareader, non_conds, .init=hierarchy_init, .fini=hierarchy_fini)
{
dds_entity_t reader;
reader = dds_get_datareader(*cond);
cr_assert_eq(dds_err_nr(reader), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(reader));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_implicit_publisher, deleted)
{
dds_entity_t participant;
dds_entity_t writer;
dds_entity_t topic;
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_publisher_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
ret = dds_get_children(participant, NULL, 0);
cr_assert_eq(ret, 2);
dds_delete(writer);
ret = dds_get_children(participant, NULL, 0);
cr_assert_eq(ret, 1);
dds_delete(topic);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_implicit_publisher, invalid_topic)
{
dds_entity_t participant;
dds_entity_t writer;
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
/* Disable SAL warning on intentional misuse of the API */
OS_WARNING_MSVC_OFF(28020);
writer = dds_create_writer(participant, 0, NULL, NULL);
/* Disable SAL warning on intentional misuse of the API */
OS_WARNING_MSVC_ON(28020);
cr_assert_lt(writer, 0);
dds_delete(writer);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_implicit_subscriber, deleted)
{
dds_entity_t participant;
dds_entity_t reader;
dds_entity_t topic;
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_subscriber_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
reader = dds_create_reader(participant, topic, NULL, NULL);
cr_assert_gt(reader, 0);
ret = dds_get_children(participant, NULL, 0);
cr_assert_eq(ret, 2);
dds_delete(reader);
ret = dds_get_children(participant, NULL, 0);
cr_assert_eq(ret, 1);
dds_delete(topic);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_explicit_subscriber, invalid_topic)
{
dds_entity_t participant;
dds_entity_t reader;
dds_entity_t subscriber;
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
subscriber = dds_create_subscriber(participant, NULL,NULL);
/* Disable SAL warning on intentional misuse of the API */
OS_WARNING_MSVC_OFF(28020);
reader = dds_create_reader(subscriber, 0, NULL, NULL);
OS_WARNING_MSVC_ON(28020);
cr_assert_lt(reader, 0);
dds_delete(reader);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, implicit_publisher)
{
dds_entity_t participant;
dds_entity_t publisher;
dds_entity_t writer;
dds_entity_t topic;
dds_entity_t child[2], child2[2];
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_publisher_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
ret = dds_get_children(participant, child, 2);
cr_assert_eq(ret, 2);
if(child[0] == topic){
publisher = child[1];
} else if(child[1] == topic){
publisher = child[0];
} else{
cr_assert(false, "topic was not returned");
}
cr_assert_neq(publisher, topic);
cr_assert_gt(publisher, 0);
cr_assert_neq(publisher, writer);
dds_delete(writer);
ret = dds_get_children(participant, child2, 2);
cr_assert_eq(ret, 2);
cr_assert( (child2[0] == child[0]) || (child2[0] == child[1]) );
cr_assert( (child2[1] == child[0]) || (child2[1] == child[1]) );
dds_delete(topic);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_children, implicit_subscriber)
{
dds_entity_t participant;
dds_entity_t subscriber;
dds_entity_t reader;
dds_entity_t topic;
dds_entity_t child[2], child2[2];
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_subscriber_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
reader = dds_create_reader(participant, topic, NULL, NULL);
cr_assert_gt(reader, 0);
ret = dds_get_children(participant, child, 2);
cr_assert_eq(ret, 2);
if(child[0] == topic){
subscriber = child[1];
} else if(child[1] == topic){
subscriber = child[0];
} else{
cr_assert(false, "topic was not returned");
}
cr_assert_neq(subscriber, topic);
cr_assert_gt(subscriber, 0);
cr_assert_neq(subscriber, reader);
dds_delete(reader);
ret = dds_get_children(participant, child2, 2);
cr_assert_eq(ret, 2);
cr_assert( (child2[0] == child[0]) || (child2[0] == child[1]) );
cr_assert( (child2[1] == child[0]) || (child2[1] == child[1]) );
dds_delete(topic);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_parent, implicit_publisher)
{
dds_entity_t participant;
dds_entity_t writer;
dds_entity_t parent;
dds_entity_t topic;
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_publisher_promotion_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
parent = dds_get_parent(writer);
cr_assert_neq(parent, participant);
cr_assert_gt(parent, 0);
dds_delete(writer);
ret = dds_delete(parent);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_entity_get_parent, implicit_subscriber)
{
dds_entity_t participant;
dds_entity_t reader;
dds_entity_t parent;
dds_entity_t topic;
dds_return_t ret;
char name[100];
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, create_topic_name("ddsc_entity_implicit_subscriber_promotion_test", name, 100), NULL, NULL);
cr_assert_gt(topic, 0);
reader = dds_create_reader(participant, topic, NULL, NULL);
cr_assert_gt(reader, 0);
parent = dds_get_parent(reader);
cr_assert_neq(parent, participant);
cr_assert_gt(parent, 0);
dds_delete(reader);
ret = dds_delete(parent);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_OK);
dds_delete(participant);
}
/*************************************************************************************************/
/*************************************************************************************************/
#endif

File diff suppressed because it is too large Load diff

33
src/core/ddsc/tests/err.c Normal file
View file

@ -0,0 +1,33 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
Test(ddsc_err, str)
{
cr_assert_str_eq(dds_err_str(1 ), "Success");
cr_assert_str_eq(dds_err_str(-255 ), "Unknown");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_OK * -1), "Success");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_ERROR * -1), "Error");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_UNSUPPORTED * -1), "Unsupported");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_BAD_PARAMETER * -1), "Bad Parameter");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_PRECONDITION_NOT_MET * -1), "Precondition Not Met");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_OUT_OF_RESOURCES * -1), "Out Of Resources");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_NOT_ENABLED * -1), "Not Enabled");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_IMMUTABLE_POLICY * -1), "Immutable Policy");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_INCONSISTENT_POLICY * -1), "Inconsistent Policy");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_ALREADY_DELETED * -1), "Already Deleted");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_TIMEOUT * -1), "Timeout");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_NO_DATA * -1), "No Data");
cr_assert_str_eq(dds_err_str(DDS_RETCODE_ILLEGAL_OPERATION * -1), "Illegal Operation");
}

View file

@ -0,0 +1,39 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include "os/os.h"
Test(ddsc_err, unique_file_id)
{
dds_entity_t participant, reader, writer;
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
/* Disable SAL warning on intentional misuse of the API */
OS_WARNING_MSVC_OFF(28020);
reader = dds_create_reader(0, 0, NULL, NULL);
cr_assert_lt(reader, 0);
writer = dds_create_writer(0, 0, NULL, NULL);
cr_assert_lt(writer, 0);
OS_WARNING_MSVC_ON(28020);
cr_log_info("file_id for dds_create_reader: %d", dds_err_file_id(reader));
cr_log_info("file_id for dds_create_writer: %d", dds_err_file_id(writer));
cr_assert_neq(dds_err_file_id(reader), dds_err_file_id(writer));
dds_delete(participant);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,332 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <os/os.h>
#include "config_env.h"
#include "ddsc/ddsc_project.h"
#define cr_assert_status_eq(s1, s2, ...) cr_assert_eq(dds_err_nr(s1), s2, __VA_ARGS__)
Test(ddsc_participant, create_and_delete) {
dds_entity_t participant, participant2, participant3;
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
participant2 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant2, 0, "dds_participant_create");
dds_delete (participant);
dds_delete (participant2);
participant3 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant3, 0, "dds_participant_create");
dds_delete (participant3);
}
/* Test for creating participant with no configuration file */
Test(ddsc_participant, create_with_no_conf_no_env) {
dds_entity_t participant, participant2, participant3;
dds_return_t status;
dds_domainid_t domain_id;
dds_domainid_t valid_domain=0;
const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");
cr_assert_eq(env_uri, NULL, DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI must be NULL");
//invalid domain
participant = dds_create_participant (1, NULL, NULL);
cr_assert_lt(participant, 0, "Error must be received for invalid domain value");
//valid specific domain value
participant2 = dds_create_participant (valid_domain, NULL, NULL);
cr_assert_gt(participant2, 0, "Valid participant must be received for valid specific domain value");
status = dds_get_domainid(participant2, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
cr_assert_eq(domain_id, valid_domain, "Retrieved domain ID must be valid");
//DDS_DOMAIN_DEFAULT from user
participant3 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant3, 0, "Valid participant must be received for DDS_DOMAIN_DEFAULT");
status = dds_get_domainid(participant3, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
cr_assert_eq(domain_id, valid_domain, "Retrieved domain ID must be valid");
dds_delete(participant2);
dds_delete(participant3);
}
////WITH CONF
/* Test for creating participant with valid configuration file */
Test(ddsc_participant, create_with_conf_no_env) {
dds_entity_t participant, participant2, participant3;
dds_return_t status;
dds_domainid_t domain_id;
dds_domainid_t valid_domain=3;
static char env_uri_str[1000];
(void) sprintf(env_uri_str, "%s=%s", DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI", CONFIG_ENV_SIMPLE_UDP);
os_putenv(env_uri_str);
static char env_mp_str[100];
(void) sprintf(env_mp_str, "%s=%s", "MAX_PARTICIPANTS", CONFIG_ENV_MAX_PARTICIPANTS);
os_putenv(env_mp_str);
const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");
cr_assert_neq(env_uri, NULL, DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI must be set");
//invalid domain
participant = dds_create_participant (1, NULL, NULL);
cr_assert_lt(participant, 0, "Error must be received for invalid domain value");
//valid specific domain value
participant2 = dds_create_participant (valid_domain, NULL, NULL);
cr_assert_gt(participant2, 0, "Valid participant must be received for valid specific domain value");
status = dds_get_domainid(participant2, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
cr_assert_eq(domain_id, valid_domain, "Retrieved domain ID must be valid");
//DDS_DOMAIN_DEFAULT from the user
participant3 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant3, 0, "Valid participant must be received for DDS_DOMAIN_DEFAULT");
status = dds_get_domainid(participant3, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
cr_assert_eq(domain_id, valid_domain, "Retrieved domain ID must be valid");
dds_delete(participant2);
dds_delete(participant3);
}
Test(ddsc_participant_lookup, one) {
dds_entity_t participant;
dds_entity_t participants[3];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 3;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 1, "dds_lookup_participant(domain_id, participants, size)");
cr_assert_eq(participants[0], participant,"dds_lookup_participant did not return the participant");
dds_delete (participant);
}
Test(ddsc_participant_lookup, multiple) {
dds_entity_t participant, participant2;
dds_entity_t participants[2];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 2;
/* Create participants */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
participant2 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant2, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 2, "dds_lookup_participant(domain_id, participants, size)");
cr_assert(participants[0] == participant || participants[0] == participant2,"ddsc_participant_lookup");
cr_assert(participants[1] == participant || participants[1] == participant2,"ddsc_participant_lookup");
cr_assert_neq(participants[0], participants[1], "dds_lookup_participant returned a participant twice");
dds_delete (participant2);
dds_delete (participant);
}
Test(ddsc_participant_lookup, array_too_small) {
dds_entity_t participant, participant2, participant3;
dds_entity_t participants[2];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 2;
/* Create participants */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
participant2 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant2, 0, "dds_participant_create");
participant3 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant3, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 3, "dds_lookup_participant(domain_id, participants, size)");
cr_assert(participants[0] == participant || participants[0] == participant2 || participants[0] == participant3,"ddsc_participant_lookup");
cr_assert(participants[1] == participant || participants[1] == participant2 || participants[1] == participant3,"ddsc_participant_lookup");
cr_assert_neq(participants[0], participants[1], "dds_lookup_participant returned a participant twice");
dds_delete (participant3);
dds_delete (participant2);
dds_delete (participant);
}
Test(ddsc_participant_lookup, null_zero){
dds_entity_t participant;
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 0;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
num_of_found_pp = dds_lookup_participant( domain_id, NULL, size);
cr_assert_eq(num_of_found_pp, 1, "dds_lookup_participant(domain_id, participants, size)");
dds_delete (participant);
}
Test(ddsc_participant_lookup, null_nonzero){
dds_entity_t participant;
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 2;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
num_of_found_pp = dds_lookup_participant( domain_id, NULL, size);
cr_assert_status_eq(num_of_found_pp, DDS_RETCODE_BAD_PARAMETER, "dds_lookup_participant did not return bad parameter");
dds_delete (participant);
}
Test(ddsc_participant_lookup, unknown_id) {
dds_entity_t participant;
dds_entity_t participants[3];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 3;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
domain_id ++;
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 0, "dds_lookup_participant(domain_id, participants, size)");
dds_delete (participant);
}
Test(ddsc_participant_lookup, none) {
dds_entity_t participants[2];
dds_return_t num_of_found_pp;
size_t size = 2;
num_of_found_pp = dds_lookup_participant( 0, participants, size);
cr_assert_eq(num_of_found_pp, 0, "dds_lookup_participant did not return 0");
}
Test(ddsc_participant_lookup, no_more) {
dds_entity_t participant;
dds_entity_t participants[3];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 3;
/* Create a participant */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
dds_delete (participant);
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 0, "dds_lookup_participant did not return 0");
}
Test(ddsc_participant_lookup, deleted) {
dds_entity_t participant, participant2;
dds_entity_t participants[2];
dds_domainid_t domain_id;
dds_return_t status, num_of_found_pp;
size_t size = 2;
/* Create participants */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_participant_create");
participant2 = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant2, 0, "dds_participant_create");
/* Get domain id */
status = dds_get_domainid(participant, &domain_id);
cr_assert_status_eq(status, DDS_RETCODE_OK, "dds_get_domainid(participant, domain_id)");
dds_delete (participant2);
num_of_found_pp = dds_lookup_participant( domain_id, participants, size);
cr_assert_eq(num_of_found_pp, 1, "dds_lookup_participant did not return one participant");
cr_assert(participants[0] == participant,"ddsc_participant_lookup");
dds_delete (participant);
}

View file

@ -0,0 +1,268 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
/* We are deliberately testing some bad arguments that SAL will complain about.
* So, silence SAL regarding these issues. */
#pragma warning(push)
#pragma warning(disable: 28020)
#define cr_assert_status_eq(s1, s2, ...) cr_assert_eq(dds_err_nr(s1), s2, __VA_ARGS__)
/* Dummy callback */
static void data_available_cb(dds_entity_t reader, void* arg) {}
Test(ddsc_publisher, create)
{
const char *singlePartitions[] = { "partition" };
const char *multiplePartitions[] = { "partition1", "partition2" };
const char *duplicatePartitions[] = { "partition", "partition" };
dds_entity_t participant;
dds_entity_t publisher, publisher1;
dds_listener_t *listener;
dds_qos_t *qos;
/* Use NULL participant */
publisher = dds_create_publisher(0, NULL, NULL);
cr_assert_eq(dds_err_nr(publisher), DDS_RETCODE_BAD_PARAMETER, "dds_create_publisher(NULL,NULL,NULL)");
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_create_participant(DDS_DOMAIN_DEFAULT,NULL,NULL)");
/* Use non-null participant */
publisher = dds_create_publisher(participant, NULL, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,NULL)");
/* Use entity that is not a participant */
publisher1 = dds_create_publisher(publisher, NULL, NULL);
cr_assert_eq(dds_err_nr(publisher1), DDS_RETCODE_ILLEGAL_OPERATION, "dds_create_publisher(publisher,NULL,NULL)");
dds_delete(publisher);
/* Create a non-null qos */
qos = dds_qos_create();
cr_assert_neq(qos, NULL, "dds_qos_create()");
/* Use qos without partition; in that case the default partition should be used */
publisher = dds_create_publisher(participant, qos, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,qos,NULL) where qos with default partition");
dds_delete(publisher);
/* Somehow, the compiler thinks the char arrays might not be zero-terminated... */
#pragma warning(push)
#pragma warning(disable: 6054)
/* Use qos with single partition */
dds_qset_partition (qos, 1, singlePartitions);
publisher = dds_create_publisher(participant, qos, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,qos,NULL) where qos with single partition");
dds_delete(publisher);
/* Use qos with multiple partitions */
dds_qset_partition (qos, 2, multiplePartitions);
publisher = dds_create_publisher(participant, qos, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,qos,NULL) where qos with multiple partitions");
dds_delete(publisher);
/* Use qos with multiple partitions */
dds_qset_partition (qos, 2, duplicatePartitions);
publisher = dds_create_publisher(participant, qos, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,qos,NULL) where qos with duplicate partitions");
dds_delete(publisher);
#pragma warning(pop)
/* Use listener(NULL) */
listener = dds_listener_create(NULL);
cr_assert_neq(listener, NULL, "dds_listener_create(NULL)");
publisher = dds_create_publisher(participant, NULL, listener);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,listener(NULL))");
dds_delete(publisher);
dds_listener_reset(listener);
/* Use listener for data_available */
dds_lset_data_available(listener, NULL);
publisher = dds_create_publisher(participant, NULL, listener);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,listener) with dds_lset_data_available(listener, NULL)");
dds_delete(publisher);
dds_listener_reset(listener);
/* Use DDS_LUNSET for data_available */
dds_lset_data_available(listener, DDS_LUNSET);
publisher = dds_create_publisher(participant, NULL, listener);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,listener) with dds_lset_data_available(listener, DDS_LUNSET)");
dds_delete(publisher);
dds_listener_reset(listener);
/* Use callback for data_available */
dds_lset_data_available(listener, data_available_cb);
publisher = dds_create_publisher(participant, NULL, listener);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,listener) with dds_lset_data_available(listener, data_available_cb)");
dds_delete(publisher);
/* Use both qos setting and callback listener */
dds_lset_data_available(listener, data_available_cb);
publisher = dds_create_publisher(participant, qos, listener);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,qos,listener) with dds_lset_data_available(listener, data_available_cb)");
dds_delete(publisher);
dds_listener_delete(listener);
dds_qos_delete(qos);
dds_delete (participant);
}
Test(ddsc_publisher, suspend_resume)
{
dds_entity_t participant, publisher;
dds_return_t status;
/* Suspend a 0 publisher */
status = dds_suspend(0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_suspend(NULL)");
/* Resume a 0 publisher */
status = dds_resume(0);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_resume(NULL)");
/* Uae dds_suspend on something else than a publisher */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_create_participant(DDS_DOMAIN_DEFAULT,NULL,NULL)");
status = dds_suspend(participant);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_suspend(participant)");
/* Use dds_resume on something else than a publisher */
status = dds_resume(participant);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_resume(participant)");
/* Use dds_resume without calling dds_suspend */
publisher = dds_create_publisher(participant, NULL, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,NULL)");
status = dds_resume(publisher); /* Should be precondition not met? */
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_resume(publisher) without prior suspend");
/* Use dds_suspend on non-null publisher */
status = dds_suspend(publisher);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_suspend(publisher)");
/* Use dds_resume on non-null publisher */
status = dds_resume(publisher);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_resume(publisher)");
dds_delete(publisher);
dds_delete(participant);
return;
}
Test(ddsc_publisher, wait_for_acks)
{
dds_entity_t participant, publisher;
dds_return_t status;
dds_duration_t zeroSec = ((dds_duration_t)DDS_SECS(0));
dds_duration_t oneSec = ((dds_duration_t)DDS_SECS(1));
dds_duration_t minusOneSec = ((dds_duration_t)DDS_SECS(-1));
/* Wait_for_acks on 0 publisher or writer and minusOneSec timeout */
status = dds_wait_for_acks(0, minusOneSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(NULL,-1)");
/* Wait_for_acks on NULL publisher or writer and zeroSec timeout */
status = dds_wait_for_acks(0, zeroSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(NULL,0)");
/* wait_for_acks on NULL publisher or writer and oneSec timeout */
status = dds_wait_for_acks(0, oneSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(NULL,1)");
/* wait_for_acks on NULL publisher or writer and DDS_INFINITE timeout */
status = dds_wait_for_acks(0, DDS_INFINITY);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(NULL,DDS_INFINITY)");
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "dds_create_participant(DDS_DOMAIN_DEFAULT,NULL,NULL)");
/* Wait_for_acks on participant and minusOneSec timeout */
status = dds_wait_for_acks(participant, minusOneSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(participant,-1)");
/* Wait_for_acks on participant and zeroSec timeout */
status = dds_wait_for_acks(participant, zeroSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(participant,0)");
/* Wait_for_acks on participant and oneSec timeout */
status = dds_wait_for_acks(participant, oneSec);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(participant,1)");
/* Wait_for_acks on participant and DDS_INFINITE timeout */
status = dds_wait_for_acks(participant, DDS_INFINITY);
cr_assert_status_eq(status, DDS_RETCODE_BAD_PARAMETER, "dds_wait_for_acks(participant,DDS_INFINITY)");
publisher = dds_create_publisher(participant, NULL, NULL);
cr_assert_gt(publisher, 0, "dds_create_publisher(participant,NULL,NULL)");
/* Wait_for_acks on publisher and minusOneSec timeout */
status = dds_wait_for_acks(publisher, minusOneSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(publisher,-1)");
/* Wait_for_acks on publisher and zeroSec timeout */
status = dds_wait_for_acks(publisher, zeroSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(publisher,0)");
/* Wait_for_acks on publisher and oneSec timeout */
status = dds_wait_for_acks(publisher, oneSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(publisher,1)");
/* Wait_for_acks on publisher and DDS_INFINITE timeout */
status = dds_wait_for_acks(publisher, DDS_INFINITY);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(publisher,DDS_INFINITY)");
/* TODO: create tests by calling dds_qwait_for_acks on writers */
status = dds_suspend(publisher);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_suspend(publisher)");
/* Wait_for_acks on suspended publisher and minusOneSec timeout */
status = dds_wait_for_acks(publisher, minusOneSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(suspended_publisher,-1)");
/* Wait_for_acks on suspended publisher and zeroSec timeout */
status = dds_wait_for_acks(publisher, zeroSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(suspended_publisher,0)");
/* Wait_for_acks on suspended publisher and oneSec timeout */
status = dds_wait_for_acks(publisher, oneSec);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(suspended_publisher,1)");
/* Wait_for_acks on suspended publisher and DDS_INFINITE timeout */
status = dds_wait_for_acks(publisher, DDS_INFINITY);
cr_assert_status_eq(status, DDS_RETCODE_UNSUPPORTED, "dds_wait_for_acks(suspended_publisher,DDS_INFINITY)");
dds_delete(publisher);
dds_delete(participant);
return;
}
Test(ddsc_publisher, coherency)
{
return;
}
#pragma warning(pop)

621
src/core/ddsc/tests/qos.c Normal file
View file

@ -0,0 +1,621 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include "os/os.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#if 0
#else
/* We are deliberately testing some bad arguments that SAL will complain about.
* So, silence SAL regarding these issues. */
#pragma warning(push)
#pragma warning(disable: 6387 28020)
/****************************************************************************
* Convenience global policies
****************************************************************************/
struct pol_userdata {
void *value;
size_t sz;
};
struct pol_topicdata {
void *value;
size_t sz;
};
struct pol_groupdata {
void *value;
size_t sz;
};
struct pol_durability {
dds_durability_kind_t kind;
};
struct pol_history {
dds_history_kind_t kind;
int32_t depth;
};
struct pol_resource_limits {
int32_t max_samples;
int32_t max_instances;
int32_t max_samples_per_instance;
};
struct pol_presentation {
dds_presentation_access_scope_kind_t access_scope;
bool coherent_access;
bool ordered_access;
};
struct pol_lifespan {
dds_duration_t lifespan;
};
struct pol_deadline {
dds_duration_t deadline;
};
struct pol_latency_budget {
dds_duration_t duration;
};
struct pol_ownership {
dds_ownership_kind_t kind;
};
struct pol_ownership_strength {
int32_t value;
};
struct pol_liveliness {
dds_liveliness_kind_t kind;
dds_duration_t lease_duration;
};
struct pol_time_based_filter {
dds_duration_t minimum_separation;
};
struct pol_partition {
uint32_t n;
char **ps;
};
struct pol_reliability {
dds_reliability_kind_t kind;
dds_duration_t max_blocking_time;
};
struct pol_transport_priority {
int32_t value;
};
struct pol_destination_order {
dds_destination_order_kind_t kind;
};
struct pol_writer_data_lifecycle {
bool autodispose;
};
struct pol_reader_data_lifecycle {
dds_duration_t autopurge_nowriter_samples_delay;
dds_duration_t autopurge_disposed_samples_delay;
};
struct pol_durability_service {
dds_duration_t service_cleanup_delay;
dds_history_kind_t history_kind;
int32_t history_depth;
int32_t max_samples;
int32_t max_instances;
int32_t max_samples_per_instance;
};
static struct pol_userdata g_pol_userdata;
static struct pol_topicdata g_pol_topicdata;
static struct pol_groupdata g_pol_groupdata;
static struct pol_durability g_pol_durability;
static struct pol_history g_pol_history;
static struct pol_resource_limits g_pol_resource_limits;
static struct pol_presentation g_pol_presentation;
static struct pol_lifespan g_pol_lifespan;
static struct pol_deadline g_pol_deadline;
static struct pol_latency_budget g_pol_latency_budget;
static struct pol_ownership g_pol_ownership;
static struct pol_ownership_strength g_pol_ownership_strength;
static struct pol_liveliness g_pol_liveliness;
static struct pol_time_based_filter g_pol_time_based_filter;
static struct pol_partition g_pol_partition;
static struct pol_reliability g_pol_reliability;
static struct pol_transport_priority g_pol_transport_priority;
static struct pol_destination_order g_pol_destination_order;
static struct pol_writer_data_lifecycle g_pol_writer_data_lifecycle;
static struct pol_reader_data_lifecycle g_pol_reader_data_lifecycle;
static struct pol_durability_service g_pol_durability_service;
static const char* c_userdata = "user_key";
static const char* c_topicdata = "topic_key";
static const char* c_groupdata = "group_key";
static const char* c_partitions[] = {"Partition1", "Partition2"};
/****************************************************************************
* Test initializations and teardowns.
****************************************************************************/
static dds_qos_t *g_qos = NULL;
static void
qos_init(void)
{
g_qos = dds_qos_create();
cr_assert_not_null(g_qos);
g_pol_userdata.value = (void*)c_userdata;
g_pol_userdata.sz = strlen((char*)g_pol_userdata.value) + 1;
g_pol_topicdata.value = (void*)c_topicdata;
g_pol_topicdata.sz = strlen((char*)g_pol_topicdata.value) + 1;
g_pol_groupdata.value = (void*)c_groupdata;
g_pol_groupdata.sz = strlen((char*)g_pol_groupdata.value) + 1;
g_pol_durability.kind = DDS_DURABILITY_TRANSIENT;
g_pol_history.kind = DDS_HISTORY_KEEP_LAST;
g_pol_history.depth = 1;
g_pol_resource_limits.max_samples = 1;
g_pol_resource_limits.max_instances = 1;
g_pol_resource_limits.max_samples_per_instance = 1;
g_pol_presentation.access_scope = DDS_PRESENTATION_INSTANCE;
g_pol_presentation.coherent_access = true;
g_pol_presentation.ordered_access = true;
g_pol_lifespan.lifespan = 10000;
g_pol_deadline.deadline = 20000;
g_pol_latency_budget.duration = 30000;
g_pol_ownership.kind = DDS_OWNERSHIP_EXCLUSIVE;
g_pol_ownership_strength.value = 10;
g_pol_liveliness.kind = DDS_LIVELINESS_AUTOMATIC;
g_pol_liveliness.lease_duration = 40000;
g_pol_time_based_filter.minimum_separation = 50000;
g_pol_partition.ps = (char**)c_partitions;
g_pol_partition.n = 2;
g_pol_reliability.kind = DDS_RELIABILITY_RELIABLE;
g_pol_reliability.max_blocking_time = 60000;
g_pol_transport_priority.value = 42;
g_pol_destination_order.kind = DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP;
g_pol_writer_data_lifecycle.autodispose = true;
g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay = 70000;
g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay = 80000;
g_pol_durability_service.history_depth = 1;
g_pol_durability_service.history_kind = DDS_HISTORY_KEEP_LAST;
g_pol_durability_service.max_samples = 2;
g_pol_durability_service.max_instances = 3;
g_pol_durability_service.max_samples_per_instance = 4;
g_pol_durability_service.service_cleanup_delay = 90000;
}
static void
qos_fini(void)
{
dds_qos_delete(g_qos);
}
/****************************************************************************
* API tests
****************************************************************************/
Test(ddsc_qos, userdata, .init=qos_init, .fini=qos_fini)
{
struct pol_userdata p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_userdata(NULL, g_pol_userdata.value, g_pol_userdata.sz);
dds_qget_userdata(NULL, &p.value, &p.sz);
dds_qget_userdata(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_userdata(g_qos, g_pol_userdata.value, g_pol_userdata.sz);
dds_qget_userdata(g_qos, &p.value, &p.sz);
cr_assert_eq(p.sz, g_pol_userdata.sz);
cr_assert_str_eq(p.value, g_pol_userdata.value);
dds_free(p.value);
}
Test(ddsc_qos, topicdata, .init=qos_init, .fini=qos_fini)
{
struct pol_topicdata p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_topicdata(NULL, g_pol_topicdata.value, g_pol_topicdata.sz);
dds_qget_topicdata(NULL, &p.value, &p.sz);
dds_qget_topicdata(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_topicdata(g_qos, g_pol_topicdata.value, g_pol_topicdata.sz);
dds_qget_topicdata(g_qos, &p.value, &p.sz);
cr_assert_eq(p.sz, g_pol_topicdata.sz);
cr_assert_str_eq(p.value, g_pol_topicdata.value);
dds_free(p.value);
}
Test(ddsc_qos, groupdata, .init=qos_init, .fini=qos_fini)
{
struct pol_groupdata p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_groupdata(NULL, g_pol_groupdata.value, g_pol_groupdata.sz);
dds_qget_groupdata(NULL, &p.value, &p.sz);
dds_qget_groupdata(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_groupdata(g_qos, g_pol_groupdata.value, g_pol_groupdata.sz);
dds_qget_groupdata(g_qos, &p.value, &p.sz);
cr_assert_eq(p.sz, g_pol_groupdata.sz);
cr_assert_str_eq(p.value, g_pol_groupdata.value);
dds_free(p.value);
}
Test(ddsc_qos, durability, .init=qos_init, .fini=qos_fini)
{
struct pol_durability p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_durability(NULL, g_pol_durability.kind);
dds_qget_durability(NULL, &p.kind);
dds_qget_durability(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_durability(g_qos, g_pol_durability.kind);
dds_qget_durability(g_qos, &p.kind);
cr_assert_eq(p.kind, g_pol_durability.kind);
}
Test(ddsc_qos, history, .init=qos_init, .fini=qos_fini)
{
struct pol_history p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_history(NULL, g_pol_history.kind, g_pol_history.depth);
dds_qget_history(NULL, &p.kind, &p.depth);
dds_qget_history(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_history(g_qos, g_pol_history.kind, g_pol_history.depth);
dds_qget_history(g_qos, &p.kind, &p.depth);
cr_assert_eq(p.kind, g_pol_history.kind);
cr_assert_eq(p.depth, g_pol_history.depth);
}
Test(ddsc_qos, resource_limits, .init=qos_init, .fini=qos_fini)
{
struct pol_resource_limits p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_resource_limits(NULL, g_pol_resource_limits.max_samples, g_pol_resource_limits.max_instances, g_pol_resource_limits.max_samples_per_instance);
dds_qget_resource_limits(NULL, &p.max_samples, &p.max_instances, &p.max_samples_per_instance);
dds_qget_resource_limits(g_qos, NULL, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_resource_limits(g_qos, g_pol_resource_limits.max_samples, g_pol_resource_limits.max_instances, g_pol_resource_limits.max_samples_per_instance);
dds_qget_resource_limits(g_qos, &p.max_samples, &p.max_instances, &p.max_samples_per_instance);
cr_assert_eq(p.max_samples, g_pol_resource_limits.max_samples);
cr_assert_eq(p.max_instances, g_pol_resource_limits.max_instances);
cr_assert_eq(p.max_samples_per_instance, g_pol_resource_limits.max_samples_per_instance);
}
Test(ddsc_qos, presentation, .init=qos_init, .fini=qos_fini)
{
struct pol_presentation p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_presentation(NULL, g_pol_presentation.access_scope, g_pol_presentation.coherent_access, g_pol_presentation.ordered_access);
dds_qget_presentation(NULL, &p.access_scope, &p.coherent_access, &p.ordered_access);
dds_qget_presentation(g_qos, NULL, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_presentation(g_qos, g_pol_presentation.access_scope, g_pol_presentation.coherent_access, g_pol_presentation.ordered_access);
dds_qget_presentation(g_qos, &p.access_scope, &p.coherent_access, &p.ordered_access);
cr_assert_eq(p.access_scope, g_pol_presentation.access_scope);
cr_assert_eq(p.coherent_access, g_pol_presentation.coherent_access);
cr_assert_eq(p.ordered_access, g_pol_presentation.ordered_access);
}
Test(ddsc_qos, lifespan, .init=qos_init, .fini=qos_fini)
{
struct pol_lifespan p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_lifespan(NULL, g_pol_lifespan.lifespan);
dds_qget_lifespan(NULL, &p.lifespan);
dds_qget_lifespan(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_lifespan(g_qos, g_pol_lifespan.lifespan);
dds_qget_lifespan(g_qos, &p.lifespan);
cr_assert_eq(p.lifespan, g_pol_lifespan.lifespan);
}
Test(ddsc_qos, deadline, .init=qos_init, .fini=qos_fini)
{
struct pol_deadline p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_deadline(NULL, g_pol_deadline.deadline);
dds_qget_deadline(NULL, &p.deadline);
dds_qget_deadline(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_deadline(g_qos, g_pol_deadline.deadline);
dds_qget_deadline(g_qos, &p.deadline);
cr_assert_eq(p.deadline, g_pol_deadline.deadline);
}
Test(ddsc_qos, latency_budget, .init=qos_init, .fini=qos_fini)
{
struct pol_latency_budget p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_latency_budget(NULL, g_pol_latency_budget.duration);
dds_qget_latency_budget(NULL, &p.duration);
dds_qget_latency_budget(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_latency_budget(g_qos, g_pol_latency_budget.duration);
dds_qget_latency_budget(g_qos, &p.duration);
cr_assert_eq(p.duration, g_pol_latency_budget.duration);
}
Test(ddsc_qos, ownership, .init=qos_init, .fini=qos_fini)
{
struct pol_ownership p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_ownership(NULL, g_pol_ownership.kind);
dds_qget_ownership(NULL, &p.kind);
dds_qget_ownership(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_ownership(g_qos, g_pol_ownership.kind);
dds_qget_ownership(g_qos, &p.kind);
cr_assert_eq(p.kind, g_pol_ownership.kind);
}
Test(ddsc_qos, ownership_strength, .init=qos_init, .fini=qos_fini)
{
struct pol_ownership_strength p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_ownership_strength(NULL, g_pol_ownership_strength.value);
dds_qget_ownership_strength(NULL, &p.value);
dds_qget_ownership_strength(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_ownership_strength(g_qos, g_pol_ownership_strength.value);
dds_qget_ownership_strength(g_qos, &p.value);
cr_assert_eq(p.value, g_pol_ownership_strength.value);
}
Test(ddsc_qos, liveliness, .init=qos_init, .fini=qos_fini)
{
struct pol_liveliness p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_liveliness(NULL, g_pol_liveliness.kind, g_pol_liveliness.lease_duration);
dds_qget_liveliness(NULL, &p.kind, &p.lease_duration);
dds_qget_liveliness(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_liveliness(g_qos, g_pol_liveliness.kind, g_pol_liveliness.lease_duration);
dds_qget_liveliness(g_qos, &p.kind, &p.lease_duration);
cr_assert_eq(p.kind, g_pol_liveliness.kind);
cr_assert_eq(p.lease_duration, g_pol_liveliness.lease_duration);
}
Test(ddsc_qos, time_base_filter, .init=qos_init, .fini=qos_fini)
{
struct pol_time_based_filter p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_time_based_filter(NULL, g_pol_time_based_filter.minimum_separation);
dds_qget_time_based_filter(NULL, &p.minimum_separation);
dds_qget_time_based_filter(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_time_based_filter(g_qos, g_pol_time_based_filter.minimum_separation);
dds_qget_time_based_filter(g_qos, &p.minimum_separation);
cr_assert_eq(p.minimum_separation, g_pol_time_based_filter.minimum_separation);
}
Test(ddsc_qos, partition, .init=qos_init, .fini=qos_fini)
{
struct pol_partition p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_partition(NULL, g_pol_partition.n, c_partitions);
dds_qget_partition(NULL, &p.n, &p.ps);
dds_qget_partition(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_partition(g_qos, g_pol_partition.n, c_partitions);
dds_qget_partition(g_qos, &p.n, &p.ps);
cr_assert_eq(p.n, 2);
cr_assert_eq(p.n, g_pol_partition.n);
cr_assert_str_eq(p.ps[0], g_pol_partition.ps[0]);
cr_assert_str_eq(p.ps[1], g_pol_partition.ps[1]);
dds_free(p.ps[0]);
dds_free(p.ps[1]);
dds_free(p.ps);
}
Test(ddsc_qos, reliability, .init=qos_init, .fini=qos_fini)
{
struct pol_reliability p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_reliability(NULL, g_pol_reliability.kind, g_pol_reliability.max_blocking_time);
dds_qget_reliability(NULL, &p.kind, &p.max_blocking_time);
dds_qget_reliability(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_reliability(g_qos, g_pol_reliability.kind, g_pol_reliability.max_blocking_time);
dds_qget_reliability(g_qos, &p.kind, &p.max_blocking_time);
cr_assert_eq(p.kind, g_pol_reliability.kind);
cr_assert_eq(p.max_blocking_time, g_pol_reliability.max_blocking_time);
}
Test(ddsc_qos, transport_priority, .init=qos_init, .fini=qos_fini)
{
struct pol_transport_priority p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_transport_priority(NULL, g_pol_transport_priority.value);
dds_qget_transport_priority(NULL, &p.value);
dds_qget_transport_priority(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_transport_priority(g_qos, g_pol_transport_priority.value);
dds_qget_transport_priority(g_qos, &p.value);
cr_assert_eq(p.value, g_pol_transport_priority.value);
}
Test(ddsc_qos, destination_order, .init=qos_init, .fini=qos_fini)
{
struct pol_destination_order p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_destination_order(NULL, g_pol_destination_order.kind);
dds_qget_destination_order(NULL, &p.kind);
dds_qget_destination_order(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_destination_order(g_qos, g_pol_destination_order.kind);
dds_qget_destination_order(g_qos, &p.kind);
cr_assert_eq(p.kind, g_pol_destination_order.kind);
}
Test(ddsc_qos, writer_data_lifecycle, .init=qos_init, .fini=qos_fini)
{
struct pol_writer_data_lifecycle p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_writer_data_lifecycle(NULL, g_pol_writer_data_lifecycle.autodispose);
dds_qget_writer_data_lifecycle(NULL, &p.autodispose);
dds_qget_writer_data_lifecycle(g_qos, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_writer_data_lifecycle(g_qos, g_pol_writer_data_lifecycle.autodispose);
dds_qget_writer_data_lifecycle(g_qos, &p.autodispose);
cr_assert_eq(p.autodispose, g_pol_writer_data_lifecycle.autodispose);
}
Test(ddsc_qos, reader_data_lifecycle, .init=qos_init, .fini=qos_fini)
{
struct pol_reader_data_lifecycle p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_reader_data_lifecycle(NULL, g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay, g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay);
dds_qget_reader_data_lifecycle(NULL, &p.autopurge_nowriter_samples_delay, &p.autopurge_disposed_samples_delay);
dds_qget_reader_data_lifecycle(g_qos, NULL, NULL);
/* Getting after setting, should yield the original input. */
dds_qset_reader_data_lifecycle(g_qos, g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay, g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay);
dds_qget_reader_data_lifecycle(g_qos, &p.autopurge_nowriter_samples_delay, &p.autopurge_disposed_samples_delay);
cr_assert_eq(p.autopurge_nowriter_samples_delay, g_pol_reader_data_lifecycle.autopurge_nowriter_samples_delay);
cr_assert_eq(p.autopurge_disposed_samples_delay, g_pol_reader_data_lifecycle.autopurge_disposed_samples_delay);
}
Test(ddsc_qos, durability_service, .init=qos_init, .fini=qos_fini)
{
struct pol_durability_service p = { 0 };
/* NULLs shouldn't crash and be a noops. */
dds_qset_durability_service(NULL,
g_pol_durability_service.service_cleanup_delay,
g_pol_durability_service.history_kind,
g_pol_durability_service.history_depth,
g_pol_durability_service.max_samples,
g_pol_durability_service.max_instances,
g_pol_durability_service.max_samples_per_instance);
dds_qget_durability_service(NULL,
&p.service_cleanup_delay,
&p.history_kind,
&p.history_depth,
&p.max_samples,
&p.max_instances,
&p.max_samples_per_instance);
dds_qget_durability_service(g_qos,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
/* Getting after setting, should yield the original input. */
dds_qset_durability_service(g_qos,
g_pol_durability_service.service_cleanup_delay,
g_pol_durability_service.history_kind,
g_pol_durability_service.history_depth,
g_pol_durability_service.max_samples,
g_pol_durability_service.max_instances,
g_pol_durability_service.max_samples_per_instance);
dds_qget_durability_service(g_qos,
&p.service_cleanup_delay,
&p.history_kind,
&p.history_depth,
&p.max_samples,
&p.max_instances,
&p.max_samples_per_instance);
cr_assert_eq(p.service_cleanup_delay, g_pol_durability_service.service_cleanup_delay);
cr_assert_eq(p.history_kind, g_pol_durability_service.history_kind);
cr_assert_eq(p.history_depth, g_pol_durability_service.history_depth);
cr_assert_eq(p.max_samples, g_pol_durability_service.max_samples);
cr_assert_eq(p.max_instances, g_pol_durability_service.max_instances);
cr_assert_eq(p.max_samples_per_instance, g_pol_durability_service.max_samples_per_instance);
}
#endif
#pragma warning(pop)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

3208
src/core/ddsc/tests/reader.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,769 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <assert.h>
#include "ddsc/dds.h"
#include "os/os.h"
#include "Space.h"
#include "RoundTrip.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/theories.h>
#if 0
#define PRINT_SAMPLE(info, sample) cr_log_info("%s (%d, %d, %d)\n", info, sample.long_1, sample.long_2, sample.long_3);
#else
#define PRINT_SAMPLE(info, sample)
#endif
/**************************************************************************************************
*
* Test fixtures
*
*************************************************************************************************/
/*
* By writing, disposing, unregistering, reading and re-writing, the following
* data will be available in the reader history (but not in this order).
* | long_1 | long_2 | long_3 | sst | vst | ist |
* ----------------------------------------------------------
* | 0 | 0 | 0 | not_read | new | alive |
* | 0 | 1 | 2 | not_read | new | alive |
* | 0 | 2 | 4 | not_read | new | alive |
* | 1 | 3 | 6 | read | old | alive |
* | 1 | 4 | 8 | read | old | alive |
* | 1 | 5 | 10 | read | old | alive |
* | 2 | 6 | 12 | not_read | old | alive |
* | 2 | 7 | 14 | not_read | old | alive |
* | 2 | 8 | 16 | read | old | alive |
* | 3 | 9 | 18 | not_read | old | alive |
* | 3 | 10 | 20 | read | old | alive |
* | 3 | 11 | 22 | not_read | old | alive |
* | 4 | 12 | 24 | read | old | alive |
* | 4 | 13 | 26 | not_read | old | alive |
* | 4 | 14 | 28 | not_read | old | alive |
* | 5 | 15 | 30 | read | old | disposed |
* | 5 | 16 | 32 | not_read | old | disposed |
* | 5 | 17 | 34 | read | old | disposed |
* | 6 | 18 | 36 | read | old | no_writers |
* | 6 | 19 | 38 | not_read | old | no_writers |
* | 6 | 20 | 40 | read | old | no_writers |
*
*/
#define MAX_SAMPLES 21
#define RDR_NOT_READ_CNT 11
int rdr_expected_long_2[RDR_NOT_READ_CNT] = { 0, 1, 2, 6, 7, 9, 11, 13, 14, 16, 19 };
/* Because we only read one sample at a time, only the first sample of an instance
* can be new. This turns out to be only the very first sample. */
#define SAMPLE_VST(long_2) ((long_2 == 0) ? DDS_VST_NEW : DDS_VST_OLD)
#define SAMPLE_IST(long_1) ((long_1 == 5) ? DDS_IST_NOT_ALIVE_DISPOSED : \
(long_1 == 6) ? DDS_IST_NOT_ALIVE_NO_WRITERS : \
DDS_IST_ALIVE )
static dds_entity_t g_participant = 0;
static dds_entity_t g_subscriber = 0;
static dds_entity_t g_publisher = 0;
static dds_entity_t g_topic = 0;
static dds_entity_t g_reader = 0;
static dds_entity_t g_writer = 0;
static dds_entity_t g_waitset = 0;
static dds_entity_t g_rcond = 0;
static dds_entity_t g_qcond = 0;
static void* g_loans[MAX_SAMPLES];
static void* g_samples[MAX_SAMPLES];
static Space_Type1 g_data[MAX_SAMPLES];
static dds_sample_info_t g_info[MAX_SAMPLES];
static dds_instance_handle_t g_hdl_valid;
static dds_instance_handle_t g_hdl_nil = DDS_HANDLE_NIL;
static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;
}
static bool
filter_init(const void * sample)
{
const Space_Type1 *s = sample;
return ((s->long_2 == 3) ||
(s->long_2 == 4) ||
(s->long_2 == 5) ||
(s->long_2 == 8) ||
(s->long_2 == 10) ||
(s->long_2 == 12) ||
(s->long_2 == 15) ||
(s->long_2 == 17) ||
(s->long_2 == 18) ||
(s->long_2 == 20));
}
static bool
filter_mod2(const void * sample)
{
const Space_Type1 *s = sample;
return (s->long_2 % 2 == 0);
}
static void
reader_iterator_init(void)
{
Space_Type1 sample = { 0 };
dds_attach_t triggered;
dds_return_t ret;
char name[100];
dds_qos_t *qos;
qos = dds_qos_create();
cr_assert_not_null(qos, "Failed to create prerequisite qos");
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_subscriber = dds_create_subscriber(g_participant, NULL, NULL);
cr_assert_gt(g_subscriber, 0, "Failed to create prerequisite g_subscriber");
g_publisher = dds_create_publisher(g_participant, NULL, NULL);
cr_assert_gt(g_publisher, 0, "Failed to create prerequisite g_publisher");
g_waitset = dds_create_waitset(g_participant);
cr_assert_gt(g_waitset, 0, "Failed to create g_waitset");
g_topic = dds_create_topic(g_participant, &Space_Type1_desc, create_topic_name("ddsc_read_iterator_test", name, sizeof name), NULL, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
/* Create a writer that will not automatically dispose unregistered samples. */
dds_qset_writer_data_lifecycle(qos, false);
g_writer = dds_create_writer(g_publisher, g_topic, qos, NULL);
cr_assert_gt(g_writer, 0, "Failed to create prerequisite g_writer");
/* Create a reader that keeps all samples when not taken. */
dds_qset_history(qos, DDS_HISTORY_KEEP_ALL, DDS_LENGTH_UNLIMITED);
g_reader = dds_create_reader(g_subscriber, g_topic, qos, NULL);
cr_assert_gt(g_reader, 0, "Failed to create prerequisite g_reader");
/* Create a read condition that only reads old samples. */
g_rcond = dds_create_readcondition(g_reader, DDS_NOT_READ_SAMPLE_STATE | DDS_NOT_NEW_VIEW_STATE | DDS_ANY_INSTANCE_STATE);
cr_assert_gt(g_rcond, 0, "Failed to create prerequisite g_rcond");
/* Create a query condition that only reads of instances mod2. */
g_qcond = dds_create_querycondition(g_reader, DDS_NOT_READ_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE, filter_mod2);
cr_assert_gt(g_qcond, 0, "Failed to create prerequisite g_qcond");
/* Sync g_reader to g_writer. */
ret = dds_set_enabled_status(g_reader, DDS_SUBSCRIPTION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_reader status");
ret = dds_waitset_attach(g_waitset, g_reader, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_reader");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_reader r");
cr_assert_eq(g_reader, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_reader a");
ret = dds_waitset_detach(g_waitset, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_reader");
/* Sync g_writer to g_reader. */
ret = dds_set_enabled_status(g_writer, DDS_PUBLICATION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_writer status");
ret = dds_waitset_attach(g_waitset, g_writer, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_writer");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_writer r");
cr_assert_eq(g_writer, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_writer a");
ret = dds_waitset_detach(g_waitset, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_writer");
/* Initialize reading buffers. */
memset (g_data, 0, sizeof (g_data));
for (int i = 0; i < MAX_SAMPLES; i++) {
g_samples[i] = &g_data[i];
}
for (int i = 0; i < MAX_SAMPLES; i++) {
g_loans[i] = NULL;
}
/* Write the samples. */
for (int i = 0; i < MAX_SAMPLES; i++) {
sample.long_1 = i/3;
sample.long_2 = i;
sample.long_3 = i*2;
ret = dds_write(g_writer, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
}
/* | long_1 | long_2 | long_3 | sst | vst | ist |
* -----------------------------------------------------
* | 0 | 0 | 0 | not_read | new | alive |
* | 0 | 1 | 2 | not_read | new | alive |
* | 0 | 2 | 4 | not_read | new | alive |
* | 1 | 3 | 6 | not_read | new | alive |
* | 1 | 4 | 8 | not_read | new | alive |
* | 1 | 5 | 10 | not_read | new | alive |
* | 2 | 6 | 12 | not_read | new | alive |
* | 2 | 7 | 14 | not_read | new | alive |
* | 2 | 8 | 16 | not_read | new | alive |
* | 3 | 9 | 18 | not_read | new | alive |
* | 3 | 10 | 20 | not_read | new | alive |
* | 3 | 11 | 22 | not_read | new | alive |
* | 4 | 12 | 24 | not_read | new | alive |
* | 4 | 13 | 26 | not_read | new | alive |
* | 4 | 14 | 28 | not_read | new | alive |
* | 5 | 15 | 30 | not_read | new | alive |
* | 5 | 16 | 32 | not_read | new | alive |
* | 5 | 17 | 34 | not_read | new | alive |
* | 6 | 18 | 36 | not_read | new | alive |
* | 6 | 19 | 38 | not_read | new | alive |
* | 6 | 20 | 40 | not_read | new | alive |
*/
/* Set the sst to read for the proper samples by using a query
* condition that filters for these specific samples. */
{
dds_entity_t qcond = 0;
/* Create a query condition that reads the specific sample to get a set of 'read' samples after init. */
qcond = dds_create_querycondition(g_reader, DDS_ANY_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE, filter_init);
cr_assert_gt(g_qcond, 0, "Failed to create prerequisite qcond");
ret = dds_read(qcond, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_gt(ret, 0, "Failed prerequisite read: %d", dds_err_nr(ret));
dds_delete(qcond);
}
/* | long_1 | long_2 | long_3 | sst | vst | ist |
* -----------------------------------------------------
* | 0 | 0 | 0 | not_read | new | alive |
* | 0 | 1 | 2 | not_read | new | alive |
* | 0 | 2 | 4 | not_read | new | alive |
* | 1 | 3 | 6 | read | old | alive |
* | 1 | 4 | 8 | read | old | alive |
* | 1 | 5 | 10 | read | old | alive |
* | 2 | 6 | 12 | not_read | old | alive |
* | 2 | 7 | 14 | not_read | old | alive |
* | 2 | 8 | 16 | read | old | alive |
* | 3 | 9 | 18 | not_read | old | alive |
* | 3 | 10 | 20 | read | old | alive |
* | 3 | 11 | 22 | not_read | old | alive |
* | 4 | 12 | 24 | read | old | alive |
* | 4 | 13 | 26 | not_read | old | alive |
* | 4 | 14 | 28 | not_read | old | alive |
* | 5 | 15 | 30 | read | old | alive |
* | 5 | 16 | 32 | not_read | old | alive |
* | 5 | 17 | 34 | read | old | alive |
* | 6 | 18 | 36 | read | old | alive |
* | 6 | 19 | 38 | not_read | old | alive |
* | 6 | 20 | 40 | read | old | alive |
*/
/* Dispose and unregister the last two samples. */
sample.long_1 = 5;
sample.long_2 = 15;
sample.long_3 = 30;
ret = dds_dispose(g_writer, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite dispose");
sample.long_1 = 6;
sample.long_2 = 16;
sample.long_3 = 32;
ret = dds_unregister_instance(g_writer, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite unregister");
/* | long_1 | long_2 | long_3 | sst | vst | ist |
* ----------------------------------------------------------
* | 0 | 0 | 0 | not_read | new | alive |
* | 0 | 1 | 2 | not_read | new | alive |
* | 0 | 2 | 4 | not_read | new | alive |
* | 1 | 3 | 6 | read | old | alive |
* | 1 | 4 | 8 | read | old | alive |
* | 1 | 5 | 10 | read | old | alive |
* | 2 | 6 | 12 | not_read | old | alive |
* | 2 | 7 | 14 | not_read | old | alive |
* | 2 | 8 | 16 | read | old | alive |
* | 3 | 9 | 18 | not_read | old | alive |
* | 3 | 10 | 20 | read | old | alive |
* | 3 | 11 | 22 | not_read | old | alive |
* | 4 | 12 | 24 | read | old | alive |
* | 4 | 13 | 26 | not_read | old | alive |
* | 4 | 14 | 28 | not_read | old | alive |
* | 5 | 15 | 30 | read | old | disposed |
* | 5 | 16 | 32 | not_read | old | disposed |
* | 5 | 17 | 34 | read | old | disposed |
* | 6 | 18 | 36 | read | old | no_writers |
* | 6 | 19 | 38 | not_read | old | no_writers |
* | 6 | 20 | 40 | read | old | no_writers |
*/
dds_qos_delete(qos);
}
static void
reader_iterator_fini(void)
{
dds_delete(g_rcond);
dds_delete(g_qcond);
dds_delete(g_reader);
dds_delete(g_writer);
dds_delete(g_subscriber);
dds_delete(g_publisher);
dds_delete(g_waitset);
dds_delete(g_topic);
dds_delete(g_participant);
}
static dds_return_t
samples_cnt(void)
{
dds_return_t ret;
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_geq(ret, 0, "Failed samples count read: %d", dds_err_nr(ret));
return ret;
}
/**************************************************************************************************
*
* These will check the dds_read_next() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_read_next, reader, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t cnt = 0;
dds_return_t ret = 1;
while (ret == 1){
ret = dds_read_next(g_reader, g_samples, g_info);
cr_assert_geq(ret, 0 , "# read %d", ret);
if(ret == 1){
Space_Type1 *sample = (Space_Type1*)g_samples[0];
PRINT_SAMPLE("ddsc_read_next::reader: Read", (*sample));
/* Expected states. */
int expected_long_2 = rdr_expected_long_2[cnt];
int expected_long_1 = expected_long_2/3;
int expected_long_3 = expected_long_2*2;
dds_sample_state_t expected_sst = DDS_SST_NOT_READ;
dds_view_state_t expected_vst = SAMPLE_VST(expected_long_2);
dds_instance_state_t expected_ist = SAMPLE_IST(expected_long_1);
/* Check data. */
cr_assert_eq(sample->long_1, expected_long_1 );
cr_assert_eq(sample->long_2, expected_long_2 );
cr_assert_eq(sample->long_3, expected_long_2 *2);
/* Check states. */
cr_assert_eq(g_info[0].valid_data, true);
cr_assert_eq(g_info[0].sample_state, expected_sst);
cr_assert_eq(g_info[0].view_state, expected_vst);
cr_assert_eq(g_info[0].instance_state, expected_ist);
cnt ++;
}
}
cr_assert_eq(cnt, RDR_NOT_READ_CNT);
/* All samples should still be available. */
ret = samples_cnt();
cr_assert_eq(ret, MAX_SAMPLES, "# samples %d, expected %d", ret, MAX_SAMPLES);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next, invalid_readers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t rdr), ddsc_read_next, invalid_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_read_next(rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_str(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next, non_readers) = {
DataPoints(dds_entity_t*, &g_participant, &g_topic, &g_writer, &g_subscriber, &g_publisher, &g_waitset, &g_rcond, &g_qcond),
};
Theory((dds_entity_t *rdr), ddsc_read_next, non_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_read_next(*rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next, already_deleted) = {
DataPoints(dds_entity_t*, &g_rcond, &g_qcond, &g_reader),
};
Theory((dds_entity_t *rdr), ddsc_read_next, already_deleted, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_delete(*rdr);
cr_assert_eq(ret, DDS_RETCODE_OK, "prerequisite delete failed: %d", dds_err_nr(ret));
ret = dds_read_next(*rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next, invalid_buffers) = {
DataPoints(void**, g_samples, g_loans, (void**)0),
DataPoints(dds_sample_info_t*, g_info, (dds_sample_info_t*)0 ),
};
Theory((void **buf, dds_sample_info_t *si), ddsc_read_next, invalid_buffers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
cr_assume((buf != g_samples) || (si != g_info));
cr_assume(buf != g_loans);
ret = dds_read_next(g_reader, buf, si);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_read_next_wl() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_read_next_wl, reader, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t cnt = 0;
dds_return_t ret = 1;
while (ret == 1){
ret = dds_read_next_wl(g_reader, g_loans, g_info);
cr_assert_geq(ret, 0 , "# read %d", ret);
if(ret == 1){
Space_Type1 *sample = (Space_Type1*)g_loans[0];
PRINT_SAMPLE("ddsc_read_next_wl::reader: Read", (*sample));
/* Expected states. */
int expected_long_2 = rdr_expected_long_2[cnt];
int expected_long_1 = expected_long_2/3;
int expected_long_3 = expected_long_2*2;
dds_sample_state_t expected_sst = DDS_SST_NOT_READ;
dds_view_state_t expected_vst = SAMPLE_VST(expected_long_2);
dds_instance_state_t expected_ist = SAMPLE_IST(expected_long_1);
/* Check data. */
cr_assert_eq(sample->long_1, expected_long_2/3 );
cr_assert_eq(sample->long_2, expected_long_2 );
cr_assert_eq(sample->long_3, expected_long_2 *2);
/* Check states. */
cr_assert_eq(g_info[0].valid_data, true);
cr_assert_eq(g_info[0].sample_state, expected_sst);
cr_assert_eq(g_info[0].view_state, expected_vst);
cr_assert_eq(g_info[0].instance_state, expected_ist);
cnt ++;
}
}
cr_assert_eq(cnt, RDR_NOT_READ_CNT);
ret = dds_return_loan(g_reader, g_loans, ret);
cr_assert_eq (ret, DDS_RETCODE_OK);
/* All samples should still be available. */
ret = samples_cnt();
cr_assert_eq(ret, MAX_SAMPLES, "# samples %d, expected %d", ret, MAX_SAMPLES);
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next_wl, invalid_readers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t rdr), ddsc_read_next_wl, invalid_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_read_next_wl(rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next_wl, non_readers) = {
DataPoints(dds_entity_t*, &g_participant, &g_topic, &g_writer, &g_subscriber, &g_publisher, &g_waitset, &g_rcond, &g_qcond),
};
Theory((dds_entity_t *rdr), ddsc_read_next_wl, non_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_read_next_wl(*rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next_wl, already_deleted) = {
DataPoints(dds_entity_t*, &g_rcond, &g_qcond, &g_reader),
};
Theory((dds_entity_t *rdr), ddsc_read_next_wl, already_deleted, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_delete(*rdr);
cr_assert_eq(ret, DDS_RETCODE_OK, "prerequisite delete failed: %d", dds_err_nr(ret));
ret = dds_read_next_wl(*rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_read_next_wl, invalid_buffers) = {
DataPoints(void**, g_loans, (void**)0),
DataPoints(dds_sample_info_t*, g_info, (dds_sample_info_t*)0 ),
};
Theory((void **buf, dds_sample_info_t *si), ddsc_read_next_wl, invalid_buffers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
cr_assume((buf != g_loans) || (si != g_info));
ret = dds_read_next_wl(g_reader, buf, si);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_take_next() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_take_next, reader, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t cnt = 0;
dds_return_t ret = 1;
while (ret == 1){
ret = dds_take_next(g_reader, g_samples, g_info);
cr_assert_geq(ret, 0 , "# read %d", ret);
if(ret == 1){
Space_Type1 *sample = (Space_Type1*)g_samples[0];
PRINT_SAMPLE("ddsc_take_next::reader: Read", (*sample));
/* Expected states. */
int expected_long_2 = rdr_expected_long_2[cnt];
int expected_long_1 = expected_long_2/3;
int expected_long_3 = expected_long_2*2;
dds_sample_state_t expected_sst = DDS_SST_NOT_READ;
dds_view_state_t expected_vst = SAMPLE_VST(expected_long_2);
dds_instance_state_t expected_ist = SAMPLE_IST(expected_long_1);
/* Check data. */
cr_assert_eq(sample->long_1, expected_long_1 );
cr_assert_eq(sample->long_2, expected_long_2 );
cr_assert_eq(sample->long_3, expected_long_2 *2);
/* Check states. */
cr_assert_eq(g_info[0].valid_data, true);
cr_assert_eq(g_info[0].sample_state, expected_sst);
cr_assert_eq(g_info[0].view_state, expected_vst);
cr_assert_eq(g_info[0].instance_state, expected_ist);
cnt ++;
}
}
cr_assert_eq(cnt, RDR_NOT_READ_CNT);
/* All samples should still be available. */
ret = samples_cnt();
cr_assert_eq(ret, (MAX_SAMPLES - RDR_NOT_READ_CNT), "# samples %d, expected %d", ret, MAX_SAMPLES);
}
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next, invalid_readers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t rdr), ddsc_take_next, invalid_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_take_next(rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next, non_readers) = {
DataPoints(dds_entity_t*, &g_participant, &g_topic, &g_writer, &g_subscriber, &g_publisher, &g_waitset, &g_rcond, &g_qcond),
};
Theory((dds_entity_t *rdr), ddsc_take_next, non_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_take_next(*rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next, already_deleted) = {
DataPoints(dds_entity_t*, &g_rcond, &g_qcond, &g_reader),
};
Theory((dds_entity_t *rdr), ddsc_take_next, already_deleted, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_delete(*rdr);
cr_assert_eq(ret, DDS_RETCODE_OK, "prerequisite delete failed: %d", dds_err_nr(ret));
ret = dds_take_next(*rdr, g_samples, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next, invalid_buffers) = {
DataPoints(void**, g_samples, g_loans, (void**)0),
DataPoints(dds_sample_info_t*, g_info, (dds_sample_info_t*)0 ),
};
Theory((void **buf, dds_sample_info_t *si), ddsc_take_next, invalid_buffers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
cr_assume((buf != g_samples) || (si != g_info));
cr_assume(buf != g_loans);
ret = dds_take_next(g_reader, buf, si);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_take_next_wl() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_take_next_wl, reader, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t cnt = 0;
dds_return_t ret = 1;
while (ret == 1){
ret = dds_take_next_wl(g_reader, g_loans, g_info);
cr_assert_geq(ret, 0 , "# read %d", ret);
if(ret == 1){
Space_Type1 *sample = (Space_Type1*)g_loans[0];
PRINT_SAMPLE("ddsc_read_next_wl::reader: Read", (*sample));
/* Expected states. */
int expected_long_2 = rdr_expected_long_2[cnt];
int expected_long_1 = expected_long_2/3;
int expected_long_3 = expected_long_2*2;
dds_sample_state_t expected_sst = DDS_SST_NOT_READ;
dds_view_state_t expected_vst = SAMPLE_VST(expected_long_2);
dds_instance_state_t expected_ist = SAMPLE_IST(expected_long_1);
/* Check data. */
cr_assert_eq(sample->long_1, expected_long_2/3 );
cr_assert_eq(sample->long_2, expected_long_2 );
cr_assert_eq(sample->long_3, expected_long_2 *2);
/* Check states. */
cr_assert_eq(g_info[0].valid_data, true);
cr_assert_eq(g_info[0].sample_state, expected_sst);
cr_assert_eq(g_info[0].view_state, expected_vst);
cr_assert_eq(g_info[0].instance_state, expected_ist);
cnt ++;
}
}
cr_assert_eq(cnt, RDR_NOT_READ_CNT);
ret = dds_return_loan(g_reader, g_loans, ret);
cr_assert_eq (ret, DDS_RETCODE_OK);
/* All samples should still be available. */
ret = samples_cnt();
cr_assert_eq(ret, (MAX_SAMPLES - RDR_NOT_READ_CNT), "# samples %d, expected %d", ret, MAX_SAMPLES);
}
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next_wl, invalid_readers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t rdr), ddsc_take_next_wl, invalid_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_take_next_wl(rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next_wl, non_readers) = {
DataPoints(dds_entity_t*, &g_participant, &g_topic, &g_writer, &g_subscriber, &g_publisher, &g_waitset, &g_rcond, &g_qcond),
};
Theory((dds_entity_t *rdr), ddsc_take_next_wl, non_readers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_take_next_wl(*rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next_wl, already_deleted) = {
DataPoints(dds_entity_t*, &g_rcond, &g_qcond, &g_reader),
};
Theory((dds_entity_t *rdr), ddsc_take_next_wl, already_deleted, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
ret = dds_delete(*rdr);
cr_assert_eq(ret, DDS_RETCODE_OK, "prerequisite delete failed: %d", dds_err_nr(ret));
ret = dds_take_next_wl(*rdr, g_loans, g_info);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_take_next_wl, invalid_buffers) = {
DataPoints(void**, g_loans, (void**)0),
DataPoints(dds_sample_info_t*, g_info, (dds_sample_info_t*)0 ),
};
Theory((void **buf, dds_sample_info_t *si), ddsc_take_next_wl, invalid_buffers, .init=reader_iterator_init, .fini=reader_iterator_fini)
{
dds_return_t ret;
cr_assume((buf != g_loans) || (si != g_info));
ret = dds_take_next_wl(g_reader, buf, si);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/

View file

@ -0,0 +1,227 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <assert.h>
#include "ddsc/dds.h"
#include "os/os.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/theories.h>
#include "Space.h"
/**************************************************************************************************
*
* Test fixtures
*
*************************************************************************************************/
#define MAX_SAMPLES 7
#define INITIAL_SAMPLES 2
static dds_entity_t g_participant = 0;
static dds_entity_t g_topic = 0;
static dds_entity_t g_reader = 0;
static dds_entity_t g_writer = 0;
static dds_entity_t g_waitset = 0;
static dds_time_t g_past = 0;
static dds_time_t g_present = 0;
static void* g_samples[MAX_SAMPLES];
static Space_Type1 g_data[MAX_SAMPLES];
static dds_sample_info_t g_info[MAX_SAMPLES];
static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;
}
static void
registering_init(void)
{
Space_Type1 sample = { 0 };
dds_qos_t *qos = dds_qos_create ();
dds_attach_t triggered;
dds_return_t ret;
char name[100];
/* Use by source timestamp to be able to check the time related funtions. */
dds_qset_destination_order(qos, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP);
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_waitset = dds_create_waitset(g_participant);
cr_assert_gt(g_waitset, 0, "Failed to create g_waitset");
g_topic = dds_create_topic(g_participant, &Space_Type1_desc, create_topic_name("ddsc_registering_test", name, sizeof name), qos, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
/* Create a reader that keeps one sample on three instances. */
dds_qset_reliability(qos, DDS_RELIABILITY_RELIABLE, DDS_MSECS(100));
dds_qset_resource_limits(qos, DDS_LENGTH_UNLIMITED, 3, 1);
g_reader = dds_create_reader(g_participant, g_topic, qos, NULL);
cr_assert_gt(g_reader, 0, "Failed to create prerequisite g_reader");
/* Create a writer that will not automatically dispose unregistered samples. */
dds_qset_writer_data_lifecycle(qos, false);
g_writer = dds_create_writer(g_participant, g_topic, qos, NULL);
cr_assert_gt(g_writer, 0, "Failed to create prerequisite g_writer");
/* Sync g_writer to g_reader. */
ret = dds_set_enabled_status(g_writer, DDS_PUBLICATION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_writer status");
ret = dds_waitset_attach(g_waitset, g_writer, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_writer");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_writer r");
cr_assert_eq(g_writer, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_writer a");
ret = dds_waitset_detach(g_waitset, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_writer");
/* Sync g_reader to g_writer. */
ret = dds_set_enabled_status(g_reader, DDS_SUBSCRIPTION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_reader status");
ret = dds_waitset_attach(g_waitset, g_reader, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_reader");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_reader r");
cr_assert_eq(g_reader, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_reader a");
ret = dds_waitset_detach(g_waitset, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_reader");
/* Write initial samples. */
for (int i = 0; i < INITIAL_SAMPLES; i++) {
sample.long_1 = i;
sample.long_2 = i*2;
sample.long_3 = i*3;
ret = dds_write(g_writer, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
}
/* Initialize reading buffers. */
memset (g_data, 0, sizeof (g_data));
for (int i = 0; i < MAX_SAMPLES; i++) {
g_samples[i] = &g_data[i];
}
/* Initialize times. */
g_present = dds_time();
g_past = g_present - DDS_SECS(1);
dds_qos_delete(qos);
}
static void
registering_fini(void)
{
dds_delete(g_reader);
dds_delete(g_writer);
dds_delete(g_waitset);
dds_delete(g_topic);
dds_delete(g_participant);
}
#if 0
#else
/**************************************************************************************************
*
* These will check the dds_register_instance() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_register_instance, deleted_entity, .init=registering_init, .fini=registering_fini)
{
dds_return_t ret;
dds_instance_handle_t handle;
dds_delete(g_writer);
ret = dds_register_instance(g_writer, &handle, g_data);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
static dds_instance_handle_t hndle = 0;
static Space_Type1 data;
TheoryDataPoints(ddsc_register_instance, invalid_params) = {
DataPoints(dds_instance_handle_t *, &hndle, NULL),
DataPoints(void*, &data, NULL)
};
Theory((dds_instance_handle_t *hndl2, void *datap), ddsc_register_instance, invalid_params/*, .init=registering_init, .fini=registering_fini*/)
{
dds_return_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
/* Only test when the combination of parameters is actually invalid.*/
cr_assume((hndl2 == NULL) || (datap == NULL));
OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */
ret = dds_register_instance(g_writer, hndl2, datap);
OS_WARNING_MSVC_ON(6387);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d != expected %d", dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER);
}
TheoryDataPoints(ddsc_register_instance, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t writer), ddsc_register_instance, invalid_writers, .init=registering_init, .fini=registering_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
dds_instance_handle_t handle;
ret = dds_register_instance(writer, &handle, g_data);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
TheoryDataPoints(ddsc_register_instance, non_writers) = {
DataPoints(dds_entity_t*, &g_waitset, &g_reader, &g_topic, &g_participant),
};
Theory((dds_entity_t *writer), ddsc_register_instance, non_writers, .init=registering_init, .fini=registering_fini)
{
dds_return_t ret;
dds_instance_handle_t handle;
ret = dds_register_instance(*writer, &handle, g_data);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
Test(ddsc_register_instance, registering_new_instance, .init=registering_init, .fini=registering_fini)
{
dds_instance_handle_t instHndl, instHndl2;
dds_return_t ret;
Space_Type1 newInstance = { INITIAL_SAMPLES, 0, 0 };
instHndl = dds_instance_lookup(g_writer, &newInstance);
cr_assert_eq(instHndl, DDS_HANDLE_NIL);
ret = dds_register_instance(g_writer, &instHndl2, &newInstance);
cr_assert_eq(ret, DDS_RETCODE_OK);
instHndl = dds_instance_lookup(g_writer, &newInstance);
cr_assert_eq(instHndl, instHndl2);
}
Test(ddsc_register_instance, data_already_available, .init=registering_init, .fini=registering_fini)
{
dds_instance_handle_t instHndl, instHndl2;
dds_return_t ret;
instHndl = dds_instance_lookup(g_writer, &g_data);
cr_assert_neq(instHndl, DDS_HANDLE_NIL);
ret = dds_register_instance(g_writer, &instHndl2, &g_data);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_eq(instHndl2, instHndl);
}
#endif

View file

@ -0,0 +1,150 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include "RoundTrip.h"
#include "os/os.h"
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
dds_entity_t participant = 0, topic = 0, reader = 0, read_condition = 0;
void create_entities(void)
{
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, "ddsc_reader_return_loan_RoundTrip", NULL, NULL);
cr_assert_gt(topic, 0);
reader = dds_create_reader(participant, topic, NULL, NULL);
cr_assert_gt(reader, 0);
read_condition = dds_create_readcondition(reader, DDS_ANY_STATE);
cr_assert_gt(read_condition, 0);
}
void delete_entities(void)
{
dds_return_t result;
result = dds_delete(participant);
cr_assert_eq(dds_err_nr(result), DDS_RETCODE_OK, "Recursively delete entities, Expected(%s) Returned(%s)", DDS_TO_STRING(DDS_RETCODE_OK), dds_err_str(result));
dds_delete(read_condition);
}
static void** create_loan_buf(size_t sz, bool empty)
{
size_t i;
void **buf = NULL;
buf = dds_alloc(sz * sizeof(*buf));
for (i = 0; i < sz; i++) {
buf[i] = dds_alloc(sizeof(RoundTripModule_DataType));
if (empty) {
memset(buf[i], 0, sizeof(RoundTripModule_DataType));
} else {
RoundTripModule_DataType *s = buf[i];
s->payload._maximum = 0;
s->payload._length = 25;
s->payload._buffer = dds_alloc(25);
memset(s->payload._buffer, 'z', 25);
s->payload._release = true;
}
}
return buf;
}
static void delete_loan_buf(void **buf, size_t sz, bool empty)
{
size_t i;
for (i = 0; i < sz; i++) {
RoundTripModule_DataType *s = buf[i];
if (!empty) {
cr_expect_gt(s->payload._length, 0, "Expected allocated 'payload'-sequence in sample-contents of loan");
if (s->payload._length > 0) {
/* Freed by a successful dds_return_loan */
dds_free(s->payload._buffer);
}
}
/* dds_return_loan only free's sample contents */
dds_free(s);
}
dds_free(buf);
}
/* Verify DDS_RETCODE_BAD_PARAMETER is returned */
Test(ddsc_reader, return_loan_bad_params, .init = create_entities, .fini = delete_entities)
{
dds_return_t result;
void **buf = NULL;
result = dds_return_loan(reader, NULL, 0);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_BAD_PARAMETER, "Invalid buffer(null), Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_BAD_PARAMETER),
dds_err_str(result));
#pragma warning(push)
#pragma warning(disable: 6387)
result = dds_return_loan(reader, buf, 10);
#pragma warning(pop)
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_BAD_PARAMETER, "Invalid buffer size, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_BAD_PARAMETER),
dds_err_str(result));
buf = create_loan_buf(10, false);
#pragma warning(push)
#pragma warning(disable: 28020)
result = dds_return_loan(0, buf, 10);
#pragma warning(pop)
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_BAD_PARAMETER, "Invalid entity, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_BAD_PARAMETER),
dds_err_str(result));
result = dds_return_loan(participant, buf, 0);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_ILLEGAL_OPERATION, "Invalid entity-kind, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_ILLEGAL_OPERATION),
dds_err_str(result));
delete_loan_buf(buf, 10, false);
}
/* Verify DDS_RETCODE_OK is returned */
Test(ddsc_reader, return_loan_success, .init = create_entities, .fini = delete_entities)
{
void **buf;
void *buf2 = NULL;
dds_return_t result;
buf = create_loan_buf(10, false);
result = dds_return_loan(reader, buf, 10);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_OK, "Return loan of size 10 via reader entity, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_OK),
dds_err_str(result));
result = dds_return_loan(reader, &buf2, 0);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_OK, "Return empty loan via reader entity, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_OK),
dds_err_str(result));
delete_loan_buf(buf, 10, true);
buf = create_loan_buf(10, false);
result = dds_return_loan(read_condition, buf, 10);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_OK, "Return loan of size 10 via read-condition entity, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_OK),
dds_err_str(result));
result = dds_return_loan(read_condition, &buf2, 0);
cr_expect_eq(dds_err_nr(result), DDS_RETCODE_OK, "Return empty loan via read-condition entity, Expected(%s) Returned(%s)",
DDS_TO_STRING(DDS_RETCODE_OK),
dds_err_str(result));
delete_loan_buf(buf, 10, true);
}

View file

@ -0,0 +1,111 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
/* We are deliberately testing some bad arguments that SAL will complain about.
* So, silence SAL regarding these issues. */
#pragma warning(push)
#pragma warning(disable: 6387 28020)
static void on_data_available(dds_entity_t reader, void* arg) {}
static void on_publication_matched(dds_entity_t writer, const dds_publication_matched_status_t status, void* arg) {}
Test(ddsc_subscriber, notify_readers) {
dds_entity_t participant;
dds_entity_t subscriber;
dds_return_t ret;
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "Failed to create prerequisite participant");
subscriber = dds_create_subscriber(participant, NULL, NULL);
cr_assert_gt(subscriber, 0, "Failed to create prerequisite subscriber");
/* todo implement tests */
ret = dds_notify_readers(subscriber);
cr_expect_eq(dds_err_nr(ret), DDS_RETCODE_UNSUPPORTED, "Invalid return code %d", ret);
dds_delete(subscriber);
dds_delete(participant);
}
Test(ddsc_subscriber, create) {
dds_entity_t participant;
dds_entity_t subscriber;
dds_listener_t *listener;
dds_qos_t *sqos;
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0, "Failed to create prerequisite participant");
/*** Verify participant parameter ***/
subscriber = dds_create_subscriber(0, NULL, NULL);
cr_assert_eq(dds_err_nr(subscriber), DDS_RETCODE_BAD_PARAMETER, "dds_create_subscriber: invalid participant parameter");
subscriber = dds_create_subscriber(participant, NULL, NULL);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: valid participant parameter");
dds_delete(subscriber);
/*** Verify qos parameter ***/
sqos = dds_qos_create(); /* Use defaults (no user-defined policies) */
subscriber = dds_create_subscriber(participant, sqos, NULL);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: default QoS parameter");
dds_delete(subscriber);
dds_qos_delete(sqos);
sqos = dds_qos_create();
dds_qset_destination_order(sqos, 3); /* Set invalid dest. order (ignored, not applicable for subscriber) */
subscriber = dds_create_subscriber(participant, sqos, NULL);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: invalid non-applicable QoS parameter");
dds_delete(subscriber);
dds_qos_delete(sqos);
sqos = dds_qos_create();
dds_qset_presentation(sqos, 123, 1, 1); /* Set invalid presentation policy */
subscriber = dds_create_subscriber(participant, sqos, NULL);
cr_assert_eq(dds_err_nr(subscriber), DDS_RETCODE_INCONSISTENT_POLICY, "dds_create_subscriber: invalid presentation access_scope QoS parameter");
dds_qos_delete(sqos);
/*** Verify listener parameter ***/
listener = dds_listener_create(NULL); /* Use defaults (all listeners unset) */
subscriber = dds_create_subscriber(participant, NULL, listener);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: unset listeners");
dds_delete(subscriber);
dds_listener_delete(listener);
listener = dds_listener_create(NULL);
dds_lset_data_available(listener, &on_data_available); /* Set on_data_available listener */
subscriber = dds_create_subscriber(participant, NULL, listener);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: on_data_available listener");
dds_delete(subscriber);
dds_listener_delete(listener);
listener = dds_listener_create(NULL);
dds_lset_publication_matched(listener, &on_publication_matched); /* Set on_publication_matched listener (ignored, not applicable for subscriber) */
subscriber = dds_create_subscriber(participant, NULL, listener);
cr_assert_gt(subscriber, 0, "dds_create_subscriber: on_publication_matched listener");
dds_delete(subscriber);
dds_listener_delete(listener);
dds_delete(participant);
}
#pragma warning(pop)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,31 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
const char*
entity_kind_str(dds_entity_t ent) {
if(ent <= 0) {
return "(ERROR)";
}
switch(ent & DDS_ENTITY_KIND_MASK) {
case DDS_KIND_TOPIC: return "Topic";
case DDS_KIND_PARTICIPANT: return "Participant";
case DDS_KIND_READER: return "Reader";
case DDS_KIND_WRITER: return "Writer";
case DDS_KIND_SUBSCRIBER: return "Subscriber";
case DDS_KIND_PUBLISHER: return "Publisher";
case DDS_KIND_COND_READ: return "ReadCondition";
case DDS_KIND_COND_QUERY: return "QueryCondition";
case DDS_KIND_WAITSET: return "WaitSet";
default: return "(INVALID_ENTITY)";
}
}

View file

@ -0,0 +1,17 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#ifndef _TEST_COMMON_H_
#define _TEST_COMMON_H_
const char *entity_kind_str(dds_entity_t ent);
#endif /* _TEST_COMMON_H_ */

428
src/core/ddsc/tests/topic.c Normal file
View file

@ -0,0 +1,428 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include "ddsc/dds.h"
#include "os/os.h"
#include "RoundTrip.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/theories.h>
/**************************************************************************************************
*
* Test fixtures
*
*************************************************************************************************/
static dds_entity_t g_participant = 0;
static dds_entity_t g_topicRtmAddress = 0;
static dds_entity_t g_topicRtmDataType = 0;
static dds_qos_t *g_qos = NULL;
static dds_qos_t *g_qos_null = NULL;
static dds_listener_t *g_listener = NULL;
static dds_listener_t *g_list_null= NULL;
#define MAX_NAME_SIZE (100)
char g_topicRtmAddressName[MAX_NAME_SIZE];
char g_topicRtmDataTypeName[MAX_NAME_SIZE];
char g_nameBuffer[MAX_NAME_SIZE];
static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;
}
static void
ddsc_topic_init(void)
{
create_topic_name("ddsc_topic_test_rtm_address", g_topicRtmAddressName, MAX_NAME_SIZE);
create_topic_name("ddsc_topic_test_rtm_datatype", g_topicRtmDataTypeName, MAX_NAME_SIZE);
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_topicRtmAddress = dds_create_topic(g_participant, &RoundTripModule_Address_desc, g_topicRtmAddressName, NULL, NULL);
cr_assert_gt(g_topicRtmAddress, 0, "Failed to create prerequisite g_topicRtmAddress");
g_topicRtmDataType = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, g_topicRtmDataTypeName, NULL, NULL);
cr_assert_gt(g_topicRtmDataType, 0, "Failed to create prerequisite g_topicRtmDataType");
g_qos = dds_qos_create();
g_listener = dds_listener_create(NULL);
}
static void
ddsc_topic_fini(void)
{
dds_qos_delete(g_qos);
dds_listener_delete(g_listener);
dds_delete(g_topicRtmDataType);
dds_delete(g_topicRtmAddress);
dds_delete(g_participant);
}
/**************************************************************************************************
*
* These will check the topic creation in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_topic_create, valid) = {
DataPoints(char *, "valid", "_VALID", "Val1d", "valid_", "vA_1d"),
DataPoints(dds_qos_t**, &g_qos_null, &g_qos ),
DataPoints(dds_listener_t**, &g_list_null, &g_listener ),
};
Theory((char *name, dds_qos_t **qos, dds_listener_t **listener), ddsc_topic_create, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
dds_return_t ret;
topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, name, *qos, *listener);
cr_assert_gt(topic, 0, "Failed dds_create_topic(par, desc, %s, %p, %p): %s", name, *qos, *listener, dds_err_str(topic));
ret = dds_delete(topic);
cr_assert_eq(ret, DDS_RETCODE_OK);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, invalid_qos, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
dds_qos_t *qos = dds_qos_create();
OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */
dds_qset_lifespan(qos, DDS_SECS(-1));
OS_WARNING_MSVC_OFF(28020);
topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, "inconsistent", qos, NULL);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_INCONSISTENT_POLICY, "returned %s", dds_err_str(topic));
dds_qos_delete(qos);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, non_participants, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
topic = dds_create_topic(g_topicRtmDataType, &RoundTripModule_DataType_desc, "non_participant", NULL, NULL);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_ILLEGAL_OPERATION, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, duplicate, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
/* Creating the same topic should fail. */
topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, g_topicRtmDataTypeName, NULL, NULL);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, same_name, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
/* Creating the different topic with same name should fail. */
topic = dds_create_topic(g_participant, &RoundTripModule_Address_desc, g_topicRtmDataTypeName, NULL, NULL);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, recreate, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
dds_return_t ret;
/* Re-creating previously created topic should succeed. */
ret = dds_delete(g_topicRtmDataType);
cr_assert_eq(ret, DDS_RETCODE_OK);
topic = dds_create_topic (g_participant, &RoundTripModule_DataType_desc, g_topicRtmDataTypeName, NULL, NULL);
cr_assert_gt(topic, 0, "returned %s", dds_err_str(topic));
ret = dds_delete(topic);
cr_assert_eq(ret, DDS_RETCODE_OK);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_create, desc_null, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */
topic = dds_create_topic (g_participant, NULL, "desc_null", NULL, NULL);
OS_WARNING_MSVC_ON(6387);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_BAD_PARAMETER, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_topic_create, invalid_names) = {
DataPoints(char *, NULL, "", "mi-dle", "-start", "end-", "1st", "Thus$", "pl+s", "t(4)"),
};
Theory((char *name), ddsc_topic_create, invalid_names, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, name, NULL, NULL);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_BAD_PARAMETER, "dds_create_topic(%s) returned %s", name, dds_err_str(topic));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the topic finding in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_find, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
dds_return_t ret;
topic = dds_find_topic(g_participant, g_topicRtmDataTypeName);
cr_assert_eq(topic, g_topicRtmDataType, "returned %s", dds_err_str(topic));
ret = dds_delete(topic);
cr_assert_eq(ret, DDS_RETCODE_OK);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_find, non_participants, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
topic = dds_find_topic(g_topicRtmDataType, "non_participant");
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_ILLEGAL_OPERATION, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_find, null, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */
topic = dds_find_topic(g_participant, NULL);
OS_WARNING_MSVC_ON(6387);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_BAD_PARAMETER, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_find, unknown, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
topic = dds_find_topic(g_participant, "unknown");
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_find, deleted, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_entity_t topic;
dds_delete(g_topicRtmDataType);
topic = dds_find_topic(g_participant, g_topicRtmDataTypeName);
cr_assert_eq(dds_err_nr(topic), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %s", dds_err_str(topic));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check getting the topic name in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_name, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[MAX_NAME_SIZE];
dds_return_t ret;
ret = dds_get_name(g_topicRtmDataType, name, MAX_NAME_SIZE);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_str_eq(name, g_topicRtmDataTypeName);
ret = dds_get_name(g_topicRtmAddress, name, MAX_NAME_SIZE);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_str_eq(name, g_topicRtmAddressName);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_name, too_small, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[10];
dds_return_t ret;
ret = dds_get_name(g_topicRtmDataType, name, 10);
cr_assert_eq(ret, DDS_RETCODE_OK);
g_topicRtmDataTypeName[9] = '\0';
cr_assert_str_eq(name, g_topicRtmDataTypeName);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_name, non_topic, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[MAX_NAME_SIZE];
dds_return_t ret;
ret = dds_get_name(g_participant, name, MAX_NAME_SIZE);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_topic_get_name, invalid_params) = {
DataPoints(char*, (char*)0, g_nameBuffer),
DataPoints(size_t, 0, MAX_NAME_SIZE),
};
Theory((char *name, size_t size), ddsc_topic_get_name, invalid_params, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_return_t ret;
cr_assume((name != g_nameBuffer) || (size != MAX_NAME_SIZE));
ret = dds_get_name(g_topicRtmDataType, name, size);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_name, deleted, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[MAX_NAME_SIZE];
dds_return_t ret;
dds_delete(g_topicRtmDataType);
ret = dds_get_name(g_topicRtmDataType, name, MAX_NAME_SIZE);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check getting the type name in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_type_name, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
const char *rtmDataTypeType = "RoundTripModule::DataType";
const char *rtmAddressType = "RoundTripModule::Address";
char name[MAX_NAME_SIZE];
dds_return_t ret;
ret = dds_get_type_name(g_topicRtmDataType, name, MAX_NAME_SIZE);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_str_eq(name, rtmDataTypeType);
ret = dds_get_type_name(g_topicRtmAddress, name, MAX_NAME_SIZE);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_str_eq(name, rtmAddressType);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_type_name, too_small, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
const char *rtmDataTypeType = "RoundTrip";
char name[10];
dds_return_t ret;
ret = dds_get_type_name(g_topicRtmDataType, name, 10);
cr_assert_eq(ret, DDS_RETCODE_OK);
cr_assert_str_eq(name, rtmDataTypeType);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_type_name, non_topic, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[MAX_NAME_SIZE];
dds_return_t ret;
ret = dds_get_type_name(g_participant, name, MAX_NAME_SIZE);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_topic_get_type_name, invalid_params) = {
DataPoints(char*, (char*)0, g_nameBuffer),
DataPoints(size_t, 0, MAX_NAME_SIZE),
};
Theory((char *name, size_t size), ddsc_topic_get_type_name, invalid_params, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_return_t ret;
cr_assume((name != g_nameBuffer) || (size != MAX_NAME_SIZE));
ret = dds_get_type_name(g_topicRtmDataType, name, size);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_get_type_name, deleted, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
char name[MAX_NAME_SIZE];
dds_return_t ret;
dds_delete(g_topicRtmDataType);
ret = dds_get_type_name(g_topicRtmDataType, name, MAX_NAME_SIZE);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will set the topic qos in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_set_qos, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_return_t ret;
/* Latency is the only one allowed to change. */
dds_qset_latency_budget(g_qos, DDS_SECS(1));
ret = dds_set_qos(g_topicRtmDataType, g_qos);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_UNSUPPORTED, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_set_qos, inconsistent, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_return_t ret;
OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */
dds_qset_lifespan(g_qos, DDS_SECS(-1));
OS_WARNING_MSVC_ON(28020);
ret = dds_set_qos(g_topicRtmDataType, g_qos);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_INCONSISTENT_POLICY, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_topic_set_qos, immutable, .init=ddsc_topic_init, .fini=ddsc_topic_fini)
{
dds_return_t ret;
dds_qset_destination_order(g_qos, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP); /* Immutable */
ret = dds_set_qos(g_topicRtmDataType, g_qos);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_IMMUTABLE_POLICY, "returned %s", dds_err_str(ret));
}
/*************************************************************************************************/

View file

@ -0,0 +1,105 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <stdio.h>
#include "ddsc/dds.h"
#include "Space.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#define TRACE_SAMPLE(info, sample) cr_log_info("%s (%d, %d, %d)\n", info, sample.long_1, sample.long_2, sample.long_3);
#define MAX_SAMPLES (7)
Test(ddsc_transient_local, late_joiner)
{
Space_Type1 sample = { 0 };
dds_return_t ret;
dds_entity_t par;
dds_entity_t pub;
dds_entity_t sub;
dds_entity_t top;
dds_entity_t wrt;
dds_entity_t rdr;
dds_qos_t *qos;
static void* samples[MAX_SAMPLES];
static Space_Type1 data[MAX_SAMPLES];
static dds_sample_info_t info[MAX_SAMPLES];
/* Initialize reading buffers. */
memset (data, 0, sizeof (data));
for (int i = 0; i < MAX_SAMPLES; i++) {
samples[i] = &data[i];
}
/* Use transient local with reliable. */
qos = dds_qos_create();
dds_qset_durability(qos, DDS_DURABILITY_TRANSIENT_LOCAL);
dds_qset_reliability(qos, DDS_RELIABILITY_RELIABLE, DDS_INFINITY);
/* Create participant and topic. */
par = dds_create_participant(DDS_DOMAIN_DEFAULT, qos, NULL);
cr_assert_gt(par, 0, "Failed to create prerequisite par");
top = dds_create_topic(par, &Space_Type1_desc, "ddsc_transient_local_happy_days", qos, NULL);
cr_assert_gt(par, 0, "Failed to create prerequisite top");
/* Create publishing entities. */
cr_log_info("Create writer\n");
pub = dds_create_publisher(par, qos, NULL);
cr_assert_gt(pub, 0, "Failed to create prerequisite pub");
wrt = dds_create_writer(pub, top, qos, NULL);
cr_assert_gt(wrt, 0, "Failed to create prerequisite wrt");
/* Write first set of samples. */
sample.long_1 = 1;
sample.long_2 = 1;
sample.long_3 = 1;
TRACE_SAMPLE("Write ", sample);
ret = dds_write(wrt, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
sample.long_1 = 2;
sample.long_2 = 2;
sample.long_3 = 2;
TRACE_SAMPLE("Write ", sample);
ret = dds_write(wrt, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
/* Create subscribing entities. */
cr_log_info("Create reader\n");
sub = dds_create_subscriber(par, qos, NULL);
cr_assert_gt(sub, 0, "Failed to create prerequisite sub");
rdr = dds_create_reader(sub, top, qos, NULL);
cr_assert_gt(rdr, 0, "Failed to create prerequisite g_reader");
/* Write second set of samples. */
sample.long_1 = 8;
sample.long_2 = 8;
sample.long_3 = 8;
TRACE_SAMPLE("Write ", sample);
ret = dds_write(wrt, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
sample.long_1 = 9;
sample.long_2 = 9;
sample.long_3 = 9;
TRACE_SAMPLE("Write ", sample);
ret = dds_write(wrt, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
/* Read samples, which should be all four. */
ret = dds_read(rdr, samples, info, MAX_SAMPLES, MAX_SAMPLES);
cr_log_info("Read cnt %d\n", ret);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)samples[i];
TRACE_SAMPLE("Read ", (*sample));
}
cr_assert_eq(ret, 4, "# read %d, expected 4", ret);
dds_delete(par);
dds_qos_delete(qos);
}

123
src/core/ddsc/tests/types.c Normal file
View file

@ -0,0 +1,123 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include "ddsc/dds.h"
#include "TypesArrayKey.h"
#define strfy(s) #s
#define DDSC_ARRAYTYPEKEY_TEST(type, init) \
do { \
dds_return_t status; \
dds_entity_t par, top, wri; \
TypesArrayKey_##type##_arraytypekey data; \
for( unsigned i = 0; i < (sizeof data.key / sizeof *data.key); i++) data.key[i] = (init); \
\
par = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL); \
cr_assert_gt(par, 0); \
top = dds_create_topic(par, &TypesArrayKey_##type##_arraytypekey_desc, strfy(type), NULL, NULL); \
cr_assert_gt(top, 0); \
wri = dds_create_writer(par, top, NULL, NULL); \
cr_assert_gt(wri, 0); \
\
status = dds_write(wri, &data); \
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK); \
\
dds_delete(wri); \
dds_delete(top); \
dds_delete(par); \
} while (0)
Test(ddsc_types, long_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(long, 1);
}
Test(ddsc_types, longlong_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(longlong, 1);
}
Test(ddsc_types, unsignedshort_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(unsignedshort, 1);
}
Test(ddsc_types, unsignedlong_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(unsignedlong, 1);
}
Test(ddsc_types, unsignedlonglong_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(unsignedlonglong, 1);
}
Test(ddsc_types, float_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(float, 1.0f);
}
Test(ddsc_types, double_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(double, 1.0f);
}
Test(ddsc_types, char_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(char, '1');
}
Test(ddsc_types, boolean_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(boolean, true);
}
Test(ddsc_types, octet_arraytypekey)
{
DDSC_ARRAYTYPEKEY_TEST(octet, 1);
}
Test(ddsc_types, alltypeskey)
{
dds_return_t status;
dds_entity_t par, top, wri;
const TypesArrayKey_alltypeskey atk_data = {
.l = -1,
.ll = -1,
.us = 1,
.ul = 1,
.ull = 1,
.f = 1.0f,
.d = 1.0f,
.c = '1',
.b = true,
.o = 1,
.s = "1"
};
par = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(par, 0);
top = dds_create_topic(par, &TypesArrayKey_alltypeskey_desc, "AllTypesKey", NULL, NULL);
cr_assert_gt(top, 0);
wri = dds_create_writer(par, top, NULL, NULL);
cr_assert_gt(wri, 0);
status = dds_write(wri, &atk_data);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK);
dds_delete(wri);
dds_delete(top);
dds_delete(par);
}

View file

@ -0,0 +1,709 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <assert.h>
#include "ddsc/dds.h"
#include "os/os.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/theories.h>
#include "Space.h"
/**************************************************************************************************
*
* Test fixtures
*
*************************************************************************************************/
#define MAX_SAMPLES 7
#define INITIAL_SAMPLES 2
static dds_entity_t g_participant = 0;
static dds_entity_t g_topic = 0;
static dds_entity_t g_reader = 0;
static dds_entity_t g_writer = 0;
static dds_entity_t g_waitset = 0;
static dds_time_t g_past = 0;
static dds_time_t g_present = 0;
static void* g_samples[MAX_SAMPLES];
static Space_Type1 g_data[MAX_SAMPLES];
static dds_sample_info_t g_info[MAX_SAMPLES];
static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;
}
static void
unregistering_init(void)
{
Space_Type1 sample = { 0 };
dds_qos_t *qos = dds_qos_create ();
dds_attach_t triggered;
dds_return_t ret;
char name[100];
/* Use by source timestamp to be able to check the time related funtions. */
dds_qset_destination_order(qos, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP);
g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(g_participant, 0, "Failed to create prerequisite g_participant");
g_waitset = dds_create_waitset(g_participant);
cr_assert_gt(g_waitset, 0, "Failed to create g_waitset");
g_topic = dds_create_topic(g_participant, &Space_Type1_desc, create_topic_name("ddsc_unregistering_test", name, 100), qos, NULL);
cr_assert_gt(g_topic, 0, "Failed to create prerequisite g_topic");
/* Create a reader that keeps one sample on three instances. */
dds_qset_reliability(qos, DDS_RELIABILITY_RELIABLE, DDS_MSECS(100));
dds_qset_resource_limits(qos, DDS_LENGTH_UNLIMITED, 3, 1);
g_reader = dds_create_reader(g_participant, g_topic, qos, NULL);
cr_assert_gt(g_reader, 0, "Failed to create prerequisite g_reader");
/* Create a writer that will not automatically dispose unregistered samples. */
dds_qset_writer_data_lifecycle(qos, false);
g_writer = dds_create_writer(g_participant, g_topic, qos, NULL);
cr_assert_gt(g_writer, 0, "Failed to create prerequisite g_writer");
/* Sync g_writer to g_reader. */
ret = dds_set_enabled_status(g_writer, DDS_PUBLICATION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_writer status");
ret = dds_waitset_attach(g_waitset, g_writer, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_writer");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_writer r");
cr_assert_eq(g_writer, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_writer a");
ret = dds_waitset_detach(g_waitset, g_writer);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_writer");
/* Sync g_reader to g_writer. */
ret = dds_set_enabled_status(g_reader, DDS_SUBSCRIPTION_MATCHED_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_reader status");
ret = dds_waitset_attach(g_waitset, g_reader, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_reader");
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Failed prerequisite dds_waitset_wait g_reader r");
cr_assert_eq(g_reader, (dds_entity_t)(intptr_t)triggered, "Failed prerequisite dds_waitset_wait g_reader a");
ret = dds_waitset_detach(g_waitset, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to detach prerequisite g_reader");
/* Write initial samples. */
for (int i = 0; i < INITIAL_SAMPLES; i++) {
sample.long_1 = i;
sample.long_2 = i*2;
sample.long_3 = i*3;
ret = dds_write(g_writer, &sample);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed prerequisite write");
}
/* Initialize reading buffers. */
memset (g_data, 0, sizeof (g_data));
for (int i = 0; i < MAX_SAMPLES; i++) {
g_samples[i] = &g_data[i];
}
/* Initialize times. */
g_present = dds_time();
g_past = g_present - DDS_SECS(1);
dds_qos_delete(qos);
}
static void
unregistering_fini(void)
{
dds_delete(g_reader);
dds_delete(g_writer);
dds_delete(g_waitset);
dds_delete(g_topic);
dds_delete(g_participant);
}
#if 0
#else
/**************************************************************************************************
*
* These will check the dds_unregister_instance() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance, deleted, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
dds_delete(g_writer);
ret = dds_unregister_instance(g_writer, g_data);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance, null, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance(g_writer, NULL);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t writer), ddsc_unregister_instance, invalid_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_unregister_instance(writer, g_data);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance, non_writers) = {
DataPoints(dds_entity_t*, &g_waitset, &g_reader, &g_topic, &g_participant),
};
Theory((dds_entity_t *writer), ddsc_unregister_instance, non_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance(*writer, g_data);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance, unregistering_old_instance, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 22, 22 };
dds_return_t ret;
ret = dds_unregister_instance(g_writer, &oldInstance);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 == 0) {
/* Check data. */
cr_assert_eq(sample->long_2, 0);
cr_assert_eq(sample->long_3, 0);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE);
} else if (sample->long_1 == 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_unregister_instance_ts() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ts, deleted, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
dds_delete(g_writer);
ret = dds_unregister_instance_ts(g_writer, g_data, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ts, null, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ts(g_writer, NULL, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ts, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t writer), ddsc_unregister_instance_ts, invalid_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_unregister_instance_ts(writer, g_data, g_present);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ts, non_writers) = {
DataPoints(dds_entity_t*, &g_waitset, &g_reader, &g_topic, &g_participant),
};
Theory((dds_entity_t *writer), ddsc_unregister_instance_ts, non_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ts(*writer, g_data, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ts, unregistering_old_instance, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 22, 22 };
dds_return_t ret;
ret = dds_unregister_instance_ts(g_writer, &oldInstance, g_present);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 == 0) {
/* Check data (data part of unregister is not used, only the key part). */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE);
} else if (sample->long_1 == 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ts, unregistering_past_sample, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 0, 0 };
dds_attach_t triggered;
dds_return_t ret;
/* Unregistering a sample in the past should trigger a lost sample. */
ret = dds_set_enabled_status(g_reader, DDS_SAMPLE_LOST_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_reader status");
ret = dds_waitset_attach(g_waitset, g_reader, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_reader");
/* Now, unregister a sample in the past. */
ret = dds_unregister_instance_ts(g_writer, &oldInstance, g_past);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Wait for 'sample lost'. */
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Unregistering past sample did not trigger 'sample lost'");
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if ((sample->long_1 == 0) || (sample->long_1 == 1)) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_unregister_instance_ih() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ih, deleted, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
dds_delete(g_writer);
ret = dds_unregister_instance_ih(g_writer, DDS_HANDLE_NIL);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih, invalid_handles) = {
DataPoints(dds_instance_handle_t, DDS_HANDLE_NIL, 0, 1, 100, UINT64_MAX),
};
Theory((dds_instance_handle_t handle), ddsc_unregister_instance_ih, invalid_handles, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ih(g_writer, handle);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t writer), ddsc_unregister_instance_ih, invalid_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_unregister_instance_ih(writer, DDS_HANDLE_NIL);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih, non_writers) = {
DataPoints(dds_entity_t*, &g_waitset, &g_reader, &g_topic, &g_participant),
};
Theory((dds_entity_t *writer), ddsc_unregister_instance_ih, non_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ih(*writer, DDS_HANDLE_NIL);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ih, unregistering_old_instance, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 22, 22 };
dds_instance_handle_t hdl = dds_instance_lookup(g_writer, &oldInstance);
dds_return_t ret;
ret = dds_unregister_instance_ih(g_writer, hdl);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 == 0) {
/* Check data. */
cr_assert_eq(sample->long_2, 0);
cr_assert_eq(sample->long_3, 0);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE);
} else if (sample->long_1 == 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/**************************************************************************************************
*
* These will check the dds_unregister_instance_ih_ts() in various ways.
*
*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ih_ts, deleted, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
dds_delete(g_writer);
ret = dds_unregister_instance_ih_ts(g_writer, DDS_HANDLE_NIL, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih_ts, invalid_handles) = {
DataPoints(dds_instance_handle_t, DDS_HANDLE_NIL, 0, 1, 100, UINT64_MAX),
};
Theory((dds_instance_handle_t handle), ddsc_unregister_instance_ih_ts, invalid_handles, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ih_ts(g_writer, handle, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_PRECONDITION_NOT_MET, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih_ts, invalid_writers) = {
DataPoints(dds_entity_t, -2, -1, 0, 1, 100, INT_MAX, INT_MIN),
};
Theory((dds_entity_t writer), ddsc_unregister_instance_ih_ts, invalid_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1;
dds_return_t ret;
ret = dds_unregister_instance_ih_ts(writer, DDS_HANDLE_NIL, g_present);
cr_assert_eq(dds_err_nr(ret), dds_err_nr(exp), "returned %d != expected %d", dds_err_nr(ret), dds_err_nr(exp));
}
/*************************************************************************************************/
/*************************************************************************************************/
TheoryDataPoints(ddsc_unregister_instance_ih_ts, non_writers) = {
DataPoints(dds_entity_t*, &g_waitset, &g_reader, &g_topic, &g_participant),
};
Theory((dds_entity_t *writer), ddsc_unregister_instance_ih_ts, non_writers, .init=unregistering_init, .fini=unregistering_fini)
{
dds_return_t ret;
ret = dds_unregister_instance_ih_ts(*writer, DDS_HANDLE_NIL, g_present);
cr_assert_eq(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION, "returned %d", dds_err_nr(ret));
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ih_ts, unregistering_old_instance, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 22, 22 };
dds_instance_handle_t hdl = dds_instance_lookup(g_writer, &oldInstance);
dds_return_t ret;
ret = dds_unregister_instance_ih_ts(g_writer, hdl, g_present);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 == 0) {
/* Check data (data part of unregister is not used, only the key part). */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE);
} else if (sample->long_1 == 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ih_ts, unregistering_past_sample, .init=unregistering_init, .fini=unregistering_fini)
{
Space_Type1 oldInstance = { 0, 0, 0 };
dds_instance_handle_t hdl = dds_instance_lookup(g_writer, &oldInstance);
dds_attach_t triggered;
dds_return_t ret;
/* Unregistering a sample in the past should trigger a lost sample. */
ret = dds_set_enabled_status(g_reader, DDS_SAMPLE_LOST_STATUS);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to set prerequisite g_reader status");
ret = dds_waitset_attach(g_waitset, g_reader, g_reader);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed to attach prerequisite g_reader");
/* Now, unregister a sample in the past. */
ret = dds_unregister_instance_ih_ts(g_writer, hdl, g_past);
cr_assert_eq(ret, DDS_RETCODE_OK, "Unregistering old instance returned %d", dds_err_nr(ret));
/* Wait for 'sample lost'. */
ret = dds_waitset_wait(g_waitset, &triggered, 1, DDS_SECS(1));
cr_assert_eq(ret, 1, "Unregistering past sample did not trigger 'sample lost'");
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 2, "# read %d, expected %d", ret, 2);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if ((sample->long_1 == 0) || (sample->long_1 == 1)) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
} else {
cr_assert(false, "Unknown sample read");
}
}
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance, dispose_unregistered_sample, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t writer;
writer = dds_create_writer(g_participant, g_topic, NULL, NULL);
cr_assert_gt(g_writer, 0, "Failed to create writer");
Space_Type1 newInstance = { INITIAL_SAMPLES, 0, 0 };
dds_return_t ret;
ret = dds_write(writer, &newInstance);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed write");
ret = dds_unregister_instance(writer, &newInstance);
cr_assert_eq(ret, DDS_RETCODE_OK, "Disposing unregistered sample returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 3, "# read %d, expected %d", ret, 3);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 <= 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else if (sample->long_1 == 2) {
/* Check data. */
cr_assert_eq(sample->long_2, 0);
cr_assert_eq(sample->long_3, 0);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
dds_delete(writer);
}
/*************************************************************************************************/
/*************************************************************************************************/
Test(ddsc_unregister_instance_ts, dispose_unregistered_sample, .init=unregistering_init, .fini=unregistering_fini)
{
dds_entity_t writer;
writer = dds_create_writer(g_participant, g_topic, NULL, NULL);
cr_assert_gt(g_writer, 0, "Failed to create writer");
Space_Type1 newInstance = { INITIAL_SAMPLES, 0, 0 };
dds_return_t ret;
ret = dds_write(writer, &newInstance);
cr_assert_eq(ret, DDS_RETCODE_OK, "Failed write");
ret = dds_unregister_instance(writer, &newInstance);
cr_assert_eq(ret, DDS_RETCODE_OK, "Disposing unregistered sample returned %d", dds_err_nr(ret));
/* Read all available samples. */
ret = dds_read(g_reader, g_samples, g_info, MAX_SAMPLES, MAX_SAMPLES);
cr_assert_eq(ret, 3, "# read %d, expected %d", ret, 3);
for(int i = 0; i < ret; i++) {
Space_Type1 *sample = (Space_Type1*)g_samples[i];
if (sample->long_1 <= 1) {
/* Check data. */
cr_assert_eq(sample->long_2, sample->long_1 * 2);
cr_assert_eq(sample->long_3, sample->long_1 * 3);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_ALIVE_INSTANCE_STATE);
} else if (sample->long_1 == 2) {
/* Check data. */
cr_assert_eq(sample->long_2, 0);
cr_assert_eq(sample->long_3, 0);
/* Check states. */
cr_assert_eq(g_info[i].valid_data, true);
cr_assert_eq(g_info[i].sample_state, DDS_SST_NOT_READ);
cr_assert_eq(g_info[i].view_state, DDS_VST_NEW);
cr_assert_eq(g_info[i].instance_state, DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE);
} else {
cr_assert(false, "Unknown sample read");
}
}
dds_delete(writer);
}
/*************************************************************************************************/
#endif

View file

@ -0,0 +1,182 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <criterion/parameterized.h>
#include "ddsc/dds.h"
#include "RoundTrip.h"
#include "test-common.h"
static dds_entity_t e[8];
#define PAR (0) /* Participant */
#define TOP (1) /* Topic */
#define PUB (2) /* Publisher */
#define WRI (3) /* Writer */
#define SUB (4) /* Subscriber */
#define REA (5) /* Reader */
#define RCD (6) /* ReadCondition */
#define BAD (7) /* Bad (non-entity) */
static void
setup(void)
{
e[PAR] = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(e[PAR], 0);
e[TOP] = dds_create_topic(e[PAR], &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
cr_assert_gt(e[TOP], 0);
e[PUB] = dds_create_publisher(e[PAR], NULL, NULL);
cr_assert_gt(e[PUB], 0);
e[WRI] = dds_create_writer(e[PUB], e[TOP], NULL, NULL);
cr_assert_gt(e[WRI], 0);
e[SUB] = dds_create_subscriber(e[PAR], NULL, NULL);
cr_assert_gt(e[SUB], 0);
e[REA] = dds_create_reader(e[SUB], e[TOP], NULL, NULL);
cr_assert_gt(e[REA], 0);
e[RCD] = dds_create_readcondition(e[REA], DDS_ANY_STATE);
cr_assert_gt(e[RCD], 0);
e[BAD] = 1;
}
static void
teardown(void)
{
for(unsigned i = (sizeof e / sizeof *e); i > 0; i--) {
dds_delete(e[i - 1]);
}
}
/*************************************************************************************************/
struct index_result {
unsigned index;
dds_return_t exp_res;
};
/*************************************************************************************************/
ParameterizedTestParameters(ddsc_unsupported, dds_begin_end_coherent) {
/* The parameters seem to be initialized before spawning children,
* so it makes no sense to try and store anything dynamic here. */
static struct index_result pars[] = {
{PUB, DDS_RETCODE_UNSUPPORTED},
{WRI, DDS_RETCODE_UNSUPPORTED},
{SUB, DDS_RETCODE_UNSUPPORTED},
{REA, DDS_RETCODE_UNSUPPORTED},
{BAD, DDS_RETCODE_BAD_PARAMETER}
};
return cr_make_param_array(struct index_result, pars, sizeof pars / sizeof *pars);
};
ParameterizedTest(struct index_result *par, ddsc_unsupported, dds_begin_end_coherent, .init = setup, .fini = teardown)
{
dds_return_t result;
result = dds_begin_coherent(e[par->index]);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_begin_coherent(%s): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
result = dds_end_coherent(e[par->index]);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_end_coherent(%s): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
}
/*************************************************************************************************/
ParameterizedTestParameters(ddsc_unsupported, dds_wait_for_acks) {
static struct index_result pars[] = {
{PUB, DDS_RETCODE_UNSUPPORTED},
{WRI, DDS_RETCODE_UNSUPPORTED},
{BAD, DDS_RETCODE_BAD_PARAMETER}
};
return cr_make_param_array(struct index_result, pars, sizeof pars / sizeof *pars);
};
ParameterizedTest(struct index_result *par, ddsc_unsupported, dds_wait_for_acks, .init = setup, .fini = teardown)
{
dds_return_t result;
result = dds_wait_for_acks(e[par->index], 0);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_wait_for_acks(%s, 0): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
}
/*************************************************************************************************/
ParameterizedTestParameters(ddsc_unsupported, dds_suspend_resume) {
static struct index_result pars[] = {
{PUB, DDS_RETCODE_UNSUPPORTED},
{WRI, DDS_RETCODE_BAD_PARAMETER},
{BAD, DDS_RETCODE_BAD_PARAMETER}
};
return cr_make_param_array(struct index_result, pars, sizeof pars / sizeof *pars);
};
ParameterizedTest(struct index_result *par, ddsc_unsupported, dds_suspend_resume, .init = setup, .fini = teardown)
{
dds_return_t result;
result = dds_suspend(e[par->index]);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_suspend(%s): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
result = dds_resume(e[par->index]);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_resume(%s): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
}
/*************************************************************************************************/
ParameterizedTestParameters(ddsc_unsupported, dds_get_instance_handle) {
/* The parameters seem to be initialized before spawning children,
* so it makes no sense to try and store anything dynamic here. */
static struct index_result pars[] = {
{TOP, DDS_RETCODE_ILLEGAL_OPERATION}, /* TODO: Shouldn't this be either supported or unsupported? */
{PUB, DDS_RETCODE_UNSUPPORTED},
{SUB, DDS_RETCODE_UNSUPPORTED},
{RCD, DDS_RETCODE_ILLEGAL_OPERATION},
{BAD, DDS_RETCODE_BAD_PARAMETER}
};
return cr_make_param_array(struct index_result, pars, sizeof pars / sizeof *pars);
};
ParameterizedTest(struct index_result *par, ddsc_unsupported, dds_get_instance_handle, .init = setup, .fini = teardown)
{
dds_return_t result;
dds_instance_handle_t ih;
result = dds_get_instance_handle(e[par->index], &ih);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_get_instance_handle(%s): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
}
/*************************************************************************************************/
ParameterizedTestParameters(ddsc_unsupported, dds_set_qos) {
/* The parameters seem to be initialized before spawning children,
* so it makes no sense to try and store anything dynamic here. */
static struct index_result pars[] = {
{PAR, DDS_RETCODE_UNSUPPORTED},
{TOP, DDS_RETCODE_UNSUPPORTED},
{PUB, DDS_RETCODE_UNSUPPORTED},
{WRI, DDS_RETCODE_UNSUPPORTED},
{SUB, DDS_RETCODE_UNSUPPORTED},
{REA, DDS_RETCODE_UNSUPPORTED},
{RCD, DDS_RETCODE_ILLEGAL_OPERATION},
{BAD, DDS_RETCODE_BAD_PARAMETER}
};
return cr_make_param_array(struct index_result, pars, sizeof pars / sizeof *pars);
};
ParameterizedTest(struct index_result *par, ddsc_unsupported, dds_set_qos, .init = setup, .fini = teardown)
{
dds_return_t result;
dds_qos_t *qos;
qos = dds_qos_create();
result = dds_set_qos(e[par->index], qos);
cr_expect_eq(dds_err_nr(result), par->exp_res, "Unexpected return code %d \"%s\" (expected %d \"%s\") from dds_set_qos(%s, qos): (%d)", dds_err_nr(result), dds_err_str(result), par->exp_res, dds_err_str(-par->exp_res), entity_kind_str(e[par->index]), result);
dds_qos_delete(qos);
}

File diff suppressed because it is too large Load diff

160
src/core/ddsc/tests/write.c Normal file
View file

@ -0,0 +1,160 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include "ddsc/dds.h"
#include "RoundTrip.h"
#include "Space.h"
#include "os/os.h"
/* Tests in this file only concern themselves with very basic api tests of
dds_write and dds_write_ts */
static const int payloadSize = 32;
static RoundTripModule_DataType data = { 0 };
static dds_entity_t participant = 0;
static dds_entity_t topic = 0;
static dds_entity_t publisher = 0;
static dds_entity_t writer = 0;
static void
setup(void)
{
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
cr_assert_gt(topic, 0);
publisher = dds_create_publisher(participant, NULL, NULL);
cr_assert_gt(publisher, 0);
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
memset(&data, 0, sizeof(data));
data.payload._length = payloadSize;
data.payload._buffer = dds_alloc (payloadSize);
memset(data.payload._buffer, 'a', payloadSize);
data.payload._release = true;
data.payload._maximum = 0;
}
static void
teardown(void)
{
RoundTripModule_DataType_free (&data, DDS_FREE_CONTENTS);
memset(&data, 0, sizeof(data));
dds_delete(writer);
dds_delete(publisher);
dds_delete(topic);
dds_delete(participant);
}
Test(ddsc_write, basic, .init = setup, .fini = teardown)
{
dds_return_t status;
status = dds_write(writer, &data);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK);
}
Test(ddsc_write, null_writer, .init = setup, .fini = teardown)
{
dds_return_t status;
/* Disable warning related to improper API usage by passing incompatible parameter. */
OS_WARNING_MSVC_OFF(28020);
status = dds_write(0, &data);
OS_WARNING_MSVC_ON(28020);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_BAD_PARAMETER);
}
Test(ddsc_write, bad_writer, .init = setup, .fini = teardown)
{
dds_return_t status;
status = dds_write(publisher, &data);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_ILLEGAL_OPERATION);
}
Test(ddsc_write, closed_writer, .init = setup, .fini = teardown)
{
dds_return_t status;
status = dds_delete(writer);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK);
status = dds_write(writer, &data);
writer = 0;
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_ALREADY_DELETED);
}
Test(ddsc_write, null_sample, .init = setup, .fini = teardown)
{
dds_return_t status;
/* Disable warning related to improper API usage by passing NULL to a non-NULL parameter. */
OS_WARNING_MSVC_OFF(6387);
status = dds_write(writer, NULL);
OS_WARNING_MSVC_ON(6387);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_BAD_PARAMETER);
}
Test(ddsc_write_ts, basic, .init = setup, .fini = teardown)
{
dds_return_t status;
status = dds_write_ts(writer, &data, dds_time());
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK);
}
Test(ddsc_write_ts, bad_timestamp, .init = setup, .fini = teardown)
{
dds_return_t status;
status = dds_write_ts(writer, &data, -1);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_BAD_PARAMETER);
}
Test(ddsc_write, simpletypes)
{
dds_return_t status;
dds_entity_t par, top, wri;
const Space_simpletypes st_data = {
.l = -1,
.ll = -1,
.us = 1,
.ul = 1,
.ull = 1,
.f = 1.0f,
.d = 1.0f,
.c = '1',
.b = true,
.o = 1,
.s = "This string is exactly so long that it would previously trigger CHAM-405. If this string is shortened exactly one character, all is well. Since it is fixed now, there doesn't need to be any further investigation."
};
par = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(par, 0);
top = dds_create_topic(par, &Space_simpletypes_desc, "SimpleTypes", NULL, NULL);
cr_assert_gt(top, 0);
wri = dds_create_writer(par, top, NULL, NULL);
cr_assert_gt(wri, 0);
status = dds_write(wri, &st_data);
cr_assert_eq(dds_err_nr(status), DDS_RETCODE_OK);
dds_delete(wri);
dds_delete(top);
dds_delete(par);
}

View file

@ -0,0 +1,110 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited 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
*/
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include "ddsc/dds.h"
#include "RoundTrip.h"
#include "os/os.h"
static dds_entity_t participant = 0;
static dds_entity_t topic = 0;
static dds_entity_t publisher = 0;
static dds_entity_t writer = 0;
static void
setup(void)
{
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
cr_assert_gt(participant, 0);
topic = dds_create_topic(participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
cr_assert_gt(topic, 0);
publisher = dds_create_publisher(participant, NULL, NULL);
cr_assert_gt(publisher, 0);
}
static void
teardown(void)
{
dds_delete(writer);
dds_delete(publisher);
dds_delete(topic);
dds_delete(participant);
}
Test(ddsc_create_writer, basic, .init = setup, .fini = teardown)
{
dds_return_t result;
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
result = dds_delete(writer);
cr_assert_eq(result, DDS_RETCODE_OK);
}
Test(ddsc_create_writer, null_parent, .init = setup, .fini = teardown)
{
OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */
writer = dds_create_writer(0, topic, NULL, NULL);
OS_WARNING_MSVC_ON(28020);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_BAD_PARAMETER);
}
Test(ddsc_create_writer, bad_parent, .init = setup, .fini = teardown)
{
writer = dds_create_writer(topic, topic, NULL, NULL);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_ILLEGAL_OPERATION);
}
Test(ddsc_create_writer, participant, .init = setup, .fini = teardown)
{
writer = dds_create_writer(participant, topic, NULL, NULL);
cr_assert_gt(writer, 0);
}
Test(ddsc_create_writer, publisher, .init = setup, .fini = teardown)
{
writer = dds_create_writer(publisher, topic, NULL, NULL);
cr_assert_gt(writer, 0);
}
Test(ddsc_create_writer, deleted_publisher, .init = setup, .fini = teardown)
{
dds_delete(publisher);
writer = dds_create_writer(publisher, topic, NULL, NULL);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_ALREADY_DELETED);
}
Test(ddsc_create_writer, null_topic, .init = setup, .fini = teardown)
{
OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */
writer = dds_create_writer(publisher, 0, NULL, NULL);
OS_WARNING_MSVC_ON(28020);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_BAD_PARAMETER);
}
Test(ddsc_create_writer, bad_topic, .init = setup, .fini = teardown)
{
writer = dds_create_writer(publisher, publisher, NULL, NULL);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_ILLEGAL_OPERATION);
}
Test(ddsc_create_writer, deleted_topic, .init = setup, .fini = teardown)
{
dds_delete(topic);
writer = dds_create_writer(publisher, topic, NULL, NULL);
cr_assert_eq(dds_err_nr(writer), DDS_RETCODE_ALREADY_DELETED);
}