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>
This commit is contained in:
parent
318968f40f
commit
cd6742ee12
439 changed files with 22117 additions and 28782 deletions
101
src/ddsrt/tests/string.c
Normal file
101
src/ddsrt/tests/string.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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/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_Test(ddsrt_string, strtok_r)
|
||||
{
|
||||
char *res;
|
||||
char *saveptr;
|
||||
char ts1[] = "123,234";
|
||||
char ts2[] = ",;,123abc,,456,:,";
|
||||
char ts3[] = ",,,123,,456,789,,,";
|
||||
|
||||
res = ddsrt_strtok_r(ts1, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "123") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "234") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",", &saveptr);
|
||||
CU_ASSERT(res == NULL);
|
||||
|
||||
res = ddsrt_strtok_r(ts2, ",;", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "123abc") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "456") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",:", &saveptr);
|
||||
CU_ASSERT(res == NULL);
|
||||
|
||||
res = ddsrt_strtok_r(ts3, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "123") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "456") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",", &saveptr);
|
||||
CU_ASSERT(strcmp(res, "789") == 0);
|
||||
res = ddsrt_strtok_r( NULL, ",:", &saveptr);
|
||||
CU_ASSERT(res == NULL);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue