mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
spa/string: add spa_streq() and spa_strneq() for string equality
Easier to use than strcmp() since their return value matches expectations. And they do what is expected with NULL strings, two NULL pointers are equal, one NULL pointer is not equal.
This commit is contained in:
parent
9bbe5c7517
commit
d8a9534a9a
2 changed files with 39 additions and 0 deletions
|
|
@ -477,6 +477,22 @@ static void test_strtol(void)
|
|||
spa_assert(!spa_atoi32(NULL, &v, 16) && v == 0xabcd);
|
||||
}
|
||||
|
||||
static void test_streq(void)
|
||||
{
|
||||
spa_assert(spa_streq(NULL, NULL));
|
||||
spa_assert(spa_streq("", ""));
|
||||
spa_assert(spa_streq("a", "a"));
|
||||
spa_assert(spa_streq("abc", "abc"));
|
||||
spa_assert(!spa_streq(NULL, "abc"));
|
||||
spa_assert(!spa_streq("abc", NULL));
|
||||
|
||||
spa_assert(spa_strneq("abc", "aaa", 1));
|
||||
spa_assert(spa_strneq("abc", "abc", 7));
|
||||
spa_assert(!spa_strneq("abc", "aaa", 2));
|
||||
spa_assert(!spa_strneq("abc", NULL, 7));
|
||||
spa_assert(!spa_strneq(NULL, "abc", 7));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
test_abi();
|
||||
|
|
@ -487,5 +503,6 @@ int main(int argc, char *argv[])
|
|||
test_hook();
|
||||
test_ringbuffer();
|
||||
test_strtol();
|
||||
test_streq();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue