diff options
author | axtloss <axtlos@disroot.org> | 2024-10-17 02:39:27 +0200 |
---|---|---|
committer | axtloss <axtlos@disroot.org> | 2024-10-17 02:39:27 +0200 |
commit | 7f0fc08c05142f9f70cb05a4b1b1d6f0b1a3279b (patch) | |
tree | 0c1934e2d6940a99e97f2adefdac46cd3b9e384d /tests/test_strfmt.c | |
parent | b2182396df5d99ff5c26161aaffa5ced879742c5 (diff) | |
download | extlib-7f0fc08c05142f9f70cb05a4b1b1d6f0b1a3279b.tar.gz extlib-7f0fc08c05142f9f70cb05a4b1b1d6f0b1a3279b.tar.bz2 |
Add strfmt
Diffstat (limited to 'tests/test_strfmt.c')
-rw-r--r-- | tests/test_strfmt.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_strfmt.c b/tests/test_strfmt.c new file mode 100644 index 0000000..c8ab08e --- /dev/null +++ b/tests/test_strfmt.c @@ -0,0 +1,52 @@ +#include <string.h> +#define USE_SECURE_MEM +#include "../src/extlib.h" +#include "stdbool.h" + +int +test_strfmt () +{ + int errno = 0; + char *test_string_1 = strfmt ("meow", (struct style) {0, false, BOLD}); + printf ("\e[1mtest_strfmt\e[0m:: No Color, Bold: %s\n", test_string_1); + if (strcmp (test_string_1, "\e[1mmeow\e[0m") != 0) + errno = 1; + + char *test_string_2 = strfmt ("meow", (struct style) {RED, false, 0}); + printf ("\e[1mtest_strfmt\e[0m:: Red, No style: %s\n", test_string_2); + if (strcmp (test_string_2, "\e[38;5;1mmeow\e[0m") != 0) + errno = 2; + + char *test_string_3 = strfmt ("meow", (struct style) {RED, false, BOLD}); + printf ("\e[1mtest_strfmt\e[0m:: Red, Bold: %s\n", test_string_3); + if (strcmp (test_string_3, "\e[38;5;1m\e[1mmeow\e[0m") != 0) + errno = 3; + + char *test_string_4 = strfmt ("meow", (struct style) {RED, true, 0}); + printf ("\e[1mtest_strfmt\e[0m:: Red background, No style: %s\n", test_string_4); + if (strcmp (test_string_4, "\e[48;5;1mmeow\e[0m") != 0) + errno = 4; + + char *test_string_5 = strfmt ("meow", (struct style) {RED, true, BOLD}); + printf ("\e[1mtest_strfmt\e[0m:: Red background, Bold: %s\n", test_string_5); + if (strcmp (test_string_5, "\e[48;5;1m\e[1mmeow\e[0m") != 0) + errno = 5; + + free_secure ((void **) &test_string_1, strlen (test_string_1)); + free_secure ((void **) &test_string_2, strlen (test_string_2)); + free_secure ((void **) &test_string_3, strlen (test_string_3)); + free_secure ((void **) &test_string_4, strlen (test_string_4)); + free_secure ((void **) &test_string_5, strlen (test_string_5)); + return errno; +} + +struct test_t* +test_strfmt_t () +{ + struct test_t* test = malloc (sizeof (struct test_t)); + test->test_func=test_strfmt; + test->test_name="test_strfmt"; + test->test_desc="strfmt"; + return test; +} + |