forked from rafaelsteil/libcgi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: */ |