Add string functions used by security plugins to ddsrt (#334)

* String functions required by DDS Security Access Control plugin

The implementation for the DDS Security Access Control plugin
requires two additional string functions. This commit adds the
ddsrt_str_replace function (including tests) and exports the
existing function ddsrt_todigit.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Suppress strcpy warnings in Windows builds for ddsrt_str_replace

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Minor nitpicks on ddsrt_str_replace

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Dennis Potman 2019-12-04 10:22:40 +01:00 committed by eboasson
parent e2afccf4a0
commit 37c64e0965
5 changed files with 97 additions and 1 deletions

View file

@ -12,6 +12,7 @@
#include <string.h>
#include "CUnit/Theory.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsrt/string.h"
typedef enum { eq, lt, gt } eq_t;
@ -67,3 +68,26 @@ CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp,
CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0));
}
CU_TheoryDataPoints(ddsrt_str_replace, basic) = {
CU_DataPoints(const char *, "", "a", "aaa", "aaa", "aaa", "aaa", "a", "aa", "acaca", "aacaacaa", "aaa"),
CU_DataPoints(const char *, "a", "", "a", "a", "a", "aa", "aaa", "a", "a", "aa", "a"),
CU_DataPoints(const char *, "b", "b", "b", "bb", "bb", "b", "b", "b", "bb", "b", ""),
CU_DataPoints(size_t, 0, 0, 0, 1, 2, 0, 0, 10, 0, 2, 0),
CU_DataPoints(const char *, "", NULL, "bbb", "bbaa", "bbbba", "ba", "a", "bb", "bbcbbcbb", "bcbcaa", ""),
};
CU_Theory((const char *str, const char *srch, const char *subst, size_t max, const char * exp), ddsrt_str_replace, basic)
{
char * r = ddsrt_str_replace(str, srch, subst, max);
if (exp != NULL)
{
CU_ASSERT_FATAL(r != NULL);
CU_ASSERT(strcmp(r, exp) == 0);
ddsrt_free(r);
}
else
{
CU_ASSERT_FATAL(r == NULL);
}
}