#include #include #include #include "astr.h" static void test_astr_alloc_empty(void) { char *s = astr_alloc_empty(); assert(s); assert(0 == strlen(s)); free(s); } static void test_astr_alloc_format(void) { char *s = astr_alloc_format("answer: %i", 42); assert(s); assert(10 == strlen(s)); assert(astr_eq("answer: 42", s)); free(s); } static void test_astr_alloc_format_for_NULL_format(void) { errno = 0; char *s = astr_alloc_format(NULL); assert(!s); assert(EINVAL == errno); free(s); } static void test_astr_eq(void) { char *s = astr_alloc_format("foo"); assert(astr_eq("foo", s)); assert(!astr_eq(s, "bar")); free(s); } static void test_astr_eq_for_NULL_string(void) { char *s = astr_alloc_format("foo"); assert(!astr_eq(s, NULL)); assert(!astr_eq(NULL, s)); assert(astr_eq(NULL, NULL)); free(s); } static void test_astr_eq_for_empty_strings(void) { char *s1 = astr_alloc_empty(); char *s2 = astr_alloc_empty(); assert(s1 != s2); assert(astr_eq(s1, s2)); free(s2); free(s1); } static void test_astr_len_format(void) { errno = 0; size_t length = astr_len_format("answer: %i", 42); assert(10 == length); assert(0 == errno); } static void test_astr_len_format_for_NULL_format(void) { errno = 0; size_t length = astr_len_format(NULL); assert(0 == length); assert(EINVAL == errno); } int main(int argc, char *argv[]) { test_astr_alloc_empty(); test_astr_alloc_format(); test_astr_alloc_format_for_NULL_format(); test_astr_eq(); test_astr_eq_for_NULL_string(); test_astr_eq_for_empty_strings(); test_astr_len_format(); test_astr_len_format_for_NULL_format(); return EXIT_SUCCESS; }