Skip to content

Commit

Permalink
Introduce tests for session
Browse files Browse the repository at this point in the history
This is a follow-up to rafaelsteil#25 to ensure this all works like it should
without evil memory leaks, null pointer dereferences, …

Now the first test here is very simple, just to get this test module
running.

Signed-off-by: Alexander Dahl <[email protected]>
  • Loading branch information
LeSpocky committed Jul 12, 2018
1 parent 5b37579 commit 5d67511
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ add_test(NAME cgi_slist_process_data
COMMAND cgi-test-slist processdata
)

# session
add_executable(cgi-test-session
cgi_test.c
test_session.c
)
target_link_libraries(cgi-test-session
${PROJECT_NAME}
)
add_test(NAME cgi_session_cookie_name
COMMAND cgi-test-session cookie_name
)

# trim
add_executable(cgi-test-trim
cgi_test.c
Expand Down
80 changes: 80 additions & 0 deletions test/test_session.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************//**
* @file test_session.c
*
* Test cgi session implementation.
*
* @author Alexander Dahl <[email protected]>
*
* @copyright 2017 Alexander Dahl
**********************************************************************/

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#include "cgi_test.h"

#include "cgi.h"

#define CGI_TEST_SHRT_COOKIE_NAME "cgi_sess"
#define CGI_TEST_COOKIE_NAME_49 "_______ten____twenty____thirty____fourty_____fift"
#define CGI_TEST_COOKIE_NAME_50 "_______ten____twenty____thirty____fourty_____fifty"
#define CGI_TEST_COOKIE_NAME_51 "_______ten____twenty____thirty____fourty_____fifty_"
#define CGI_TEST_LONG_COOKIE_NAME "_______ten____twenty____thirty____fourty_____fifty_____sixty"

/* local declarations */
static int cookie_name( void );

int main( int argc, char *argv[] )
{
struct cgi_test_action actions[] = {
{ "cookie_name", cookie_name },
};

/* require at least one argument to select test */
if ( argc < 2 ) return EXIT_FAILURE;

return run_action( argv[1], actions,
sizeof(actions)/sizeof(struct cgi_test_action) );
}

int cookie_name( void )
{
// cgi_session_cookie_name( NULL );

cgi_session_cookie_name( CGI_TEST_SHRT_COOKIE_NAME );
check( strcmp( CGI_TEST_SHRT_COOKIE_NAME, SESSION_COOKIE_NAME ) == 0,
"short cookie name not equal" );
check( check_string_buffer_terminated( SESSION_COOKIE_NAME,
sizeof(SESSION_COOKIE_NAME) ),
"cookie name not terminated" );

cgi_session_cookie_name( CGI_TEST_COOKIE_NAME_49 );
check( strcmp( CGI_TEST_COOKIE_NAME_49, SESSION_COOKIE_NAME ) == 0,
"49 cookie name not equal" );
check( check_string_buffer_terminated( SESSION_COOKIE_NAME,
sizeof(SESSION_COOKIE_NAME) ),
"cookie name not terminated" );

cgi_session_cookie_name( CGI_TEST_COOKIE_NAME_50 );
check( check_string_buffer_terminated( SESSION_COOKIE_NAME,
sizeof(SESSION_COOKIE_NAME) ),
"cookie name not terminated" );

cgi_session_cookie_name( CGI_TEST_COOKIE_NAME_51 );
check( check_string_buffer_terminated( SESSION_COOKIE_NAME,
sizeof(SESSION_COOKIE_NAME) ),
"cookie name not terminated" );

cgi_session_cookie_name( CGI_TEST_LONG_COOKIE_NAME );
check( check_string_buffer_terminated( SESSION_COOKIE_NAME,
sizeof(SESSION_COOKIE_NAME) ),
"cookie name not terminated" );

return EXIT_SUCCESS;

error:
return EXIT_FAILURE;
}

/* vim: set noet sts=0 ts=4 sw=4 sr: */

0 comments on commit 5d67511

Please sign in to comment.