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 <post@lespocky.de>
  • Loading branch information
LeSpocky committed Feb 16, 2017
1 parent b6fc028 commit 97cbe52
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2016 Alexander Dahl <post@lespocky.de>
# Copyright 2016,2017 Alexander Dahl <post@lespocky.de>
#

include_directories(
Expand Down Expand Up @@ -34,3 +34,14 @@ add_test(slist_get_item
add_test(slist_process_data
cgi-test-slist processdata
)

add_executable(cgi-test-session
cgi_test.c
test_session.c
)
target_link_libraries(cgi-test-session
"${PROJECT_NAME}-shared"
)
add_test(session_cookie_name
cgi-test-session cookie_name
)
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 <post@lespocky.de>
*
* @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 97cbe52

Please sign in to comment.