joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_sn_coap_parser.c Source File

test_sn_coap_parser.c

00001 /*
00002  * Copyright (c) 2015 ARM. All rights reserved.
00003  */
00004 #include "test_sn_coap_parser.h"
00005 #include <string.h>
00006 #include "stdint.h"
00007 #include "sn_nsdl.h"
00008 #include "sn_coap_header.h"
00009 #include "sn_coap_header_internal.h"
00010 #include "sn_coap_protocol_internal.h"
00011 
00012 int retCounter = 0;
00013 
00014 void* myMalloc(uint16_t size)
00015 {
00016     if( retCounter > 0 ){
00017         retCounter--;
00018         return malloc(size);
00019     }else {
00020         return NULL;
00021     }
00022 }
00023 
00024 void myFree(void* ptr){
00025     free(ptr);
00026 }
00027 
00028 bool test_sn_coap_parser()
00029 {
00030     retCounter = 0;
00031     bool ret = true;
00032     uint8_t* ptr = (uint8_t*)malloc(20);
00033     sn_coap_hdr_s * hdr = sn_coap_parser(NULL, 8, ptr, NULL);
00034     if( hdr != NULL ){
00035         free(hdr);
00036         ret = false;
00037     }
00038 
00039     if( ret ){
00040         struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00041         coap->sn_coap_protocol_malloc = myMalloc;
00042         coap->sn_coap_protocol_free = myFree;
00043         retCounter = 0;
00044         coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00045         hdr = sn_coap_parser(coap, 8, ptr, ver);
00046         if( hdr != NULL ){
00047             free(hdr);
00048             ret = false;
00049         }
00050 
00051         if( ret ){
00052             retCounter = 1;
00053             hdr = sn_coap_parser(coap, 8, ptr, ver);
00054             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00055                 free(hdr);
00056                 ret = false;
00057             }
00058             if (hdr)
00059                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00060         }
00061         free(ver);
00062         free(coap);
00063 
00064     }
00065 
00066     free(ptr);
00067     return ret;
00068 }
00069 
00070 bool test_sn_coap_parser_options_parsing()
00071 {
00072     bool ret = true;
00073     uint8_t* ptr = (uint8_t*)malloc(20);
00074     memset(ptr, 0, 20);
00075     ptr[0] = 9;
00076     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00077     coap->sn_coap_protocol_malloc = myMalloc;
00078     coap->sn_coap_protocol_free = myFree;
00079 
00080     retCounter = 1;
00081     coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00082     sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver);
00083     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00084         ret = false;
00085     }else{
00086         if (hdr)
00087             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00088         ptr[0] = 1;
00089         retCounter = 1;
00090         hdr = sn_coap_parser(coap, 8, ptr, ver);
00091         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00092             ret = false;
00093         }else{
00094             if (hdr)
00095                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00096             ptr[5] = 255; //this point is sufficient to test parsing of payload
00097             retCounter = 2;
00098             hdr = sn_coap_parser(coap, 6, ptr, ver);
00099             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00100                 ret = false;
00101             }else{
00102                 if (hdr)
00103                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00104                 ptr[5] = 239;
00105                 retCounter = 2;
00106                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00107                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00108                     ret = false;
00109                 }else{
00110                     if (hdr)
00111                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00112                     ptr[5] = 254; //15 | 14
00113                     retCounter = 2;
00114                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00115                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00116                         ret = false;
00117                     }else{
00118                         if (hdr)
00119                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00120                         ptr[5] = 238; //14 | 14
00121                         ptr[6] = 6;
00122                         ptr[7] = 7;
00123                         retCounter = 2;
00124                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00125                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00126                             ret = false;
00127                         }else{
00128                             if (hdr)
00129                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00130                             ptr[5] = 221; //13 | 13
00131                             ptr[6] = 6;
00132                             retCounter = 2;
00133                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00134                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00135                                 ret = false;
00136                             } else {
00137                                 if (hdr)
00138                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00139                             }
00140                         }
00141                     }
00142                 }
00143             }
00144         }
00145     }
00146 
00147     free(ver);
00148     free(coap);
00149     free(ptr);
00150     return ret;
00151 }
00152 
00153 bool test_sn_coap_parser_options_parsing_switches()
00154 {
00155     bool ret = true;
00156     uint8_t* ptr = (uint8_t*)malloc(20);
00157     memset(ptr, 0, 20);
00158     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00159     coap->sn_coap_protocol_malloc = myMalloc;
00160     coap->sn_coap_protocol_free = myFree;
00161     coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00162 
00163     //These should be tested:
00164     /*
00165     COAP_OPTION_IF_MATCH        = 1,
00166     COAP_OPTION_URI_HOST        = 3,
00167     COAP_OPTION_ETAG            = 4,
00168     COAP_OPTION_IF_NONE_MATCH   = 5,
00169     COAP_OPTION_OBSERVE         = 6,
00170     COAP_OPTION_URI_PORT        = 7,
00171     COAP_OPTION_LOCATION_PATH   = 8,
00172     COAP_OPTION_URI_PATH        = 11,
00173     COAP_OPTION_CONTENT_FORMAT  = 12,
00174     COAP_OPTION_MAX_AGE         = 14,
00175     COAP_OPTION_URI_QUERY       = 15,
00176     COAP_OPTION_ACCEPT          = 17,
00177     COAP_OPTION_LOCATION_QUERY  = 20,
00178     COAP_OPTION_BLOCK2          = 23,
00179     COAP_OPTION_BLOCK1          = 27,
00180     COAP_OPTION_SIZE2           = 28,
00181     COAP_OPTION_PROXY_URI       = 35,
00182     COAP_OPTION_PROXY_SCHEME    = 39,
00183     COAP_OPTION_SIZE1           = 60
00184     */
00185 
00186     ptr[0] = 1;
00187 
00188     retCounter = 2;
00189     ptr[5] = 17; //1 | 1 (number | length)
00190     sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver);
00191     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00192         ret = false;
00193     }else{
00194         if (hdr)
00195             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00196         ptr[5] = 51; //1 | 3
00197         retCounter = 2;
00198         hdr = sn_coap_parser(coap, 8, ptr, ver);
00199         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00200             ret = false;
00201         }else{
00202             if (hdr)
00203                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00204             ptr[5] = 48; //3 | 0
00205             retCounter = 3;
00206             hdr = sn_coap_parser(coap, 8, ptr, ver);
00207             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00208                 ret = false;
00209             }else{
00210                 if (hdr)
00211                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00212                 ptr[5] = 51; //3 | 3
00213                 retCounter = 3;
00214                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00215                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00216                     ret = false;
00217                 }else{
00218                     if (hdr)
00219                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00220                     ptr[5] = 51; //3 | 3
00221                     retCounter = 4;
00222                     //overflows, so not valid data
00223                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00224                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00225                         ret = false;
00226                     }else{
00227                         if (hdr)
00228                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00229                         ptr[5] = 68; //4 | 4
00230                         retCounter = 3;
00231                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00232                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00233                             ret = false;
00234                         }else{
00235                             if (hdr)
00236                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00237                             ptr[5] = 68; //4 | 4
00238                             retCounter = 4;
00239                             //This should test if (ret_status >= 0) {}
00240                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00241                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00242                                 ret = false;
00243                             }else{
00244                                 if (hdr)
00245                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00246                                 ptr[5] = 85; //5 | 5
00247                                 retCounter = 2;
00248                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00249                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00250                                     ret = false;
00251                                 }else{
00252                                     if (hdr)
00253                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00254                                     ptr[5] = 102; //6 | 6
00255                                     retCounter = 3;
00256                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00257                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00258                                         ret = false;
00259                                     }else{
00260                                         if (hdr)
00261                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00262                                         ptr[5] = 97; //6 | 1
00263                                         retCounter = 3;
00264                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00265                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00266                                             ret = false;
00267                                         }else{
00268                                             if (hdr)
00269                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00270                                             ptr[5] = 97; //6 | 1
00271                                             retCounter = 4;
00272                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00273                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00274                                                 ret = false;
00275                                             }else{
00276                                                 if (hdr)
00277                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00278                                                 ptr[5] = 119; //7 | 7
00279                                                 retCounter = 3;
00280                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00281                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00282                                                     ret = false;
00283                                                 }else{
00284                                                     if (hdr)
00285                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00286                                                     ptr[5] = 113; //7 | 1
00287                                                     retCounter = 3;
00288                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00289                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00290                                                         ret = false;
00291                                                     }else{
00292                                                         if (hdr)
00293                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00294                                                         ptr[5] = 113; //7 | 1
00295                                                         retCounter = 4;
00296                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00297                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00298                                                             ret = false;
00299                                                         }else{
00300                                                             if (hdr)
00301                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00302                                                             ptr[5] = 128; //8 | 8
00303                                                             retCounter = 3;
00304                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00305                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00306                                                                 ret = false;
00307                                                             }else{
00308                                                                 if (hdr)
00309                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00310                                                                 ptr[5] = 136; //8 | 8
00311                                                                 retCounter = 4;
00312                                                                 //This should test if (ret_status >= 0) {}
00313                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00314                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00315                                                                     ret = false;
00316                                                                 }else{
00317                                                                     if (hdr)
00318                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00319                                                                     ptr[5] = 187; //11 | 11
00320                                                                     retCounter = 2;
00321                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00322                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00323                                                                         ret = false;
00324                                                                     }else{
00325                                                                         if (hdr)
00326                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00327                                                                         ptr[5] = 187; //11 | 11
00328                                                                         retCounter = 3;
00329                                                                         //This should test if (ret_status >= 0) {}
00330                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00331                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00332                                                                             ret = false;
00333                                                                         }else{
00334                                                                             if (hdr)
00335                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00336                                                                             ptr[5] = 204; //12 | 12
00337                                                                             retCounter = 2;
00338                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00339                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00340                                                                                 ret = false;
00341                                                                             }else{
00342                                                                                 if (hdr)
00343                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00344                                                                                 ptr[5] = 193; //12 | 1
00345                                                                                 retCounter = 2;
00346                                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00347                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00348                                                                                     ret = false;
00349                                                                                 }else{
00350                                                                                     if (hdr)
00351                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00352                                                                                     ptr[5] = 193; //12 | 1
00353                                                                                     retCounter = 3;
00354                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00355                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00356                                                                                         ret = false;
00357                                                                                     }else{
00358                                                                                         if (hdr)
00359                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00360                                                                                         ptr[5] = 216; //13 | 8
00361                                                                                         ptr[6] = 1; //1 -> 14
00362                                                                                         retCounter = 3;
00363                                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00364                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00365                                                                                             ret = false;
00366                                                                                         }else{
00367                                                                                             if (hdr)
00368                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00369                                                                                             ptr[5] = 209; //13 | 1
00370                                                                                             ptr[6] = 1; //1 -> 14
00371                                                                                             retCounter = 3;
00372                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00373                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00374                                                                                                 ret = false;
00375                                                                                             }else{
00376                                                                                                 if (hdr)
00377                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00378                                                                                                 ptr[5] = 210; //13 | 2
00379                                                                                                 ptr[6] = 1; //1 -> 14
00380                                                                                                 retCounter = 4;
00381                                                                                                 hdr = sn_coap_parser(coap, 6, ptr, ver);
00382                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00383                                                                                                     ret = false;
00384                                                                                                 }else{
00385                                                                                                     if (hdr)
00386                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00387                                                                                                     ptr[5] = 208; //13 | 0
00388                                                                                                     ptr[6] = 2;   //2 -> 15 ???
00389                                                                                                     retCounter = 3;
00390                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00391                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00392                                                                                                         ret = false;
00393                                                                                                     }else{
00394                                                                                                         if (hdr)
00395                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00396                                                                                                         ptr[5] = 209; //13 | 1
00397                                                                                                         ptr[6] = 2;   //2 -> 15 ???
00398                                                                                                         retCounter = 5;
00399                                                                                                         //This should test if (ret_status >= 0) {}
00400                                                                                                         hdr = sn_coap_parser(coap, 7, ptr, ver);
00401                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00402                                                                                                             ret = false;
00403                                                                                                         }else{
00404                                                                                                             if (hdr)
00405                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00406                                                                                                             ptr[5] = 208; //13 | 0
00407                                                                                                             ptr[6] = 4;
00408                                                                                                             retCounter = 3;
00409                                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00410                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00411                                                                                                                 ret = false;
00412                                                                                                             }else{
00413                                                                                                                 if (hdr)
00414                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00415                                                                                                                 ptr[5] = 209; //13 | 1
00416                                                                                                                 ptr[6] = 4;
00417                                                                                                                 retCounter = 5;
00418                                                                                                                 //This should test if (ret_status >= 0) {}
00419                                                                                                                 hdr = sn_coap_parser(coap, 7, ptr, ver);
00420                                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00421                                                                                                                     ret = false;
00422                                                                                                                 }else{
00423                                                                                                                     if (hdr)
00424                                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00425                                                                                                                     ptr[5] = 208; //13 | 0
00426                                                                                                                     ptr[6] = 7;
00427                                                                                                                     retCounter = 3;
00428                                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00429                                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00430                                                                                                                         ret = false;
00431                                                                                                                     }else{
00432                                                                                                                         if (hdr)
00433                                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00434                                                                                                                         ptr[5] = 209; //13 | 1
00435                                                                                                                         ptr[6] = 7;
00436                                                                                                                         retCounter = 5;
00437                                                                                                                         //This should test if (ret_status >= 0) {}
00438                                                                                                                         hdr = sn_coap_parser(coap, 7, ptr, ver);
00439                                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00440                                                                                                                             ret = false;
00441                                                                                                                         }else{
00442                                                                                                                             if (hdr)
00443                                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00444                                                                                                                             ptr[5] = 216; //13 | 8
00445                                                                                                                             ptr[6] = 10;
00446                                                                                                                             retCounter = 3;
00447                                                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00448                                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00449                                                                                                                                 ret = false;
00450                                                                                                                             }else{
00451                                                                                                                                 if (hdr)
00452                                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00453                                                                                                                                 ptr[5] = 209; //13 | 1
00454                                                                                                                                 ptr[6] = 10;
00455                                                                                                                                 retCounter = 3;
00456                                                                                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00457                                                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00458                                                                                                                                     ret = false;
00459                                                                                                                                 }else{
00460                                                                                                                                     if (hdr)
00461                                                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00462                                                                                                                                     ptr[5] = 210; //13 | 2
00463                                                                                                                                     ptr[6] = 10;
00464                                                                                                                                     retCounter = 4;
00465                                                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00466                                                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00467                                                                                                                                         ret = false;
00468                                                                                                                                     }else{
00469                                                                                                                                         if (hdr)
00470                                                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00471                                                                                                                                         ptr[5] = 216; //13 | 8
00472                                                                                                                                         ptr[6] = 14;
00473                                                                                                                                         retCounter = 3;
00474                                                                                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00475                                                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00476                                                                                                                                             ret = false;
00477                                                                                                                                         }else{
00478                                                                                                                                             if (hdr)
00479                                                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00480                                                                                                                                             ptr[5] = 209; //13 | 1
00481                                                                                                                                             ptr[6] = 14;
00482                                                                                                                                             retCounter = 3;
00483                                                                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00484                                                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00485                                                                                                                                                 ret = false;
00486                                                                                                                                             }else{
00487                                                                                                                                                 if (hdr)
00488                                                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00489                                                                                                                                                 ptr[5] = 210; //13 | 2
00490                                                                                                                                                 ptr[6] = 14;
00491                                                                                                                                                 retCounter = 4;
00492                                                                                                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00493                                                                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00494                                                                                                                                                     ret = false;
00495                                                                                                                                                 }else{
00496                                                                                                                                                     if (hdr)
00497                                                                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00498                                                                                                                                                     ptr[5] = 208; //13 | 0
00499                                                                                                                                                     ptr[6] = 22;
00500                                                                                                                                                     retCounter = 3;
00501                                                                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00502                                                                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00503                                                                                                                                                         ret = false;
00504                                                                                                                                                     }else{
00505                                                                                                                                                         if (hdr)
00506                                                                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00507                                                                                                                                                         ptr[5] = 209; //13 | 1
00508                                                                                                                                                         ptr[6] = 22;
00509                                                                                                                                                         retCounter = 3;
00510                                                                                                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00511                                                                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00512                                                                                                                                                             ret = false;
00513                                                                                                                                                         }else{
00514                                                                                                                                                             if (hdr)
00515                                                                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00516                                                                                                                                                             ptr[5] = 209; //13 | 1
00517                                                                                                                                                             ptr[6] = 22;
00518                                                                                                                                                             retCounter = 4;
00519                                                                                                                                                             hdr = sn_coap_parser(coap, 7, ptr, ver);
00520                                                                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00521                                                                                                                                                                 ret = false;
00522                                                                                                                                                             }else{
00523                                                                                                                                                                 if (hdr)
00524                                                                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00525                                                                                                                                                                 ptr[5] = 208; //13 | 0
00526                                                                                                                                                                 ptr[6] = 26;
00527                                                                                                                                                                 retCounter = 2;
00528                                                                                                                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00529                                                                                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00530                                                                                                                                                                     ret = false;
00531                                                                                                                                                                 }else{
00532                                                                                                                                                                     if (hdr)
00533                                                                                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00534                                                                                                                                                                     ptr[5] = 208; //13 | 0
00535                                                                                                                                                                     ptr[6] = 47;
00536                                                                                                                                                                     retCounter = 2;
00537                                                                                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00538                                                                                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00539                                                                                                                                                                         ret = false;
00540                                                                                                                                                                     }else{
00541                                                                                                                                                                         if (hdr)
00542                                                                                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00543                                                                                                                                                                         ptr[5] = 216; //13 | 8
00544                                                                                                                                                                         ptr[6] = 47;
00545                                                                                                                                                                         retCounter = 3;
00546                                                                                                                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00547                                                                                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00548                                                                                                                                                                             ret = false;
00549                                                                                                                                                                         }else{
00550                                                                                                                                                                             if (hdr)
00551                                                                                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00552                                                                                                                                                                             ptr[5] = 209; //13 | 1
00553                                                                                                                                                                             ptr[6] = 47;
00554                                                                                                                                                                             retCounter = 3;
00555                                                                                                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00556                                                                                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00557                                                                                                                                                                                 ret = false;
00558                                                                                                                                                                             }else{
00559                                                                                                                                                                                 if (hdr)
00560                                                                                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00561                                                                                                                                                                                 ptr[5] = 210; //13 | 2
00562                                                                                                                                                                                 ptr[6] = 47;
00563                                                                                                                                                                                 retCounter = 4;
00564                                                                                                                                                                                 hdr = sn_coap_parser(coap, 8, ptr, ver);
00565                                                                                                                                                                                 if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00566                                                                                                                                                                                     ret = false;
00567                                                                                                                                                                                 }else{
00568                                                                                                                                                                                     if (hdr)
00569                                                                                                                                                                                         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00570                                                                                                                                                                                     ptr[5] = 209; //13 | 1
00571                                                                                                                                                                                     ptr[6] = 15;
00572                                                                                                                                                                                     retCounter = 3;
00573                                                                                                                                                                                     hdr = sn_coap_parser(coap, 8, ptr, ver);
00574                                                                                                                                                                                     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00575                                                                                                                                                                                         ret = false;
00576                                                                                                                                                                                     } else {
00577                                                                                                                                                                                         if (hdr)
00578                                                                                                                                                                                             sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00579                                                                                                                                                                                         ptr[5] = 210; //13 | 2
00580                                                                                                                                                                                         ptr[6] = 15;
00581                                                                                                                                                                                         retCounter = 4;
00582                                                                                                                                                                                         hdr = sn_coap_parser(coap, 8, ptr, ver);
00583                                                                                                                                                                                         if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00584                                                                                                                                                                                             ret = false;
00585                                                                                                                                                                                         }else{
00586                                                                                                                                                                                             if (hdr)
00587                                                                                                                                                                                                 sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00588                                                                                                                                                                                             ptr[5] = 216; //13 | 8
00589                                                                                                                                                                                             ptr[6] = 15;
00590                                                                                                                                                                                             retCounter = 3;
00591                                                                                                                                                                                             hdr = sn_coap_parser(coap, 8, ptr, ver);
00592                                                                                                                                                                                             if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00593                                                                                                                                                                                                 ret = false;
00594                                                                                                                                                                                             }else{
00595                                                                                                                                                                                                 if (hdr)
00596                                                                                                                                                                                                     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00597                                                                                                                                                                                             }
00598                                                                                                                                                                                         }
00599                                                                                                                                                                                     }
00600                                                                                                                                                                                 }
00601                                                                                                                                                                             }
00602                                                                                                                                                                         }
00603                                                                                                                                                                     }
00604                                                                                                                                                                 }
00605                                                                                                                                                             }
00606                                                                                                                                                         }
00607                                                                                                                                                     }
00608                                                                                                                                                 }
00609                                                                                                                                             }
00610                                                                                                                                         }
00611                                                                                                                                     }
00612                                                                                                                                 }
00613                                                                                                                             }
00614                                                                                                                         }
00615                                                                                                                     }
00616                                                                                                                 }
00617                                                                                                             }
00618                                                                                                         }
00619                                                                                                     }
00620                                                                                                 }
00621                                                                                             }
00622                                                                                         }
00623                                                                                     }
00624                                                                                 }
00625                                                                             }
00626                                                                         }
00627                                                                     }
00628                                                                 }
00629                                                             }
00630                                                         }
00631                                                     }
00632                                                 }
00633                                             }
00634                                         }
00635                                     }
00636                                 }
00637                             }
00638                         }
00639                     }
00640                 }
00641             }
00642         }
00643     }
00644 
00645     ptr[5] = 209; //13 | 1
00646     ptr[6] = 10;
00647     retCounter = 4;
00648     hdr = sn_coap_parser(coap, 8, ptr, ver);
00649     if( hdr == NULL ){
00650         ret = false;
00651     }else{
00652         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00653     }
00654 
00655     free(ver);
00656     free(coap);
00657     free(ptr);
00658     return ret;
00659 }
00660 
00661 bool test_sn_coap_parser_options_count_needed_memory_multiple_option()
00662 {
00663     bool ret = true;
00664     uint8_t* ptr = (uint8_t*)malloc(65635);
00665     memset(ptr, 0, 65635);
00666     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00667     coap->sn_coap_protocol_malloc = myMalloc;
00668     coap->sn_coap_protocol_free = myFree;
00669     coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00670 
00671     //Some of these should be tested:
00672     //These 6 will test sn_coap_parser_options_count_needed_memory_multiple_option overflows
00673     ptr[0] = 1;
00674     ptr[5] = 0x4d; //4 | 13
00675     ptr[6] = 254;
00676     retCounter = 4;
00677     //This should test if (ret_status >= 0) {}
00678     sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver);
00679     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00680         ret = false;
00681         goto end;
00682     }
00683     if (hdr)
00684         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00685 
00686     ptr[0] = 1;
00687     ptr[5] = 0x8d; //4 | 13
00688     ptr[6] = 254;
00689     retCounter = 4;
00690     //This should test if (ret_status >= 0) {}
00691     hdr = sn_coap_parser(coap, 8, ptr, ver);
00692     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00693         ret = false;
00694         goto end;
00695     }
00696     if (hdr)
00697         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00698 
00699     ptr[0] = 1;
00700     ptr[5] = 0xbd;
00701     ptr[6] = 254;
00702     retCounter = 4;
00703     //This should test if (ret_status >= 0) {}
00704     hdr = sn_coap_parser(coap, 8, ptr, ver);
00705     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00706         ret = false;
00707         goto end;
00708     }
00709     if (hdr)
00710         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00711 
00712     ptr[0] = 1;
00713     ptr[5] = 0xdd;
00714     ptr[6] = 2;
00715     ptr[7] = 254;
00716     retCounter = 4;
00717     //This should test if (ret_status >= 0) {}
00718     hdr = sn_coap_parser(coap, 8, ptr, ver);
00719     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00720         ret = false;
00721         goto end;
00722     }
00723     if (hdr)
00724         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00725 
00726     ptr[0] = 1;
00727     ptr[5] = 0xdd;
00728     ptr[6] = 4;
00729     ptr[7] = 254;
00730     retCounter = 4;
00731     //This should test if (ret_status >= 0) {}
00732     hdr = sn_coap_parser(coap, 8, ptr, ver);
00733     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00734         ret = false;
00735         goto end;
00736     }
00737     if (hdr)
00738         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00739 
00740     ptr[0] = 1;
00741     ptr[5] = 0xdd;
00742     ptr[6] = 7;
00743     ptr[7] = 254;
00744     retCounter = 4;
00745     //This should test if (ret_status >= 0) {}
00746     hdr = sn_coap_parser(coap, 8, ptr, ver);
00747     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00748         ret = false;
00749         goto end;
00750     }
00751     if (hdr)
00752         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00753 
00754     ptr[0] = 1;
00755     ptr[5] = 0x81;
00756     ptr[6] = 0x00;
00757     ptr[7] = 0x20;
00758     retCounter = 4;
00759     //This should test if (ret_status >= 0) {}
00760     hdr = sn_coap_parser(coap, 8, ptr, ver);
00761     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00762         ret = false;
00763         goto end;
00764     }
00765     if (hdr)
00766         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00767 
00768     ptr[0] = 1;
00769     ptr[5] = 0x81;
00770     ptr[6] = 0x00;
00771     ptr[7] = 0x00;
00772     retCounter = 4;
00773     //This should test if (ret_status >= 0) {}
00774     hdr = sn_coap_parser(coap, 6, ptr, ver);
00775     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00776         ret = false;
00777         goto end;
00778     }
00779     if (hdr)
00780         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00781 
00782     ptr[0] = 1;
00783     ptr[5] = 0x81;
00784     ptr[6] = 0x00;
00785     ptr[7] = 0x0d;
00786     retCounter = 4;
00787     //This should test if (ret_status >= 0) {}
00788     hdr = sn_coap_parser(coap, 8, ptr, ver);
00789     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00790         ret = false;
00791         goto end;
00792     }
00793     if (hdr)
00794         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00795 
00796     ptr[0] = 1;
00797     ptr[5] = 0x81;
00798     ptr[6] = 0x00;
00799     ptr[7] = 0x0e;
00800     retCounter = 4;
00801     //This should test if (ret_status >= 0) {}
00802     hdr = sn_coap_parser(coap, 8, ptr, ver);
00803     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00804         ret = false;
00805         goto end;
00806     }
00807     if (hdr)
00808         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00809 
00810     ptr[0] = 1;
00811     ptr[5] = 0x81;
00812     ptr[6] = 0x00;
00813     ptr[7] = 0x0f;
00814     retCounter = 4;
00815     //This should test if (ret_status >= 0) {}
00816     hdr = sn_coap_parser(coap, 8, ptr, ver);
00817     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00818         ret = false;
00819         goto end;
00820     }
00821     if (hdr)
00822         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00823 
00824 end:    
00825     free(ver);
00826     free(coap);
00827     free(ptr);
00828     return ret;
00829 }
00830 
00831 bool test_sn_coap_parser_options_parse_multiple_options()
00832 {
00833     bool ret = true;
00834     uint8_t* ptr = (uint8_t*)malloc(33);
00835     memset(ptr, 0, 33);
00836     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00837     coap->sn_coap_protocol_malloc = myMalloc;
00838     coap->sn_coap_protocol_free = myFree;
00839     coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00840 
00841     ptr[0] = 0x60;
00842     ptr[4] = 0x82; //opt 8 & len 2
00843     ptr[5] = 0x00;
00844     ptr[6] = 0x00;
00845     ptr[7] = 0x0d;
00846     ptr[8] = 0x00;
00847     ptr[9] = 0x6f;
00848     ptr[10] = 0x6d;
00849     ptr[11] = 0x61;
00850     ptr[12] = 0x69;
00851     ptr[13] = 0x6e;
00852     retCounter = 4;
00853     sn_coap_hdr_s *hdr = sn_coap_parser(coap, 14, ptr, ver);
00854     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00855         ret = false;
00856         goto end2;
00857     }
00858     if (hdr)
00859         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00860 
00861 
00862     ptr[7] = 0x0e;
00863     ptr[8] = 0xff;
00864     ptr[9] = 0x00;
00865     retCounter = 4;
00866     hdr = sn_coap_parser(coap, 14, ptr, ver);
00867     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00868         ret = false;
00869         goto end2;
00870     }
00871     if (hdr)
00872         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00873 
00874     ptr[0] = 0x60;
00875     ptr[4] = 0x42;
00876     ptr[5] = 0x00;
00877     ptr[6] = 0x00;
00878     ptr[7] = 0x06;
00879     ptr[8] = 0x00;
00880     ptr[9] = 0x6f;
00881     ptr[10] = 0x6d;
00882     ptr[11] = 0x61;
00883     ptr[12] = 0x69;
00884     ptr[13] = 0x6e;
00885     retCounter = 4;
00886     hdr = sn_coap_parser(coap, 14, ptr, ver);
00887     if( hdr == NULL ){
00888         ret = false;
00889         goto end2;
00890     }else{
00891         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00892     }
00893 
00894     free(ptr);
00895     ptr = (uint8_t*)malloc(10);
00896     memset(ptr, 0, 10);
00897 
00898     //this should be checked after bug http://jira.arm.com/browse/IOTCLT-244 is fixed
00899     //This is illegal options message, but gets parsed though
00900     //this test passes because parsing of data still fails (expected)
00901     ptr[0] = 0x60;
00902     ptr[4] = 0x82;
00903     ptr[5] = 0x00;
00904     ptr[6] = 0x00;
00905     ptr[7] = 0x06;
00906     ptr[8] = 0x00;
00907     ptr[9] = 0x6f;
00908     retCounter = 4;
00909     hdr = sn_coap_parser(coap, 10, ptr, ver);
00910     if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){
00911         ret = false;
00912         goto end2;
00913     }
00914     if (hdr)
00915         sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00916 
00917 end2:
00918     free(ver);
00919     free(coap);
00920     free(ptr);
00921     return ret;
00922 }
00923 
00924 bool test_sn_coap_parser_parsing()
00925 {
00926     bool ret = true;
00927     uint8_t* ptr = (uint8_t*)malloc(33);
00928     memset(ptr, 0, 33);
00929     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00930     coap->sn_coap_protocol_malloc = myMalloc;
00931     coap->sn_coap_protocol_free = myFree;
00932     coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e));
00933 
00934     ptr[0] = 0x60;
00935     ptr[4] = 0x42;
00936     ptr[5] = 0x00;
00937     ptr[6] = 0x00;
00938     retCounter = 4;
00939 
00940     //TODO: add sn_coap_parser_parsing related stuff
00941     ptr[7] = 0x20;
00942     ptr[8] = 0x00;
00943 
00944     sn_coap_hdr_s *hdr = NULL;
00945 
00946     //this should test parsing without payload marker, but it is not possible
00947 //    hdr = sn_coap_parser(coap, 9, ptr, ver);
00948 
00949 //    if( hdr != NULL ){
00950 //        ret = false;
00951 //        goto end3;
00952 //    }
00953 //    sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00954 
00955     ptr[0] = 0x60;
00956     ptr[4] = 0x42;
00957     ptr[5] = 0x00;
00958     ptr[6] = 0x00;
00959     ptr[7] = 0x06;
00960     ptr[8] = 0x00;
00961     ptr[9] = 0x6f;
00962     ptr[10] = 0x6d;
00963     ptr[11] = 0x61;
00964     ptr[12] = 0x69;
00965     ptr[13] = 0x6e;
00966     ptr[14] = 0xff;
00967     ptr[15] = 0x1;
00968     retCounter = 4;
00969 
00970     hdr = sn_coap_parser(coap, 16, ptr, ver);
00971 
00972     if( hdr == NULL ){
00973         ret = false;
00974         goto end3;
00975     }
00976 
00977     sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr);
00978 
00979 end3:
00980     free(ver);
00981     free(coap);
00982     free(ptr);
00983     return ret;
00984 }
00985 
00986 bool test_sn_coap_parser_release_allocated_coap_msg_mem()
00987 {
00988     struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s));
00989     coap->sn_coap_protocol_malloc = myMalloc;
00990     coap->sn_coap_protocol_free = myFree;
00991     retCounter = 99;
00992 
00993     sn_coap_parser_release_allocated_coap_msg_mem( NULL, NULL );
00994 
00995     sn_coap_hdr_s* ptr = (sn_coap_hdr_s*)myMalloc(sizeof(sn_coap_hdr_s));
00996     ptr->uri_path_ptr = (uint8_t*)malloc(sizeof(uint8_t));
00997     ptr->token_ptr = (uint8_t*)malloc(sizeof(uint8_t));
00998     ptr->content_type_ptr = (uint8_t*)malloc(sizeof(uint8_t));
00999     //ptr->payload_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01000     ptr->options_list_ptr = (sn_coap_options_list_s*)myMalloc(sizeof(sn_coap_options_list_s));
01001 
01002     ptr->options_list_ptr->max_age_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01003     ptr->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01004     ptr->options_list_ptr->etag_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01005     ptr->options_list_ptr->uri_host_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01006     ptr->options_list_ptr->location_path_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01007     ptr->options_list_ptr->uri_port_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01008     ptr->options_list_ptr->location_query_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01009     ptr->options_list_ptr->observe_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01010     ptr->options_list_ptr->accept_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01011     ptr->options_list_ptr->uri_query_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01012     ptr->options_list_ptr->block1_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01013     ptr->options_list_ptr->block2_ptr = (uint8_t*)malloc(sizeof(uint8_t));
01014 
01015     sn_coap_parser_release_allocated_coap_msg_mem( coap, ptr );
01016 
01017     free(coap);
01018     return true; //this is a memory leak check, so that will pass/fail
01019 }
01020