Line data Source code
1 : /** 2 : * @file suite_libhttp.c 3 : * @brief Check testsuite for libhttp functions 4 : * @author François Cerbelle (Fanfan), francois@cerbelle.net 5 : * 6 : * @internal 7 : * Created: 20/03/2022 8 : * Revision: none 9 : * Last modified: 2024-11-23 15:46 10 : * Compiler: gcc 11 : * Organization: Cerbelle.net 12 : * Copyright: Copyright (c) 2024, François Cerbelle 13 : * 14 : * This source code is released for free distribution under the terms of the 15 : * GNU General Public License as published by the Free Software Foundation. 16 : */ 17 : 18 : #ifdef HAVE_CONFIG_H 19 : #include "config.h" 20 : #endif 21 : 22 : #include <check.h> 23 : #include <stdlib.h> 24 : #include "checktools.inc" 25 : 26 : #include "libhttp.h" 27 : #include <stdio.h> /* perror */ 28 : 29 : /** Dummy test to trigger fixtures 30 : * 31 : * This test is defined and added to all testcases in order to execute at 32 : * least one test test in each testcase of the testsuite, trigger the 33 : * fixtures and have a decent coverage report. 34 : */ 35 3 : START_TEST(libhttp_test) { 36 : /* This test is supposed to trigger a SIGABRT(6) and will crash the 37 : * whole testsuite if not caught or not in a child process */ 38 3 : forktest_only; 39 : 40 2 : abort(); 41 : } 42 : END_TEST 43 : 44 3 : START_TEST(libhttp_basictest) { 45 : char* output_str; 46 : HTTP_t* http; 47 : 48 3 : http = HTTP_new(); 49 : 50 3 : HTTP_setbody(http,"<HTML></HTML>\r\n"); 51 : 52 3 : if (NULL==(HTTP_addheader(http,"Host","localhost"))) { 53 0 : perror("libhttp_basictest HTTP_addheader Host"); 54 0 : ck_abort(); 55 : } 56 : 57 3 : if (NULL==(HTTP_addheader(http,"Host","localhost"))) { 58 0 : perror("libhttp_basictest HTTP_addheader Host2"); 59 0 : ck_abort(); 60 : } 61 : 62 3 : if (NULL==(HTTP_addheader(http,"Content-type","text/html"))) { 63 0 : perror("libhttp_basictest HTTP_addheader Host"); 64 0 : ck_abort(); 65 : } 66 : 67 3 : output_str=HTTP_buildrequest(HTTPMETHOD_GET,"/v1/api/bdbs",HTTPVERSION_HTTP11); 68 3 : printf("%s",output_str); 69 3 : free(output_str); 70 : 71 3 : output_str = HTTP_buildheaders(http); 72 3 : printf("%s",output_str); 73 3 : free(output_str); 74 : 75 3 : printf("%s",HTTP_getbody(http)); 76 : 77 3 : HTTP_del(http); 78 : 79 3 : } 80 : END_TEST 81 : 82 : /************************************************************************/ 83 : /* Begining of test (potentially in child) */ 84 6 : void libhttp_checked_uninitialized_setup() { 85 6 : signals_catch(); 86 6 : forktest_gprofdir(); 87 6 : } 88 : 89 : /* End of test (potentially in child) */ 90 4 : void libhttp_checked_uninitialized_teardown() { 91 4 : signals_release(); 92 4 : } 93 : /************************************************************************/ 94 7 : void libhttp_unchecked_common_setup() { 95 7 : forktest_init(); 96 7 : } 97 3 : void libhttp_unchecked_common_teardown() { 98 3 : } 99 : /************************************************************************/ 100 8 : Suite* libhttp_suite() { 101 : Suite *s; 102 : TCase *tc; 103 : 104 8 : s = suite_create("LibHTTP"); 105 : 106 8 : tc = tcase_create("LibHTTPUninitialized"); 107 8 : tcase_set_tags(tc,"LibHTTPTag LibHTTPTag2"); 108 : /* tcase_set_timeout(tc,5); */ /* seconds */ 109 8 : tcase_add_checked_fixture(tc, libhttp_checked_uninitialized_setup, libhttp_checked_uninitialized_teardown); 110 8 : tcase_add_unchecked_fixture(tc, libhttp_unchecked_common_setup, libhttp_unchecked_common_teardown); 111 8 : suite_add_tcase(s, tc); 112 8 : tcase_add_test_raise_signal(tc, libhttp_test,6); 113 8 : tcase_add_test(tc, libhttp_basictest); 114 : 115 8 : return s; 116 : } 117 : /* vim: set tw=80: */