From 8aa6ceff81b50526e957c6c95697784bb0722055 Mon Sep 17 00:00:00 2001 From: Firas Sahli Date: Thu, 22 Nov 2018 16:43:42 +0100 Subject: [PATCH] Add test for dds_qos_copy and extra check to dds_qset_partition Signed-off-by: Firas Sahli --- src/core/ddsc/src/dds_qos.c | 10 +++++----- src/core/ddsc/tests/qos.c | 40 ++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/core/ddsc/src/dds_qos.c b/src/core/ddsc/src/dds_qos.c index fe1418f..d26f9c9 100644 --- a/src/core/ddsc/src/dds_qos.c +++ b/src/core/ddsc/src/dds_qos.c @@ -493,11 +493,11 @@ void dds_qset_partition } if (qos->partition.strs != NULL){ - for (i = 0; i < qos->partition.n; i++) { - dds_free(qos->partition.strs[i]); - } - dds_free(qos->partition.strs); - qos->partition.strs = NULL; + for (i = 0; i < qos->partition.n; i++) { + dds_free(qos->partition.strs[i]); + } + dds_free(qos->partition.strs); + qos->partition.strs = NULL; } qos->partition.n = n; diff --git a/src/core/ddsc/tests/qos.c b/src/core/ddsc/tests/qos.c index a96ee06..9fdae7e 100644 --- a/src/core/ddsc/tests/qos.c +++ b/src/core/ddsc/tests/qos.c @@ -14,7 +14,6 @@ #include #include - /* We are deliberately testing some bad arguments that SAL will complain about. * So, silence SAL regarding these issues. */ #ifdef _MSC_VER @@ -240,6 +239,45 @@ qos_fini(void) /**************************************************************************** * API tests ****************************************************************************/ +Test(ddsc_qos, copy_bad_source, .init=qos_init, .fini=qos_fini) +{ + dds_return_t result; + + result = dds_qos_copy(g_qos, NULL); + cr_assert_eq(dds_err_nr(result), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(result)); +} + +Test(ddsc_qos, copy_bad_destination, .init=qos_init, .fini=qos_fini) +{ + dds_return_t result; + + result = dds_qos_copy(NULL, g_qos); + cr_assert_eq(dds_err_nr(result), DDS_RETCODE_BAD_PARAMETER, "returned %d", dds_err_nr(result)); +} + +Test(ddsc_qos, copy_with_partition, .init=qos_init, .fini=qos_fini) +{ + dds_return_t result; + dds_qos_t *qos; + struct pol_partition p = { 0, NULL }; + + qos = dds_qos_create(); + cr_assert_not_null(qos); + + dds_qset_partition(g_qos, g_pol_partition.n, g_pol_partition.ps); + result = dds_qos_copy(qos, g_qos); + + cr_assert_eq(result, DDS_RETCODE_OK); + dds_qget_partition(qos, &p.n, &p.ps); + cr_assert_eq(p.n, g_pol_partition.n); + + for (uint32_t cnt = 0; cnt < p.n; cnt++) { + cr_assert_str_eq(p.ps[cnt], g_pol_partition.ps[cnt]); + } + + dds_qos_delete(qos); +} + Test(ddsc_qos, userdata, .init=qos_init, .fini=qos_fini) { struct pol_userdata p = { NULL, 0 };