Commits

Paweł Wieczorek  committed 8874558 Draft

testing parser

  • Participants
  • Parent commits e0e6058

Comments (0)

Files changed (3)

File src/Sip_types.ml

     | SIP_2_0 -> "SIP/2.0"
     | UnknownSipVersion s -> "SIP/"^ s
 
+let string_of_sip_uri = function
+    | SipUri s -> s
+
+let string_of_sip_cseq = function
+    | SipCseq s -> s
+

File tests/Test_parser.ml

 open Testdata_messages.Util
 
 let assert_str_equal msg a b =
-    assert_equal ~msg:msg ~printer:(fun x -> x) a b
+    assert_equal ~msg:msg ~printer:String.quote a b
 
 let assert_strs_equal msg a b =
-    assert_equal ~msg:msg ~printer:(fun x -> "[" ^ String.concat "," x ^ "]") a b
+    assert_equal ~msg:msg ~printer:(fun x -> "[" ^ String.concat "," (List.map String.quote x) ^ "]") a b
 
 let validate_extracted_field request conv field extracted expected =
     let actual_mime      = request#header (String.lowercase field) in
-    assert_equal expected (conv actual_mime);
-    assert_equal expected extracted
+    assert_equal ~msg:("mime field " ^ field) expected (conv actual_mime);
+    assert_equal ~msg:("extracted field" ^ field) expected extracted
 
 let validate_message request = function
     | DescrMimeField (field, expected) ->
-        let actual = request#header field in
-        assert_str_equal ("mime field " ^ field) expected actual
+        begin try
+            let actual = request#header (String.lowercase field) in
+            assert_str_equal ("mime field " ^ field) expected actual
+        with Not_found ->
+            failwith ("Cannot find header " ^ field)
+        end
 
     | DescrMimeFields (field, expected) ->
         let actual = request#header_all (String.lowercase field) in
         let extracted = request#sip_version in
         assert_equal ~msg:"incorrect sip version" ~printer:string_of_sip_version expected extracted
 
+    | DescrSipMethod expected ->
+        let extracted = request#sip_method in
+        assert_equal ~msg:"incorrect sip method" ~printer:string_of_sip_request_method expected extracted
+
+    | DescrUri expected ->
+        let extracted = request#uri in
+        assert_equal ~msg:"incorrect reques uri" ~printer:string_of_sip_uri expected extracted
+
+    | DescrCseq expected ->
+        let extracted = request#cseq in
+        validate_extracted_field request (fun s -> SipCseq s) "cseq" extracted expected
+
+    | DescrCallId expected ->
+        let extracted = request#call_id in
+        validate_extracted_field request (fun s -> SipCallId s) "call-id" extracted expected
+
 let valid_message_parse_test (title, buffer, descr) = 
     "valid message -- " ^ title >::
     begin fun () ->

File tests/data/Testdata_messages.ml

         | DescrContentLength of int
         | DescrSipVersion of sip_version
         | DescrMaxForwards of int
+        | DescrCseq of sip_cseq
+        | DescrUri of sip_uri
+        | DescrCallId of sip_call_id
+        | DescrSipMethod of sip_request_method
 
     let descr_content_length i = DescrContentLength i
     let descr_sip_version i    = DescrSipVersion i
     let descr_max_forwards i   = DescrMaxForwards i
     let descr_mime_field a b   = DescrMimeField (a,b)
     let descr_mime_fields a b  = DescrMimeFields (a,b)
+    let descr_cseq c           = DescrCseq c
+    let descr_uri c            = DescrUri c
+    let descr_sip_method c     = DescrSipMethod c
+    let descr_call_id c        = DescrCallId c
 end
 
 module Valid_messages = struct
             ; String.repeat "a" 142
             ]
 
+            [ descr_sip_method INVITE
+            ; descr_uri (SipUri "sip:bob@biloxi.com")
+            ; descr_sip_version SIP_2_0
+            ; descr_cseq (SipCseq "314159 INVITE")
+            ; descr_call_id (SipCallId "a84b4c76e66710@pc33.atlanta.com")
+            ; descr_max_forwards 70
+            ; descr_content_length 142
+            ; descr_mime_fields "Via"
+                [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
+                ]
+            ]
+
+        ; prepare_valid_message "basic invite RFC3261.4, multiline header"
+            [ "INVITE sip:bob@biloxi.com SIP/2.0" 
+            ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
+            ; "Max-Forwards: 70" 
+            ; "To: Bob <sip:bob@biloxi.com>" 
+            ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
+            ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
+            ; "CSeq: 314159 INVITE"
+            ; "Contact: <sip:alice@pc33.atlanta.com>"
+            ; "Content-Type: application/sdp"
+            ; "Test-header: header"
+            ; "  multiline"
+            ; "  test"
+            ; "Content-Length: 142"
+            ; ""
+            ; String.repeat "a" 142
+            ]
+
             [ descr_max_forwards 70
             ; descr_sip_version SIP_2_0
             ; descr_content_length 142
             ; descr_mime_fields "Via"
                 [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
                 ]
+
+            ; descr_mime_field "Test-header" "header multiline test"
             ]
 
-
         ; prepare_valid_message "invite with multipart body RFC3261.23.4.2"
             [ "INVITE sip:bob@biloxi.com SIP/2.0"
             ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8"
             ; "Date: Thu, 21 Feb 2002 13:02:03 GMT"
             ; "Contact: <sip:alice@pc33.atlanta.com>"
             ; "Content-Type: multipart/signed;"
-            ; "protocol=\"application/pkcs7-signature\";"
-            ; "micalg=sha1; boundary=boundary42"
+            ; "  protocol=\"application/pkcs7-signature\";"
+            ; "  micalg=sha1; boundary=boundary42"
             ; "Content-Length: 568"
             ; ""
             ; "--boundary42"
             ; "--boundary42-"
             ]
 
-            [ descr_max_forwards 70
+            [ descr_sip_method INVITE
+            ; descr_uri (SipUri "sip:bob@biloxi.com")
             ; descr_sip_version SIP_2_0
+            ; descr_call_id (SipCallId "a84b4c76e66710")
+            ; descr_cseq (SipCseq "314159 INVITE")
+            ; descr_max_forwards 70
+            ; descr_mime_field "date" "Thu, 21 Feb 2002 13:02:03 GMT"
+            ; descr_mime_field "content-type"
+                "multipart/signed; protocol=\"application/pkcs7-signature\"; micalg=sha1; boundary=boundary42"
             ; descr_content_length 568
             ]
 
             ]
 
 
-        ; prepare_valid_message "basic invite RFC3261.4, multiline header"
-            [ "INVITE sip:bob@biloxi.com SIP/2.0" 
-            ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
-            ; "Max-Forwards: 70" 
-            ; "To: Bob <sip:bob@biloxi.com>" 
-            ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
-            ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
-            ; "CSeq: 314159 INVITE"
-            ; "Contact: <sip:alice@pc33.atlanta.com>"
-            ; "Content-Type: application/sdp"
-            ; "Test-header: header"
-            ; " multiline"
-            ; " test"
-            ; "Content-Length: 142"
-            ; ""
-            ; String.repeat "a" 142
-            ]
-
-            [ descr_max_forwards 70
-            ; descr_sip_version SIP_2_0
-            ; descr_content_length 142
-
-            ; descr_mime_fields "Via"
-                [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
-                ]
-
-            ; descr_mime_field "Test-header" "header multiline test"
-            ]
     ]
 
 end