Line data Source code
1 : /** @file suite_base64.c 2 : * @brief Check testsuite for base64 encoding and decoding functions 3 : * @author François Cerbelle (Fanfan), francois@cerbelle.net 4 : * 5 : * @internal 6 : * Created: 20/03/2022 7 : * Revision: none 8 : * Last modified: 2024-11-11 21:33 9 : * Compiler: gcc 10 : * Organization: Cerbelle.net 11 : * Copyright: Copyright (c) 2024, François Cerbelle 12 : * 13 : * This source code is released for free distribution under the terms of the 14 : * GNU General Public License as published by the Free Software Foundation. 15 : */ 16 : 17 : #ifdef HAVE_CONFIG_H 18 : #include "config.h" 19 : #endif 20 : 21 : #include <check.h> 22 : #include <stdlib.h> 23 : #include "checktools.inc" 24 : 25 : #include "base64.h" 26 : 27 : /** Dummy test to trigger fixtures 28 : * 29 : * This test is defined and added to all testcases in order to execute at 30 : * least one test test in each testcase of the testsuite, trigger the 31 : * fixtures and have a decent coverage report. 32 : */ 33 6 : START_TEST(base64_test) { 34 : /* This test is supposed to trigger a SIGABRT(6) and will crash the 35 : * whole testsuite if not caught or not in a child process */ 36 6 : forktest_only; 37 : 38 4 : abort(); 39 : } 40 : END_TEST 41 : 42 3 : START_TEST(base64_encode_null) { 43 : /* Should trigger SIG11 */ 44 3 : forktest_only; 45 2 : base64_encode(NULL); 46 : } 47 : END_TEST 48 : 49 3 : START_TEST(base64_encode_empty) { 50 3 : char* enc = NULL; 51 3 : enc = base64_encode(""); 52 3 : ck_assert(NULL!=enc); 53 3 : ck_assert(0==strcmp(enc,"")); 54 3 : free(enc); 55 3 : } 56 : END_TEST 57 : 58 3 : START_TEST(base64_encode_abc) { 59 3 : char* enc = NULL; 60 3 : enc = base64_encode("abc"); 61 3 : ck_assert(NULL!=enc); 62 3 : ck_assert(0==strcmp(enc,"YWJj")); 63 3 : free(enc); 64 3 : } 65 : END_TEST 66 : 67 3 : START_TEST(base64_decode_null) { 68 : /* Should trigger SIG11 */ 69 3 : forktest_only; 70 2 : base64_decode(NULL); 71 : } 72 : END_TEST 73 : 74 3 : START_TEST(base64_decode_empty) { 75 3 : char* dec = NULL; 76 3 : dec = base64_decode(""); 77 3 : ck_assert(NULL!=dec); 78 3 : ck_assert(0==strcmp(dec,"")); 79 3 : free(dec); 80 3 : } 81 : END_TEST 82 : 83 3 : START_TEST(base64_decode_abc) { 84 3 : char* dec = NULL; 85 3 : dec = base64_decode("YWJj"); 86 3 : ck_assert(NULL!=dec); 87 3 : ck_assert(0==strcmp(dec,"abc")); 88 3 : free(dec); 89 3 : } 90 : END_TEST 91 : 92 : /************************************************************************/ 93 : /* Begining of test (potentially in child) */ 94 24 : void base64_checked_uninitialized_setup() { 95 24 : signals_catch(); 96 24 : forktest_gprofdir(); 97 24 : } 98 : 99 : /* End of test (potentially in child) */ 100 16 : void base64_checked_uninitialized_teardown() { 101 16 : signals_release(); 102 16 : } 103 : /************************************************************************/ 104 30 : void base64_unchecked_common_setup() { 105 30 : forktest_init(); 106 30 : } 107 14 : void base64_unchecked_common_teardown() { 108 14 : } 109 : /************************************************************************/ 110 20 : Suite* base64_suite() { 111 : Suite *s; 112 : TCase *tc; 113 : 114 20 : s = suite_create("Base64"); 115 : 116 20 : tc = tcase_create("Base64Encode"); 117 20 : tcase_set_tags(tc,"Base64Tag Base64Tag2"); 118 : /* tcase_set_timeout(tc,5); */ /* seconds */ 119 20 : tcase_add_checked_fixture(tc, base64_checked_uninitialized_setup, base64_checked_uninitialized_teardown); 120 20 : tcase_add_unchecked_fixture(tc, base64_unchecked_common_setup, base64_unchecked_common_teardown); 121 20 : suite_add_tcase(s, tc); 122 20 : tcase_add_test_raise_signal(tc, base64_test,6); 123 20 : tcase_add_test_raise_signal(tc, base64_encode_null,11); 124 20 : tcase_add_test(tc, base64_encode_empty); 125 20 : tcase_add_test(tc, base64_encode_abc); 126 : 127 20 : tc = tcase_create("Base64Decode"); 128 20 : tcase_set_tags(tc,"Base64Tag Base64Tag2"); 129 : /* tcase_set_timeout(tc,5); */ /* seconds */ 130 20 : tcase_add_checked_fixture(tc, base64_checked_uninitialized_setup, base64_checked_uninitialized_teardown); 131 20 : tcase_add_unchecked_fixture(tc, base64_unchecked_common_setup, base64_unchecked_common_teardown); 132 20 : suite_add_tcase(s, tc); 133 20 : tcase_add_test_raise_signal(tc, base64_test,6); 134 20 : tcase_add_test_raise_signal(tc, base64_decode_null,11); 135 20 : tcase_add_test(tc, base64_decode_empty); 136 20 : tcase_add_test(tc, base64_decode_abc); 137 : 138 20 : return s; 139 : } 140 : /* vim: set tw=80: */