changeset 80:4349f4ec01dd

Added more tests on the message module, still not complete.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 11 Jul 2008 18:05:39 +0900
parents 7871aac19438
children 94e85f845b69
files waaad/tests/Makefile.am waaad/tests/testmesg.c waaad/tests/tests.h
diffstat 3 files changed, 216 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/tests/Makefile.am	Fri Jul 11 18:05:12 2008 +0900
+++ b/waaad/tests/Makefile.am	Fri Jul 11 18:05:39 2008 +0900
@@ -4,7 +4,10 @@
 AM_CPPFLAGS = -I$(srcdir)/../../include -I$(srcdir)/..
 
 # Also use the same flags as parent directory
-AM_CPPFLAGS += -DTRACE_LEVEL=INFO -DDEFAULT_CONF_FILE='"$(defconffile)"'
+AM_CPPFLAGS += -DTRACE_LEVEL=NONE -DDEFAULT_CONF_FILE='"$(defconffile)"'
+# Remark: the tests are run by default with TRACE_LEVEL = NONE.
+# Anyway, youcan run the test directly with the "-ddd" flags to turn on the debug without recompiling.
+# example: $ waaad/test/testmesg -ddd
 
 # Add this flag to add some debug information in the tests themselves
 AM_CPPFLAGS += -DTEST_DEBUG
--- a/waaad/tests/testmesg.c	Fri Jul 11 18:05:12 2008 +0900
+++ b/waaad/tests/testmesg.c	Fri Jul 11 18:05:39 2008 +0900
@@ -35,6 +35,10 @@
 
 #include "tests.h"
 
+
+extern void dump_dict_object ( void * obj, int parents, int depth, int indent );
+
+
 /* Main test routine */
 int main(int argc, char *argv[])
 {
@@ -75,6 +79,8 @@
 		/* For debug: dump the object */
 		log_debug("Dumping Proxy-Info AVP (from template)\n");
 		msg_dump_walk(pi);
+		log_debug("Dumping dictionary model\n");
+		dict_dump(pi_model, 0, 2);
 		#endif
 		
 		/* Check that msg_free does not recursively delete if not told to. */
@@ -245,6 +251,7 @@
 				CHECK( 0, dict_search ( DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp ) );	\
 				_data.rule_avp = _avp;								\
 				_data.rule_position = (_pos);							\
+				_data.rule_order = 1;								\
 				_data.rule_min = (_min);							\
 				_data.rule_max = (_max);							\
 				_data.rule_template = (_tpl);							\
@@ -269,6 +276,11 @@
 			ADD_RULE(command, 73565, "AVP Test - enumos", 		RULE_OPTIONAL,   -1, -1,  0);
 			ADD_RULE(command, 73565, "AVP Test - grouped", 		RULE_OPTIONAL,   -1, -1,  0);
 		}
+		#if 0
+		{
+			dict_dump ( vendor, 1, 2 );
+		}
+		#endif
 	}
 	
 	/* Now create some values and check the length is correctly handled */
@@ -301,6 +313,7 @@
 			msg_avp_t * avpi = NULL;
 			msg_avp_t * avpch = NULL;
 			msg_avp_data_t * avpdata = NULL;
+			msg_data_t * msgdata = NULL;
 			#define ADD_AVP( _parent, _position, _avpi, _avpvendor, _avpname) {			\
 				dict_object_t * _avp = NULL;							\
 				dict_avp_request_t _req = { (_avpvendor), 0, (_avpname) };			\
@@ -310,6 +323,7 @@
 			}
 			/* Create a message with many AVP inside */
 			CHECK( 0, msg_new ( cmd_model, 0, &msg ) );
+			CHECK( 0, msg_data ( msg, &msgdata ) );
 			
 			/* Avp no vendor, float32 => size = 12 */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 0,     "AVP Test - no vendor - f32" );
@@ -323,35 +337,227 @@
 			CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
 			CHECK( 12, avpdata->avp_len );
 			
+			/* Check what happens when we delete the value */
+			CHECK( 0, msg_avp_setvalue ( avpi, NULL ) );
+			CHECK( EINVAL, msg_update_length ( avpi ) );
+			CHECK( 0, msg_avp_setvalue ( avpi, &value ) );
+			
 			/* Add a vendor AVP, integer64 => size = 20 */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - i64" );
 			value.i64 = 0x123456789abcdeLL;
 			CHECK( 0, msg_avp_setvalue ( avpi, &value ) );
 			CHECK( 0, msg_update_length ( avpi ) );
-			#if 1
+			#if 0
 			log_debug("AVP vendor, value 0x123456789abcdeL:\n");
 			msg_dump_one(avpi);
 			#endif
 			CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
 			CHECK( 20, avpdata->avp_len );
 			
+			/* Check the size of the message is 20 (header) + 12 + 20 = 52 */
+			CHECK( 0, msg_update_length ( msg ) );
+			CHECK( 52, msgdata->msg_length );
 			
+			/* Add an AVP with an enum value */
+			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" );
+			{
+				dict_object_t * type_model = NULL;
+				dict_object_t * value_model = NULL;
+				dict_type_enum_request_t request;
+				
+				CHECK( 0, msg_model ( avpi, &avp_model ) );
+				CHECK( 0, dict_search ( DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model ) );
+				memset(&request, 0, sizeof(request));
+				request.type_obj = type_model;
+				request.search.enum_name = "i32 const test (val 2)";
+				CHECK( 0, dict_search ( DICT_TYPE_ENUM, ENUM_BY_STRUCT, &request, &value_model ) );
+				CHECK( 0, dict_getval ( value_model, &request.search ) );
+				CHECK( 0, msg_avp_setvalue ( avpi, &request.search.enum_value ) );
+				#if 0
+				log_debug("AVP enum i32, value 2:\n");
+				msg_dump_one(avpi);
+				#endif
+			}
 			
+			/* Add an AVP with an enum value, negative */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" );
+			{
+				dict_object_t * type_model = NULL;
+				dict_object_t * value_model = NULL;
+				dict_type_enum_request_t request;
+				
+				CHECK( 0, msg_model ( avpi, &avp_model ) );
+				CHECK( 0, dict_search ( DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model ) );
+				memset(&request, 0, sizeof(request));
+				request.type_obj = type_model;
+				request.search.enum_name = "i32 const test (val -5)";
+				CHECK( 0, dict_search ( DICT_TYPE_ENUM, ENUM_BY_STRUCT, &request, &value_model ) );
+				CHECK( 0, dict_getval ( value_model, &request.search ) );
+				CHECK( 0, msg_avp_setvalue ( avpi, &request.search.enum_value ) );
+				#if 0
+				log_debug("AVP enum i32, value -5:\n");
+				msg_dump_one(avpi);
+				#endif
+				/* Check the size is correct ( 12 for header + 4 for value ) */
+				CHECK( 0, msg_update_length ( avpi ) );
+				CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
+				CHECK( 16, avpdata->avp_len );
+			}
+			
+			/* Now add a value which is not a constant into a enumerated AVP */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" );
-			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumi32" );
+			value.i32 = -10;
+			CHECK( 0, msg_avp_setvalue ( avpi, &value ) );
+			CHECK( 0, msg_update_length ( avpi ) );
+			#if 0
+			log_debug("AVP vendor enum i32, value -10 (not enum):\n");
+			msg_dump_one(avpi);
+			#endif
+			
+			/* Add an octetstring AVP */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - os" );
+			{
+				unsigned char buf[90];
+				memcpy(&buf, "This\0 is a buffer of dat\a. It is not a string so we can have any c\0ntr\0l character here...\0\0", 89);
+				value.os.data = buf;
+				value.os.len = 89;
+				CHECK( 0, msg_avp_setvalue ( avpi, &value ) );
+				memset(&buf, 0, sizeof(buf)); /* Test that the OS value is copied */
+				CHECK( 0, msg_update_length ( avpi ) );
+				#if 0
+				log_debug("AVP octet string, 'This\\0 is a b...'\n");
+				msg_dump_one(avpi);
+				#endif
+				CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
+				CHECK( 101, avpdata->avp_len );
+				CHECK( 'T', avpdata->avp_data->os.data[0] );
+			}
+
+			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + 101 = 201 */
+			CHECK( 0, msg_update_length ( msg ) );
+			CHECK( 201, msgdata->msg_length );
+			
+			/* Add an octetstring from an enumerated constant */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumos" );
+			{
+				dict_object_t * type_model = NULL;
+				dict_object_t * value_model = NULL;
+				dict_type_enum_request_t request;
+				
+				CHECK( 0, msg_model ( avpi, &avp_model ) );
+				CHECK( 0, dict_search ( DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model ) );
+				memset(&request, 0, sizeof(request));
+				request.type_obj = type_model;
+				request.search.enum_name = "os const test (waaad)";
+				CHECK( 0, dict_search ( DICT_TYPE_ENUM, ENUM_BY_STRUCT, &request, &value_model ) );
+				CHECK( 0, dict_getval ( value_model, &request.search ) );
+				CHECK( 0, msg_avp_setvalue ( avpi, &request.search.enum_value ) );
+				#if 0
+				log_debug("AVP Enumuerated OctetString:\n");
+				msg_dump_one(avpi);
+				#endif
+				/* Check the size is correct ( 12 for header + 5 for value ) */
+				CHECK( 0, msg_update_length ( avpi ) );
+				CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
+				CHECK( 17, avpdata->avp_len );
+			}
+				
+			/* Add an octetstring from an enumerated constant */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - enumos" );
+			{
+				dict_object_t * type_model = NULL;
+				dict_object_t * value_model = NULL;
+				dict_type_enum_request_t request;
+				
+				CHECK( 0, msg_model ( avpi, &avp_model ) );
+				CHECK( 0, dict_search ( DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model ) );
+				memset(&request, 0, sizeof(request));
+				request.type_obj = type_model;
+				request.search.enum_name = "os const test (waa)";
+				CHECK( 0, dict_search ( DICT_TYPE_ENUM, ENUM_BY_STRUCT, &request, &value_model ) );
+				CHECK( 0, dict_getval ( value_model, &request.search ) );
+				CHECK( 0, msg_avp_setvalue ( avpi, &request.search.enum_value ) );
+				#if 0
+				log_debug("AVP Enumuerated OctetString:\n");
+				msg_dump_one(avpi);
+				#endif
+				/* Check the size is correct ( 12 for header + 3 for value ) */
+				CHECK( 0, msg_update_length ( avpi ) );
+				CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
+				CHECK( 15, avpdata->avp_len );
+			}
+				
+
+			/* Check the size of the message is 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + 15 = 239 */
+			CHECK( 0, msg_update_length ( msg ) );
+			CHECK( 239, msgdata->msg_length );
+			
+			/* Now test the grouped AVPs */	
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" );
 			  ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" );
+			  {
+				value.os.data = "12345678";
+				value.os.len = 8;
+				CHECK( 0, msg_avp_setvalue ( avpch, &value ) );
+				#if 0
+				log_debug("AVP octet string, '1234678'\n");
+				msg_dump_one(avpch);
+				#endif
+				CHECK( 0, msg_update_length ( avpch ) );
+				CHECK( 0, msg_avp_data ( avpch, &avpdata ) );
+				CHECK( 20, avpdata->avp_len );
+			  }
 			  ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" );
+			  {
+				value.os.data = "123456789";
+				value.os.len = 9;
+				CHECK( 0, msg_avp_setvalue ( avpch, &value ) );
+				#if 0
+				log_debug("AVP octet string, '12346789'\n");
+				msg_dump_one(avpch);
+				#endif
+			  }
+			
+			/* Check the size is updated recursively: (gavp hdr: 12) + (avp1: 20) + (avp2: 21) = 53 */
+			CHECK( 0, msg_update_length ( avpi ) );
+			CHECK( 0, msg_avp_data ( avpi, &avpdata ) );
+			CHECK( 53, avpdata->avp_len );
+			
+			/* Add another similar grouped AVP, to have lot of padding */
 			ADD_AVP( msg, MSG_BRW_LAST_CHILD, avpi, 73565, "AVP Test - grouped" );
 			  ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" );
+			  {
+				value.os.data = "1";
+				value.os.len = 1;
+				CHECK( 0, msg_avp_setvalue ( avpch, &value ) );
+			  }
 			  ADD_AVP( avpi, MSG_BRW_LAST_CHILD, avpch, 73565, "AVP Test - os" );
+			  {
+				value.os.data = "1234567";
+				value.os.len = 7;
+				CHECK( 0, msg_avp_setvalue ( avpch, &value ) );
+			  }
 			
-		  }
-				
+			/* Now check the global size of the message, if padding is correctly handled */
+			/* size = 20 (header) + 12 + 20 + 16 * 3 + (101 + 3) + (17 + 3) + (15 + 1) 
+			 *        + ( 12 + ( 20 + 21) + 3 )     # padding for the grouped AVP = 3
+			 *        + ( 12 + ( (13 + 3) + 19 ) )  # The first inner AVP is padded, but not the gavp since no AVP follow  
+			 * size = 240 + 56 + 47 = 343
+			 */
+			CHECK( 0, msg_update_length ( msg ) );
+			#if 0
+			msg_dump_walk(msg);
+			#endif
+			CHECK( 343, msgdata->msg_length );
+	
+		}
+		
+		/* Now test the msg_parse_rule function */
+		{
+			dict_object_t * rule;
+			
+			CHECK( 0, msg_parse_rules( msg, &rule ) );
+		}
 	
 	}
 		
--- a/waaad/tests/tests.h	Fri Jul 11 18:05:12 2008 +0900
+++ b/waaad/tests/tests.h	Fri Jul 11 18:05:39 2008 +0900
@@ -36,6 +36,7 @@
 /* This file contains the definition of our test harness.
  * The harness is very simple yet.
  * It may be interessant to go to dejagnu later...
+ *
  */
 #ifndef _TESTS_H
 #define _TESTS_H
@@ -45,6 +46,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <getopt.h>
+#include <string.h>
 
 /* The waaad API */
 #include <waaad/waaad.h>
"Welcome to our mercurial repository"