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-06 10:30 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 2 : 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 2 : forktest_only; 37 : 38 2 : abort(); 39 : } 40 : END_TEST 41 : 42 1 : START_TEST(base64_encode_null) { 43 : /* Should trigger SIG11 */ 44 1 : forktest_only; 45 1 : base64_encode(NULL); 46 : } 47 : END_TEST 48 : 49 1 : START_TEST(base64_encode_empty) { 50 1 : char* enc = NULL; 51 1 : enc = base64_encode(""); 52 1 : ck_assert(NULL!=enc); 53 1 : ck_assert(0==strcmp(enc,"")); 54 1 : free(enc); 55 1 : } 56 : END_TEST 57 : 58 1 : START_TEST(base64_encode_abc) { 59 1 : char* enc = NULL; 60 1 : enc = base64_encode("abc"); 61 1 : ck_assert(NULL!=enc); 62 1 : ck_assert(0==strcmp(enc,"YWJj")); 63 1 : free(enc); 64 1 : } 65 : END_TEST 66 : 67 1 : START_TEST(base64_decode_null) { 68 : /* Should trigger SIG11 */ 69 1 : forktest_only; 70 1 : base64_decode(NULL); 71 : } 72 : END_TEST 73 : 74 1 : START_TEST(base64_decode_empty) { 75 1 : char* dec = NULL; 76 1 : dec = base64_decode(""); 77 1 : ck_assert(NULL!=dec); 78 1 : ck_assert(0==strcmp(dec,"")); 79 1 : free(dec); 80 1 : } 81 : END_TEST 82 : 83 1 : START_TEST(base64_decode_abc) { 84 1 : char* dec = NULL; 85 1 : dec = base64_decode("YWJj"); 86 1 : ck_assert(NULL!=dec); 87 1 : ck_assert(0==strcmp(dec,"abc")); 88 1 : free(dec); 89 1 : } 90 : END_TEST 91 : 92 : /************************************************************************/ 93 : /* Begining of test (potentially in child) */ 94 8 : void base64_checked_uninitialized_setup() { 95 8 : signals_catch(); 96 8 : forktest_gprofdir(); 97 8 : } 98 : 99 : /* End of test (potentially in child) */ 100 4 : void base64_checked_uninitialized_teardown() { 101 4 : signals_release(); 102 4 : } 103 : /************************************************************************/ 104 14 : void base64_unchecked_common_setup() { 105 14 : forktest_init(); 106 14 : } 107 6 : void base64_unchecked_common_teardown() { 108 6 : } 109 : /************************************************************************/ 110 9 : Suite* base64_suite() { 111 : Suite *s; 112 : TCase *tc; 113 : 114 9 : s = suite_create("Base64"); 115 : 116 9 : tc = tcase_create("Base64Encode"); 117 9 : tcase_set_tags(tc,"Base64EncodeTag Base64DecodeTag2"); 118 : /* tcase_set_timeout(tc,5); */ /* seconds */ 119 9 : tcase_add_checked_fixture(tc, base64_checked_uninitialized_setup, base64_checked_uninitialized_teardown); 120 9 : tcase_add_unchecked_fixture(tc, base64_unchecked_common_setup, base64_unchecked_common_teardown); 121 9 : suite_add_tcase(s, tc); 122 9 : tcase_add_test_raise_signal(tc, base64_test,6); 123 9 : tcase_add_test_raise_signal(tc, base64_encode_null,11); 124 9 : tcase_add_test(tc, base64_encode_empty); 125 9 : tcase_add_test(tc, base64_encode_abc); 126 : 127 9 : tc = tcase_create("Base64Decode"); 128 9 : tcase_set_tags(tc,"Base64DecodeTag Base64DecodeTag2"); 129 : /* tcase_set_timeout(tc,5); */ /* seconds */ 130 9 : tcase_add_checked_fixture(tc, base64_checked_uninitialized_setup, base64_checked_uninitialized_teardown); 131 9 : tcase_add_unchecked_fixture(tc, base64_unchecked_common_setup, base64_unchecked_common_teardown); 132 9 : suite_add_tcase(s, tc); 133 9 : tcase_add_test_raise_signal(tc, base64_test,6); 134 9 : tcase_add_test_raise_signal(tc, base64_decode_null,11); 135 9 : tcase_add_test(tc, base64_decode_empty); 136 9 : tcase_add_test(tc, base64_decode_abc); 137 : 138 9 : return s; 139 : } 140 : /* vim: set tw=80: */