Fix off-by-one error in dds_strretcode (#270)

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-10-09 15:52:30 +02:00 committed by eboasson
parent 5a746cad81
commit f8bff97736
4 changed files with 81 additions and 16 deletions

View file

@ -24,6 +24,7 @@ list(APPEND sources
"string.c"
"log.c"
"random.c"
"retcode.c"
"strlcpy.c"
"socket.c"
"select.c")

59
src/ddsrt/tests/retcode.c Normal file
View file

@ -0,0 +1,59 @@
/*
* 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 <string.h>
#include "CUnit/Theory.h"
#include "dds/ddsrt/retcode.h"
CU_TheoryDataPoints(ddsrt_retcode, unknown) = {
CU_DataPoints(dds_return_t,
DDS_RETCODE_NOT_ALLOWED_BY_SECURITY-1,
-(DDS_RETCODE_NOT_ALLOWED_BY_SECURITY-1),
DDS_XRETCODE_BASE,
-DDS_XRETCODE_BASE,
DDS_RETCODE_NOT_FOUND-1,
-(DDS_RETCODE_NOT_FOUND-1),
INT32_MAX,
-INT32_MAX,
INT32_MIN)
};
CU_Theory((dds_return_t ret), ddsrt_retcode, unknown)
{
CU_ASSERT_STRING_EQUAL(dds_strretcode(ret), "Unknown return code");
}
CU_TheoryDataPoints(ddsrt_retcode, spotchecks) = {
CU_DataPoints(dds_return_t,
DDS_RETCODE_OK,
-DDS_RETCODE_OK,
DDS_RETCODE_NOT_ALLOWED_BY_SECURITY,
-DDS_RETCODE_NOT_ALLOWED_BY_SECURITY,
DDS_RETCODE_IN_PROGRESS,
-DDS_RETCODE_IN_PROGRESS,
DDS_RETCODE_NOT_FOUND,
-DDS_RETCODE_NOT_FOUND),
CU_DataPoints(const char *,
"Success",
"Success",
"Not Allowed By Security",
"Not Allowed By Security",
"Operation in progress",
"Operation in progress",
"Not found",
"Not found")
};
CU_Theory((dds_return_t ret, const char *exp), ddsrt_retcode, spotchecks)
{
CU_ASSERT_STRING_EQUAL(dds_strretcode(ret), exp);
}