/
niceSOFT
/
shadow
Обзор
Документация
Войти
/
niceSOFT
/
shadow
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/unit/test_stprintf.c
67 строк
2 KB
Alejandro Colomar
lib/, src/, tests/: Rename snprintf_() => stprintf()
15 май 2026, 13:06
15 май 2026, 13:06
840519b
Код
Авторство
О чём код?
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org> // SPDX-License-Identifier: BSD-3-Clause #include "config.h" #include <stdio.h> #include <string.h> #include <stdarg.h> // Required by <cmocka.h> #include <stddef.h> // Required by <cmocka.h> #include <setjmp.h> // Required by <cmocka.h> #include <stdint.h> // Required by <cmocka.h> #include <cmocka.h> #include "attr.h" #include "sizeof.h" #include "string/sprintf/stprintf.h" static void test_stprintf_a_trunc(MAYBE_UNUSED void ** _1); static void test_stprintf_a_ok(MAYBE_UNUSED void ** _1); int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_stprintf_a_trunc), cmocka_unit_test(test_stprintf_a_ok), }; return cmocka_run_group_tests(tests, NULL, NULL); } static void test_stprintf_a_trunc(MAYBE_UNUSED void ** _1) { char buf[countof("foo")]; // Test that we're not returning SIZE_MAX assert_true(stprintf_a(buf, "f%su", "oo") < 0); assert_true(strcmp(buf, "foo") == 0); assert_true(stprintf_a(buf, "barbaz") == -1); assert_true(strcmp(buf, "bar") == 0); } static void test_stprintf_a_ok(MAYBE_UNUSED void ** _1) { char buf[countof("foo")]; assert_true(stprintf_a(buf, "%s", "foo") == strlen("foo")); assert_true(strcmp(buf, "foo") == 0); assert_true(stprintf_a(buf, "%do", 1) == strlen("1o")); assert_true(strcmp(buf, "1o") == 0); assert_true(stprintf_a(buf, "f") == strlen("f")); assert_true(strcmp(buf, "f") == 0); assert_true(stprintf_a(buf, "") == strlen("")); assert_true(strcmp(buf, "") == 0); }