cyclonedds/src/ddsrt/tests/string.c

96 lines
3.6 KiB
C
Raw Normal View History

Rearrange and fixup abstraction layer - Replace os_result by dds_retcode_t and move DDS return code defines down. Eliminates the need to convert between different return code types. - Move dds_time_t down and remove os_time. Eliminates the need to convert between different time representations and reduces code duplication. - Remove use of Microsoft source-code annotation language (SAL). SAL annotations are Microsoft specific and not very well documented. This makes it very difficult for contributers to write. - Rearrange the abstraction layer to be feature-based. The previous layout falsely assumed that the operating system dictates which implementation is best suited. For general purpose operating systems this is mostly true, but embedded targets require a slightly different approach and may not even offer all features. The new layout makes it possible to mix-and-match feature implementations and allows for features to not be implemented at all. - Replace the os prefix by ddsrt to avoid name collisions. - Remove various portions of unused and unwanted code. - Export thread names on all supported platforms. - Return native thread identifier on POSIX compatible platforms. - Add timed wait for condition variables that takes an absolute time. - Remove system abstraction for errno. The os_getErrno and os_setErrno were incorrect. Functions that might fail now simply return a DDS return code instead. - Remove thread-specific memory abstraction. os_threadMemGet and accompanying functions were a mess and their use has been eliminated by other changes in this commit. - Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name collisions and problems with faulty __nonnull__ attributes. Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
2019-01-18 14:10:19 +01:00
/*
* 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 <assert.h>
Rearrange and fixup abstraction layer - Replace os_result by dds_retcode_t and move DDS return code defines down. Eliminates the need to convert between different return code types. - Move dds_time_t down and remove os_time. Eliminates the need to convert between different time representations and reduces code duplication. - Remove use of Microsoft source-code annotation language (SAL). SAL annotations are Microsoft specific and not very well documented. This makes it very difficult for contributers to write. - Rearrange the abstraction layer to be feature-based. The previous layout falsely assumed that the operating system dictates which implementation is best suited. For general purpose operating systems this is mostly true, but embedded targets require a slightly different approach and may not even offer all features. The new layout makes it possible to mix-and-match feature implementations and allows for features to not be implemented at all. - Replace the os prefix by ddsrt to avoid name collisions. - Remove various portions of unused and unwanted code. - Export thread names on all supported platforms. - Return native thread identifier on POSIX compatible platforms. - Add timed wait for condition variables that takes an absolute time. - Remove system abstraction for errno. The os_getErrno and os_setErrno were incorrect. Functions that might fail now simply return a DDS return code instead. - Remove thread-specific memory abstraction. os_threadMemGet and accompanying functions were a mess and their use has been eliminated by other changes in this commit. - Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name collisions and problems with faulty __nonnull__ attributes. Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
2019-01-18 14:10:19 +01:00
#include "CUnit/Theory.h"
#include "dds/ddsrt/heap.h"
Rearrange and fixup abstraction layer - Replace os_result by dds_retcode_t and move DDS return code defines down. Eliminates the need to convert between different return code types. - Move dds_time_t down and remove os_time. Eliminates the need to convert between different time representations and reduces code duplication. - Remove use of Microsoft source-code annotation language (SAL). SAL annotations are Microsoft specific and not very well documented. This makes it very difficult for contributers to write. - Rearrange the abstraction layer to be feature-based. The previous layout falsely assumed that the operating system dictates which implementation is best suited. For general purpose operating systems this is mostly true, but embedded targets require a slightly different approach and may not even offer all features. The new layout makes it possible to mix-and-match feature implementations and allows for features to not be implemented at all. - Replace the os prefix by ddsrt to avoid name collisions. - Remove various portions of unused and unwanted code. - Export thread names on all supported platforms. - Return native thread identifier on POSIX compatible platforms. - Add timed wait for condition variables that takes an absolute time. - Remove system abstraction for errno. The os_getErrno and os_setErrno were incorrect. Functions that might fail now simply return a DDS return code instead. - Remove thread-specific memory abstraction. os_threadMemGet and accompanying functions were a mess and their use has been eliminated by other changes in this commit. - Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name collisions and problems with faulty __nonnull__ attributes. Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
2019-01-18 14:10:19 +01:00
#include "dds/ddsrt/string.h"
typedef enum { eq, lt, gt } eq_t;
CU_TheoryDataPoints(ddsrt_strcasecmp, basic) = {
CU_DataPoints(const char *, "a", "aa", "a", "a", "A", "a", "b", "a", "B", "A", "", "a"),
CU_DataPoints(const char *, "a", "a", "aa", "A", "a", "b", "a", "b", "A", "B", "a", ""),
CU_DataPoints(eq_t, eq, gt, lt, eq, eq, lt, gt, lt, gt, lt, lt, gt)
};
CU_Theory((const char *s1, const char *s2, eq_t e), ddsrt_strcasecmp, basic)
{
int r = ddsrt_strcasecmp(s1, s2);
CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0));
}
CU_TheoryDataPoints(ddsrt_strncasecmp, basic) = {
CU_DataPoints(const char *, "a", "aa", "a", "A", "a", "b", "a", "B", "A", "", "a"),
CU_DataPoints(const char *, "a", "a", "aa", "a", "A", "a", "b", "A", "B", "a", ""),
CU_DataPoints(size_t, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1),
CU_DataPoints(eq_t, eq, gt, lt, eq, eq, gt, lt, gt, lt, lt, gt)
};
CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, basic)
{
int r = ddsrt_strncasecmp(s1, s2, n);
CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0));
}
CU_TheoryDataPoints(ddsrt_strncasecmp, empty) = {
CU_DataPoints(const char *, "a", "", "a", "", "a", ""),
CU_DataPoints(const char *, "", "a", "", "a", "", "a"),
CU_DataPoints(size_t, 1, 1, 0, 0, 2, 2),
CU_DataPoints(eq_t, gt, lt, eq, eq, gt, lt)
};
CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, empty)
{
int r = ddsrt_strncasecmp(s1, s2, n);
CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0));
}
CU_TheoryDataPoints(ddsrt_strncasecmp, length) = {
CU_DataPoints(const char *, "aBcD", "AbCX", "aBcD", "AbCX", "aBcD"),
CU_DataPoints(const char *, "AbCX", "aBcD", "AbCX", "aBcD", "AbCd"),
CU_DataPoints(size_t, 3, 3, 4, 4, 5, 5),
CU_DataPoints(eq_t, eq, eq, lt, gt, eq, eq)
};
CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, length)
{
int r = ddsrt_strncasecmp(s1, s2, n);
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);
assert(r != NULL); /* for Clang static analyzer */
CU_ASSERT(strcmp(r, exp) == 0);
ddsrt_free(r);
}
else
{
CU_ASSERT_FATAL(r == NULL);
}
}