Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F7988928
pcmk__g_strcat_test.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
pcmk__g_strcat_test.c
View Options
/*
* Copyright 2020-2022 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include <crm_internal.h>
#include <crm/common/unittest_internal.h>
static void
add_to_null(void **state)
{
pcmk__assert_asserts(pcmk__g_strcat(NULL, NULL));
pcmk__assert_asserts(pcmk__g_strcat(NULL, "hello", NULL));
}
static void
add_nothing(void **state)
{
GString *buf = g_string_new(NULL);
// Start with empty string
pcmk__g_strcat(buf, NULL);
assert_string_equal((const char *) buf->str, "");
pcmk__g_strcat(buf, "", NULL);
assert_string_equal((const char *) buf->str, "");
// Start with populated string
g_string_append(buf, "hello");
pcmk__g_strcat(buf, NULL);
assert_string_equal((const char *) buf->str, "hello");
pcmk__g_strcat(buf, "", NULL);
assert_string_equal((const char *) buf->str, "hello");
g_string_free(buf, TRUE);
}
static void
add_words(void **state)
{
GString *buf = g_string_new(NULL);
// Verify a call with multiple words
pcmk__g_strcat(buf, "hello", " ", NULL);
assert_string_equal((const char *) buf->str, "hello ");
// Verify that a second call doesn't overwrite the first one
pcmk__g_strcat(buf, "world", NULL);
assert_string_equal((const char *) buf->str, "hello world");
g_string_free(buf, TRUE);
}
static void
stop_early(void **state)
{
GString *buf = g_string_new(NULL);
// NULL anywhere after buf in the arg list should cause a return
pcmk__g_strcat(buf, "hello", NULL, " world", NULL);
assert_string_equal((const char *) buf->str, "hello");
g_string_free(buf, TRUE);
}
PCMK__UNIT_TEST(NULL, NULL,
cmocka_unit_test(add_to_null),
cmocka_unit_test(add_nothing),
cmocka_unit_test(add_words),
cmocka_unit_test(stop_early))
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Oct 25, 2:02 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2615216
Default Alt Text
pcmk__g_strcat_test.c (1 KB)
Attached To
Mode
rP Pacemaker
Attached
Detach File
Event Timeline
Log In to Comment