# define STRSKIP(a, b) (STRPREFIX(a, b) ? (a) + strlen(b) : NULL)
# define STREQ_NULLABLE(a, b) \
- ((a) ? (b) && STREQ((a) ? (a) : "", (b) ? (b) : "") : !(b))
+ ((a) ? (b) && STREQ((a), (b)) : !(b))
# define STRNEQ_NULLABLE(a, b) \
- ((a) ? !(b) || STRNEQ((a) ? (a) : "", (b) ? (b) : "") : !!(b))
+ ((a) ? !(b) || STRNEQ((a), (b)) : !!(b))
# define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0)
# define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
VIR_LOG_INIT("tests.stringtest");
+struct testStreqData {
+ const char *a;
+ const char *b;
+};
+
+static int testStreq(const void *args)
+{
+ const struct testStreqData *data = args;
+ int ret = -1;
+ bool equal = true;
+ bool streq_rv, strneq_rv;
+ size_t i;
+
+ if ((size_t) data->a ^ (size_t) data->b)
+ equal = false;
+ if (data->a && data->b) {
+ for (i = 0; data->a[i] != '\0'; i++) {
+ if (data->b[i] == '\0' ||
+ data->a[i] != data->b[i]) {
+ equal = false;
+ break;
+ }
+ }
+ }
+
+ streq_rv = STREQ_NULLABLE(data->a, data->b);
+ strneq_rv = STRNEQ_NULLABLE(data->a, data->b);
+
+ if (streq_rv != equal) {
+ virFilePrintf(stderr,
+ "STREQ not working correctly. Expected %d got %d",
+ (int) equal, (int) streq_rv);
+ goto cleanup;
+ }
+
+ if (strneq_rv == equal) {
+ virFilePrintf(stderr,
+ "STRNEQ not working correctly. Expected %d got %d",
+ (int) equal, (int) strneq_rv);
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ return ret;
+}
+
struct testSplitData {
const char *string;
const char *delim;
{
int ret = 0;
+#define TEST_STREQ(aa, bb) \
+ do { \
+ struct testStreqData streqData = {.a = aa, .b = bb}; \
+ if (virTestRun("Streq", testStreq, &streqData) < 0) \
+ ret = -1; \
+ } while (0)
+
+ TEST_STREQ("hello", "world");
+ TEST_STREQ(NULL, NULL);
+ TEST_STREQ(NULL, "");
+ TEST_STREQ("", NULL);
+ TEST_STREQ("", "");
+ TEST_STREQ("hello", "hello");
+
#define TEST_SPLIT(str, del, max, toks) \
do { \
struct testSplitData splitData = { \