mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 13:30:27 +01:00
test: switch some xasprintf to strdup_printf()
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
This commit is contained in:
parent
589850e8df
commit
0e3bb4690a
4 changed files with 18 additions and 28 deletions
|
|
@ -363,9 +363,8 @@ valgrind_logfile(pid_t pid)
|
|||
if (!prefix)
|
||||
prefix = ".";
|
||||
|
||||
char *filename = NULL;
|
||||
int rc = xasprintf(&filename, "%s/valgrind.%d.log", prefix, pid);
|
||||
litest_assert_neg_errno_success(rc);
|
||||
char *filename = strdup_printf("%s/valgrind.%d.log", prefix, pid);
|
||||
litest_assert_ptr_notnull(filename);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
|
@ -375,8 +374,7 @@ collect_file(const char *filename, struct stringbuf *b)
|
|||
{
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
char *msg;
|
||||
xasprintf(&msg, "Failed to find '%s': %m", filename);
|
||||
char *msg = strdup_printf("Failed to find '%s': %m", filename);
|
||||
stringbuf_append_string(b, msg);
|
||||
free(msg);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1389,15 +1389,11 @@ litest_init_all_device_udev_rules(struct list *created_files)
|
|||
{
|
||||
struct created_file *file = zalloc(sizeof(*file));
|
||||
struct litest_test_device *dev;
|
||||
char *path = NULL;
|
||||
FILE *f;
|
||||
int rc;
|
||||
int fd;
|
||||
|
||||
rc = xasprintf(&path,
|
||||
"%s/99-litest-XXXXXX.rules",
|
||||
UDEV_RULES_D);
|
||||
litest_assert_errno_success(rc);
|
||||
char *path = strdup_printf("%s/99-litest-XXXXXX.rules", UDEV_RULES_D);
|
||||
litest_assert_ptr_notnull(path);
|
||||
|
||||
fd = mkstemps(path, 6);
|
||||
litest_assert_errno_success(fd);
|
||||
|
|
|
|||
|
|
@ -632,8 +632,7 @@ START_TEST(quirks_parse_product_too_many)
|
|||
snprintf(&matches[len], remaining, "0x%04X", i);
|
||||
}
|
||||
|
||||
char *quirks_file = NULL;
|
||||
xasprintf(&quirks_file, "%s%s%s", prologue, matches, epilogue);
|
||||
char *quirks_file = strdup_printf("%s%s%s", prologue, matches, epilogue);
|
||||
struct data_dir dd = make_data_dir(quirks_file);
|
||||
|
||||
free(quirks_file);
|
||||
|
|
@ -1443,7 +1442,6 @@ START_TEST(quirks_model_override)
|
|||
struct litest_device *dev = litest_current_device();
|
||||
struct udev_device *ud = libinput_device_get_udev_device(dev->libinput_device);
|
||||
struct quirks_context *ctx;
|
||||
char *quirks_file;
|
||||
struct data_dir dd;
|
||||
struct quirks *q;
|
||||
bool isset;
|
||||
|
|
@ -1451,17 +1449,16 @@ START_TEST(quirks_model_override)
|
|||
|
||||
/* Test model quirks override by setting, then unsetting (or the
|
||||
other way round) */
|
||||
int rc = xasprintf(&quirks_file,
|
||||
"[first]\n"
|
||||
"MatchUdevType=mouse\n"
|
||||
"ModelAppleTouchpad=%d\n"
|
||||
"\n"
|
||||
"[second]\n"
|
||||
"MatchUdevType=mouse\n"
|
||||
"ModelAppleTouchpad=%d\n",
|
||||
set ? 0 : 1,
|
||||
set ? 1 : 0);
|
||||
litest_assert_int_ne(rc, -1);
|
||||
char *quirks_file= strdup_printf("[first]\n"
|
||||
"MatchUdevType=mouse\n"
|
||||
"ModelAppleTouchpad=%d\n"
|
||||
"\n"
|
||||
"[second]\n"
|
||||
"MatchUdevType=mouse\n"
|
||||
"ModelAppleTouchpad=%d\n",
|
||||
set ? 0 : 1,
|
||||
set ? 1 : 0);
|
||||
litest_assert_ptr_notnull(quirks_file);
|
||||
|
||||
dd = make_data_dir(quirks_file);
|
||||
|
||||
|
|
|
|||
|
|
@ -1871,9 +1871,8 @@ START_TEST(stringbuf_test)
|
|||
rc = stringbuf_append_from_fd(b, pipefd[0], 64);
|
||||
litest_assert_neg_errno_success(rc);
|
||||
|
||||
char *expected;
|
||||
rc = xasprintf(&expected, "%s%s", compare ? compare : "", str);
|
||||
litest_assert_neg_errno_success(rc);
|
||||
char *expected = strdup_printf("%s%s", compare ? compare : "", str);
|
||||
litest_assert_ptr_notnull(expected);
|
||||
litest_assert_str_eq(b->data, expected);
|
||||
|
||||
free(compare);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue