mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-31 11:09:04 -05:00
treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done separately.
This commit is contained in:
parent
d8a9534a9a
commit
7697ed0757
130 changed files with 817 additions and 675 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include <spa/utils/dict.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
#define MAX_COUNT 100000
|
||||
#define MAX_ITEMS 1000
|
||||
|
|
@ -74,7 +75,7 @@ static void test_query(const struct spa_dict *dict)
|
|||
for (i = 0; i < MAX_COUNT; i++) {
|
||||
idx = random() % dict->n_items;
|
||||
str = spa_dict_lookup(dict, dict->items[idx].key);
|
||||
assert(strcmp(str, dict->items[idx].value) == 0);
|
||||
assert(spa_streq(str, dict->items[idx].value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/json.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
static void test_abi(void)
|
||||
{
|
||||
|
|
@ -73,7 +74,7 @@ static void expect_string(struct spa_json *it, const char *str)
|
|||
check_type(TYPE_STRING, value, len);
|
||||
s = alloca(len+1);
|
||||
spa_json_parse_string(value, len, s);
|
||||
spa_assert(strcmp(s, str) == 0);
|
||||
spa_assert(spa_streq(s, str));
|
||||
}
|
||||
static void expect_float(struct spa_json *it, float val)
|
||||
{
|
||||
|
|
@ -156,17 +157,17 @@ static void test_encode(void)
|
|||
char dst6[6];
|
||||
char result[1024];
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "test") == 6);
|
||||
spa_assert(strcmp(dst, "\"test\"") == 0);
|
||||
spa_assert(spa_streq(dst, "\"test\""));
|
||||
spa_assert(spa_json_encode_string(dst4, sizeof(dst4), "test") == 6);
|
||||
spa_assert(strncmp(dst4, "\"tes", 4) == 0);
|
||||
spa_assert(spa_json_encode_string(dst6, sizeof(dst6), "test") == 6);
|
||||
spa_assert(strncmp(dst6, "\"test\"", 6) == 0);
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "test\"\n\r \t\b\f\'") == 20);
|
||||
spa_assert(strcmp(dst, "\"test\\\"\\n\\r \\t\\b\\f'\"") == 0);
|
||||
spa_assert(spa_streq(dst, "\"test\\\"\\n\\r \\t\\b\\f'\""));
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "\x04\x05\x1f\x20\x01\x7f\x90") == 29);
|
||||
spa_assert(strcmp(dst, "\"\\u0004\\u0005\\u001f \\u0001\x7f\x90\"") == 0);
|
||||
spa_assert(spa_streq(dst, "\"\\u0004\\u0005\\u001f \\u0001\x7f\x90\""));
|
||||
spa_assert(spa_json_parse_string(dst, sizeof(dst), result) == 1);
|
||||
spa_assert(strcmp(result, "\x04\x05\x1f\x20\x01\x7f\x90") == 0);
|
||||
spa_assert(spa_streq(result, "\x04\x05\x1f\x20\x01\x7f\x90"));
|
||||
}
|
||||
|
||||
static void test_array(char *str, char **vals)
|
||||
|
|
@ -180,7 +181,7 @@ static void test_array(char *str, char **vals)
|
|||
spa_json_init(&it[1], str, strlen(str));
|
||||
for (i = 0; vals[i]; i++) {
|
||||
spa_assert(spa_json_get_string(&it[1], val, sizeof(val)) > 0);
|
||||
spa_assert(strcmp(val, vals[i]) == 0);
|
||||
spa_assert(spa_streq(val, vals[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -204,9 +205,9 @@ static void test_overflow(void)
|
|||
spa_assert(spa_json_enter_array(&it[0], &it[1]) > 0);
|
||||
|
||||
spa_assert(spa_json_get_string(&it[1], val, sizeof(val)) > 0);
|
||||
spa_assert(strcmp(val, "F") == 0);
|
||||
spa_assert(spa_streq(val, "F"));
|
||||
spa_assert(spa_json_get_string(&it[1], val, sizeof(val)) > 0);
|
||||
spa_assert(strcmp(val, "FR") == 0);
|
||||
spa_assert(spa_streq(val, "FR"));
|
||||
spa_assert(spa_json_get_string(&it[1], val, sizeof(val)) < 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <spa/debug/pod.h>
|
||||
#include <spa/param/format.h>
|
||||
#include <spa/param/video/raw.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
static void test_abi(void)
|
||||
{
|
||||
|
|
@ -288,7 +289,7 @@ static void test_init(void)
|
|||
spa_assert(SPA_POD_BODY_SIZE(&pod) == 9);
|
||||
spa_assert(spa_pod_is_string(&pod.pod.pod));
|
||||
spa_assert(spa_pod_copy_string(&pod.pod.pod, sizeof(val), val) == 0);
|
||||
spa_assert(strcmp(pod.str, val) == 0);
|
||||
spa_assert(spa_streq(pod.str, val));
|
||||
|
||||
pod.pod = SPA_POD_INIT_String(6);
|
||||
memcpy(pod.str, "test123456789", 9);
|
||||
|
|
@ -508,7 +509,7 @@ static void test_build(void)
|
|||
spa_assert((pod = spa_pod_next(pod)) != NULL && spa_pod_is_inside(head, len, pod));
|
||||
spa_assert(spa_pod_is_string(pod));
|
||||
spa_assert(spa_pod_get_string(pod, &val.s) == 0);
|
||||
spa_assert(strcmp(val.s, "test") == 0);
|
||||
spa_assert(spa_streq(val.s, "test"));
|
||||
spa_assert((pod = spa_pod_next(pod)) != NULL && spa_pod_is_inside(head, len, pod));
|
||||
spa_assert(spa_pod_is_bytes(pod));
|
||||
spa_assert(spa_pod_get_bytes(pod, &val.y, &yl) == 0);
|
||||
|
|
@ -627,7 +628,7 @@ static void test_build(void)
|
|||
spa_assert(prop->key == 3);
|
||||
spa_assert(SPA_POD_PROP_SIZE(prop) == 24);
|
||||
spa_assert(spa_pod_get_string(&prop->value, &val.s) == 0 &&
|
||||
strcmp(val.s, "test123") == 0);
|
||||
spa_streq(val.s, "test123"));
|
||||
break;
|
||||
default:
|
||||
spa_assert_not_reached();
|
||||
|
|
@ -637,7 +638,7 @@ static void test_build(void)
|
|||
spa_assert((prop = spa_pod_find_prop(pod, NULL, 3)) != NULL);
|
||||
spa_assert(prop->key == 3);
|
||||
spa_assert(spa_pod_get_string(&prop->value, &val.s) == 0 &&
|
||||
strcmp(val.s, "test123") == 0);
|
||||
spa_streq(val.s, "test123"));
|
||||
spa_assert((prop = spa_pod_find_prop(pod, prop, 1)) != NULL);
|
||||
spa_assert(prop->key == 1);
|
||||
spa_assert(spa_pod_get_int(&prop->value, &val.i) == 0 && val.i == 21);
|
||||
|
|
@ -649,7 +650,7 @@ static void test_build(void)
|
|||
spa_assert((prop = spa_pod_find_prop(pod, NULL, 3)) != NULL);
|
||||
spa_assert(prop->key == 3);
|
||||
spa_assert(spa_pod_get_string(&prop->value, &val.s) == 0 &&
|
||||
strcmp(val.s, "test123") == 0);
|
||||
spa_streq(val.s, "test123"));
|
||||
|
||||
spa_assert((pod = spa_pod_next(pod)) != NULL && spa_pod_is_inside(head, len, pod));
|
||||
spa_assert(spa_pod_is_sequence(pod));
|
||||
|
|
@ -998,7 +999,7 @@ static void test_varargs2(void)
|
|||
spa_assert(prop->key == 7);
|
||||
spa_assert(SPA_POD_PROP_SIZE(prop) == 21);
|
||||
spa_assert(spa_pod_get_string(&prop->value, &val.s) == 0);
|
||||
spa_assert(strcmp(val.s, "test") == 0);
|
||||
spa_assert(spa_streq(val.s, "test"));
|
||||
break;
|
||||
case 7:
|
||||
spa_assert(prop->key == 8);
|
||||
|
|
@ -1084,7 +1085,7 @@ static void test_varargs2(void)
|
|||
spa_assert(val.l == 4);
|
||||
spa_assert(val.f == 0.453f);
|
||||
spa_assert(val.d == 0.871);
|
||||
spa_assert(strcmp(val.s, "test") == 0);
|
||||
spa_assert(spa_streq(val.s, "test"));
|
||||
spa_assert(val.yl == sizeof(bytes));
|
||||
spa_assert(memcmp(val.y, bytes, sizeof(bytes)) == 0);
|
||||
spa_assert(memcmp(&val.R, &SPA_RECTANGLE(3, 4), sizeof(struct spa_rectangle)) == 0);
|
||||
|
|
@ -1251,7 +1252,7 @@ static void test_parser(void)
|
|||
spa_assert(val.l == 4);
|
||||
spa_assert(val.f == 0.453f);
|
||||
spa_assert(val.d == 0.871);
|
||||
spa_assert(strcmp(val.s, "test") == 0);
|
||||
spa_assert(spa_streq(val.s, "test"));
|
||||
spa_assert(val.yl == sizeof(bytes));
|
||||
spa_assert(memcmp(val.y, bytes, sizeof(bytes)) == 0);
|
||||
spa_assert(memcmp(&val.R, &SPA_RECTANGLE(3, 4), sizeof(struct spa_rectangle)) == 0);
|
||||
|
|
@ -1370,7 +1371,7 @@ static void test_parser2(void)
|
|||
spa_assert(p.state.offset == 88);
|
||||
spa_assert(spa_pod_parser_get_double(&p, &val.d) == 0 && val.d == 0.871);
|
||||
spa_assert(p.state.offset == 104);
|
||||
spa_assert(spa_pod_parser_get_string(&p, &val.s) == 0 && strcmp(val.s, "test") == 0);
|
||||
spa_assert(spa_pod_parser_get_string(&p, &val.s) == 0 && spa_streq(val.s, "test"));
|
||||
spa_assert(p.state.offset == 120);
|
||||
spa_assert(spa_pod_parser_get_bytes(&p, &val.y, &val.yl) == 0);
|
||||
spa_assert(val.yl == sizeof(bytes));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue