Navigation


Changeset 35:6486e97f56ae in freeDiameter for freeDiameter/tests/testmesg.c


Ignore:
Timestamp:
Nov 2, 2009, 2:54:42 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added test for modified message parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/tests/testmesg.c

    r10 r35  
    283283                        ADD_RULE(gavp, 73565, "AVP Test - enumos",          RULE_OPTIONAL,     0, 1, 0);
    284284                        ADD_RULE(gavp, 73565, "AVP Test - grouped",         RULE_FIXED_TAIL,  -1, 1, 1);
    285                        
     285                        /* ABNF :
     286                                < no vendor - f32 >
     287                                < i64 >
     288                                < enumi32 >
     289                            2*3 { os }
     290                             *1 [ enumos ]
     291                                < grouped >
     292                                                */
    286293                        #if 0
    287294                        fd_dict_dump_object ( gavp );
     
    728735                /* Now test the msg_parse_rule function */
    729736                {
    730                         struct dict_object * rule;
    731                        
    732                         CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &rule ) );
     737                        struct fd_pei pei;
     738                       
     739                        CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) );
    733740                       
    734741                        /* Use the "AVP Test - rules" AVP to test the rules */
     
    749756                               
    750757                                /* Check the message is still conform */
    751                                 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &rule ) );
     758                                CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) );
    752759                               
    753760                                /* The first avp is optional in fixed position, so remove it and check the message is still OK */
    754761                                CHECK( 0, fd_msg_browse ( tavp, MSG_BRW_FIRST_CHILD, &childavp, NULL) );
    755762                                CHECK( 0, fd_msg_free ( childavp ) );
    756                                 CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &rule ) );
     763                                CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) );
    757764                                ADD_AVP( tavp, MSG_BRW_FIRST_CHILD, childavp,     0, "AVP Test - no vendor - f32" );
    758765                               
    759766                               
    760767                                /* Now break some rules and check it is detected */
    761                                 #define CHECK_CONFLICT( _msg, _ruleavp, _avpvendor )            {                               \
    762                                         struct dict_object * _rule;                                                             \
    763                                         CHECK( EBADMSG,  fd_msg_parse_rules( _msg, fd_g_config->cnf_dict, &_rule ) );                   \
    764                                         if ((_ruleavp) == NULL) {                                                               \
    765                                                 CHECK( NULL, _rule);                                                            \
     768                                #define CHECK_CONFLICT( _msg, _error, _conflictavp_name, _conflictavp_vnd )             {       \
     769                                        struct fd_pei _pei;                                                                     \
     770                                        CHECK( EBADMSG,  fd_msg_parse_rules( _msg, fd_g_config->cnf_dict, &_pei ) );            \
     771                                        if (_error) {                                                                           \
     772                                                CHECK( 0, strcmp( _error, _pei.pei_errcode ) );                                 \
     773                                        }                                                                                       \
     774                                        if ((_conflictavp_name) == NULL) {                                                      \
     775                                                CHECK( NULL, _pei.pei_avp);                                                     \
    766776                                        } else {                                                                                \
    767                                                 struct dict_rule_data   _ruledata;                                              \
     777                                                struct dict_avp_request _req = { (_conflictavp_vnd), 0, (_conflictavp_name) };  \
    768778                                                struct dict_object *    _avp;                                                   \
    769                                                 struct dict_avp_request _req = { (_avpvendor), 0, (_ruleavp) };                 \
     779                                                struct dict_object * _conflict;                                                 \
     780                                                CHECK( 1, (_pei.pei_avp) ? 1 : 0 );                                             \
     781                                                CHECK( 0, fd_msg_model( _pei.pei_avp, &_conflict ) );                           \
    770782                                                CHECK( 0, fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));      \
    771                                                 CHECK( 0, fd_dict_getval( _rule, &_ruledata ) );                                \
    772                                                 CHECK( _avp, _ruledata.rule_avp );                                              \
     783                                                CHECK( _avp, _conflict );                                                       \
    773784                                        }                                                                                       \
    774785                                }
    775786
     787                        /* ABNF :
     788                                < no vendor - f32 >
     789                                < i64 >
     790                                < enumi32 >
     791                            2*3 { os }
     792                             *1 [ enumos ]
     793                                < grouped >
     794                                                */
    776795                                {
    777796                                        /* Test the FIXED_HEAD rules positions: add another AVP before the third */
     
    780799                                        ADD_AVP( tempavp, MSG_BRW_NEXT, childavp, 73565, "AVP Test - os" );
    781800                                       
    782                                         CHECK_CONFLICT( msg, "AVP Test - enumi32", 73565 );
     801                                        CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - enumi32", 73565 );
    783802                                       
    784803                                        /* Now remove this AVP */
     
    790809                                        CHECK( 0, fd_msg_free ( childavp ) );
    791810                                       
    792                                         CHECK_CONFLICT( msg, "AVP Test - enumi32", 73565 );
     811                                        CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - enumi32", 73565 );
    793812                                       
    794813                                        /* Add the AVP back */
     
    801820                                        CHECK( 0, fd_msg_free ( tempavp ) );
    802821                                       
    803                                         CHECK_CONFLICT( msg, "AVP Test - os", 73565 );  /* The rule requires at least 2 AVP, we have only 1 */
     822                                        CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - os", 73565 ); /* The rule requires at least 2 AVP, we have only 1 */
    804823                                       
    805824                                        /* Now add this AVP */
     
    811830                                        ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - os" );
    812831                                       
    813                                         CHECK_CONFLICT( msg, "AVP Test - os", 73565 );  /* The rule requires at most 3 AVP, we have 4 */
     832                                        CHECK_CONFLICT( msg, "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES", "AVP Test - os", 73565 ); /* The rule requires at most 3 AVP, we have 4 */
    814833                                       
    815834                                        /* Now delete these AVP */
     
    824843                                       
    825844                                        /* The message is still conform */
    826                                         CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &rule ) );
     845                                        CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->cnf_dict, &pei ) );
    827846                                       
    828847                                        /* Now break the rule */
    829848                                        ADD_AVP( childavp, MSG_BRW_NEXT, tempavp, 73565, "AVP Test - enumos" );
    830849                                       
    831                                         CHECK_CONFLICT( msg, "AVP Test - enumos", 73565 );      /* The rule requires at most 3 AVP, we have 4 */
     850                                        CHECK_CONFLICT( msg, "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES", "AVP Test - enumos", 73565 );
    832851                                       
    833852                                        /* Now delete this AVP */
     
    839858                                        ADD_AVP( tavp, MSG_BRW_LAST_CHILD, childavp, 73565, "AVP Test - os" );
    840859                                       
    841                                         CHECK_CONFLICT( msg, "AVP Test - grouped", 73565 );
     860                                        CHECK_CONFLICT( msg, "DIAMETER_MISSING_AVP", "AVP Test - grouped", 73565 );
    842861                                       
    843862                                        /* Now remove this AVP */
Note: See TracChangeset for help on using the changeset viewer.