cvs: pear /SOAP/test 5.2.1.simpletypes.multiref.php 5.2.1.simpletypes.string.php 5.2.simpletypes.php all.php test.utility.php
| From: | Shane Caraveo | Date: | Mon, 25 Feb 2002 02:55:38 +0000 |
| Subject: | cvs: pear /SOAP/test 5.2.1.simpletypes.multiref.php 5.2.1.simpletypes.string.php 5.2.simpletypes.php all.php test.utility.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2605@lists.php.net to get a copy of this message | ||
shane Sun Feb 24 21:55:38 2002 EDT
Added files:
/pear/SOAP/test 5.2.1.simpletypes.multiref.php
5.2.1.simpletypes.string.php 5.2.simpletypes.php
all.php test.utility.php
Log:
add some test cases
Index: pear/SOAP/test/5.2.1.simpletypes.multiref.php +++ pear/SOAP/test/5.2.1.simpletypes.multiref.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2.1 Multi-Reference"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <greeting id="String-0">Hello</greeting> <salutation href="#String-0"/> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = array('greeting'=>'Hello'); $expect['salutation'] = &$expect['greeting']; $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Backward Reference decode OK\n"; } else { print "$prefix Backward Reference decode FAILED\n"; } $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <salutation href="#String-0"/> <greeting id="String-0">Hello</greeting> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Forward Reference decode OK\n"; } else { print "$prefix Forward Reference decode FAILED\n"; } $msg = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns5='http://soapinterop.org/xsd'> <soap:Body> <n:echoStructResponse xmlns:n='http://soapinterop.org/'> <Result href='#id0'/> </n:echoStructResponse> <id0 id='id0' soapenc:root='0' xsi:type='ns5:SOAPStruct'> <varString xsi:type='xsd:string'> arg</varString> <varInt href='#id1'/> <varFloat href='#id2'/> </id0> <id1 id='id1' soapenc:root='0' xsi:type='xsd:int'> 34</id1> <id2 id='id2' soapenc:root='0' xsi:type='xsd:float'> 325.325</id2> </soap:Body> </soap:Envelope> "; $expect = array('varString' => 'arg', 'varInt' => 34, 'varFloat' => 325.325); $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Forward Reference root decode OK\n"; } else { print "$prefix Forward Reference root decode FAILED\n"; } ?> Index: pear/SOAP/test/5.2.1.simpletypes.string.php +++ pear/SOAP/test/5.2.1.simpletypes.string.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2.1 String"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:echoStringResponse xmlns:m="http://soapinterop.org/"> <return xsi:type="xsd:string">hello world</return> </m:echoStringResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = 'hello world'; $val = parseMessage($msg); if (string_compare($expect, $val)) { print "$prefix Deserialize Message OK\n"; } else { print "$prefix Deserialize Message FAILED\n"; } # serialize a soap value $expect = '<inputString xsi:type="xsd:string">hello world</inputString>'; $v = new SOAP_Value("inputString","string","hello world"); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Type OK\n"; } else { print "$prefix Serialize Type FAILED, expected $expect, got $val\n"; } # serialize a soap value with unknown type $expect = "hello world"; $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize known SOAP_Value OK\n"; } else { print "$prefix Deserialize known SOAP_Value FAILED\n"; } # serialize a soap value with unknown type $expect = '<inputString xsi:type="xsd:string">hello world</inputString>'; $v = new SOAP_Value("inputString","","hello world"); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Unknown Type OK\n"; } else { print "$prefix Serialize Unknown Type FAILED\n"; } # serialize a soap value with unknown type $expect = "hello world"; $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize Unknown SOAP_Value OK\n"; } else { print "$prefix Deserialize Unknown SOAP_Value FAILED\n"; } ?> Index: pear/SOAP/test/5.2.simpletypes.php +++ pear/SOAP/test/5.2.simpletypes.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2 Simple Types"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <age>45</age> <height>5.9</height> <displacement>-450</displacement> <color>Blue</color> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = parseMessage($msg); if (array_compare($expect, $val)) { print "$prefix Deserialize Message OK\n"; } else { print "$prefix Deserialize Message FAILED extected $expect, got $val\n"; } # serialize a soap value $expect = '<inputStruct> <age xsi:type="xsd:int">45</age> <height xsi:type="xsd:float">5.9</height> <displacement xsi:type="xsd:negativeInteger">-450</displacement> <color xsi:type="xsd:string">Blue</color> </inputStruct> '; $v = new SOAP_Value("inputStruct","struct",array( new SOAP_Value("age","int",45), new SOAP_Value("height","float",5.9), new SOAP_Value("displacement","negativeInteger",-450), new SOAP_Value("color","string","Blue") )); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Type OK\n"; } else { print "$prefix Serialize Type FAILED\n"; } # deserialize a soap value $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize known SOAP_Value OK\n"; } else { print "$prefix Deserialize known SOAP_Value FAILED\n"; } # serialize a soap value with unknown type $expect = '<inputString> <age xsi:type="xsd:int">45</age> <height xsi:type="xsd:float">5.9</height> <displacement xsi:type="xsd:int">-450</displacement> <color xsi:type="xsd:string">Blue</color> </inputString> '; $v = new SOAP_Value("inputString","struct",array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue')); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Unknown Type OK\n"; } else { print "$prefix Serialize Unknown Type FAILED\n"; } # serialize a soap value with unknown type $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize Unknown SOAP_Value OK\n"; } else { print "$prefix Deserialize Unknown SOAP_Value FAILED\n"; } ?> Index: pear/SOAP/test/all.php +++ pear/SOAP/test/all.php <?php require_once('5.2.simpletypes.php'); require_once('5.2.1.simpletypes.string.php'); require_once('5.2.1.simpletypes.multiref.php'); ?> Index: pear/SOAP/test/test.utility.php +++ pear/SOAP/test/test.utility.php <?php require_once("SOAP/Parser.php"); require_once("SOAP/Value.php"); require_once("SOAP/Message.php"); function number_compare($f1, $f2) { # figure out which has the least fractional digits preg_match('/.*?\.(.*)/',$f1,$m1); preg_match('/.*?\.(.*)/',$f2,$m2); #print_r($m1); # always use at least 2 digits of precision $d = max(min(strlen($m1[1]),strlen($m2[1])),2); $f1 = round($f1, $d); $f2 = round($f2, $d); return bccomp($f1, $f2, $d) == 0; } function string_compare($e1, $e2) { if (is_numeric($e1) && is_numeric($e2)) { return number_compare($e1, $e2); } # handle dateTime comparison $e1_type = gettype($e1); $e2_type = gettype($e2); $ok = FALSE; if ($e1_type == "string") { $dt = new SOAP_Type_dateTime(); $ok = $dt->compare($e1, $e2) == 0; } return $ok || $e1 == $e2 || strcasecmp(trim($e1), trim($e2)) == 0; } function array_compare(&$ar1, &$ar2) { if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return FALSE; # first a shallow diff $diff = array_diff($ar1, $ar2); if (count($diff) == 0) return TRUE; # diff failed, do a full check of the array foreach ($ar1 as $k => $v) { #print "comparing $v == $ar2[$k]\n"; if (gettype($v) == "array") { if (!array_compare($v, $ar2[$k])) return FALSE; } else { if (!string_compare($v, $ar2[$k])) return FALSE; } } return TRUE; } function parseMessage($msg) { # strip line endings $msg = preg_replace('/\r|\n/', '', $msg); $response = new SOAP_Parser($msg); $return = $response->getResponse(); $v = $return->decode(); if (gettype($v) == 'array' && count($v)==1) { return array_shift($v); } return $v; } ?>
Index: pear/SOAP/test/5.2.1.simpletypes.multiref.php +++ pear/SOAP/test/5.2.1.simpletypes.multiref.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2.1 Multi-Reference"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <greeting id="String-0">Hello</greeting> <salutation href="#String-0"/> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = array('greeting'=>'Hello'); $expect['salutation'] = &$expect['greeting']; $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Backward Reference decode OK\n"; } else { print "$prefix Backward Reference decode FAILED\n"; } $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <salutation href="#String-0"/> <greeting id="String-0">Hello</greeting> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Forward Reference decode OK\n"; } else { print "$prefix Forward Reference decode FAILED\n"; } $msg = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns5='http://soapinterop.org/xsd'> <soap:Body> <n:echoStructResponse xmlns:n='http://soapinterop.org/'> <Result href='#id0'/> </n:echoStructResponse> <id0 id='id0' soapenc:root='0' xsi:type='ns5:SOAPStruct'> <varString xsi:type='xsd:string'> arg</varString> <varInt href='#id1'/> <varFloat href='#id2'/> </id0> <id1 id='id1' soapenc:root='0' xsi:type='xsd:int'> 34</id1> <id2 id='id2' soapenc:root='0' xsi:type='xsd:float'> 325.325</id2> </soap:Body> </soap:Envelope> "; $expect = array('varString' => 'arg', 'varInt' => 34, 'varFloat' => 325.325); $val = parseMessage($msg); if (array_compare($val, $expect)) { print "$prefix Forward Reference root decode OK\n"; } else { print "$prefix Forward Reference root decode FAILED\n"; } ?> Index: pear/SOAP/test/5.2.1.simpletypes.string.php +++ pear/SOAP/test/5.2.1.simpletypes.string.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2.1 String"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:echoStringResponse xmlns:m="http://soapinterop.org/"> <return xsi:type="xsd:string">hello world</return> </m:echoStringResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = 'hello world'; $val = parseMessage($msg); if (string_compare($expect, $val)) { print "$prefix Deserialize Message OK\n"; } else { print "$prefix Deserialize Message FAILED\n"; } # serialize a soap value $expect = '<inputString xsi:type="xsd:string">hello world</inputString>'; $v = new SOAP_Value("inputString","string","hello world"); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Type OK\n"; } else { print "$prefix Serialize Type FAILED, expected $expect, got $val\n"; } # serialize a soap value with unknown type $expect = "hello world"; $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize known SOAP_Value OK\n"; } else { print "$prefix Deserialize known SOAP_Value FAILED\n"; } # serialize a soap value with unknown type $expect = '<inputString xsi:type="xsd:string">hello world</inputString>'; $v = new SOAP_Value("inputString","","hello world"); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Unknown Type OK\n"; } else { print "$prefix Serialize Unknown Type FAILED\n"; } # serialize a soap value with unknown type $expect = "hello world"; $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize Unknown SOAP_Value OK\n"; } else { print "$prefix Deserialize Unknown SOAP_Value FAILED\n"; } ?> Index: pear/SOAP/test/5.2.simpletypes.php +++ pear/SOAP/test/5.2.simpletypes.php <?php require_once("SOAP/test/test.utility.php"); $prefix = "5.2 Simple Types"; $msg = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:test xmlns:m="http://soapinterop.org/"> <age>45</age> <height>5.9</height> <displacement>-450</displacement> <color>Blue</color> </m:test> </SOAP-ENV:Body> </SOAP-ENV:Envelope> '; $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = parseMessage($msg); if (array_compare($expect, $val)) { print "$prefix Deserialize Message OK\n"; } else { print "$prefix Deserialize Message FAILED extected $expect, got $val\n"; } # serialize a soap value $expect = '<inputStruct> <age xsi:type="xsd:int">45</age> <height xsi:type="xsd:float">5.9</height> <displacement xsi:type="xsd:negativeInteger">-450</displacement> <color xsi:type="xsd:string">Blue</color> </inputStruct> '; $v = new SOAP_Value("inputStruct","struct",array( new SOAP_Value("age","int",45), new SOAP_Value("height","float",5.9), new SOAP_Value("displacement","negativeInteger",-450), new SOAP_Value("color","string","Blue") )); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Type OK\n"; } else { print "$prefix Serialize Type FAILED\n"; } # deserialize a soap value $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize known SOAP_Value OK\n"; } else { print "$prefix Deserialize known SOAP_Value FAILED\n"; } # serialize a soap value with unknown type $expect = '<inputString> <age xsi:type="xsd:int">45</age> <height xsi:type="xsd:float">5.9</height> <displacement xsi:type="xsd:int">-450</displacement> <color xsi:type="xsd:string">Blue</color> </inputString> '; $v = new SOAP_Value("inputString","struct",array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue')); $val = $v->serialize(); if (string_compare($expect, $val)) { print "$prefix Serialize Unknown Type OK\n"; } else { print "$prefix Serialize Unknown Type FAILED\n"; } # serialize a soap value with unknown type $expect = array('age'=>45, 'height'=> 5.9, 'displacement' => -450, 'color' => 'Blue'); $val = $v->decode(); if (string_compare($expect, $val)) { print "$prefix Deserialize Unknown SOAP_Value OK\n"; } else { print "$prefix Deserialize Unknown SOAP_Value FAILED\n"; } ?> Index: pear/SOAP/test/all.php +++ pear/SOAP/test/all.php <?php require_once('5.2.simpletypes.php'); require_once('5.2.1.simpletypes.string.php'); require_once('5.2.1.simpletypes.multiref.php'); ?> Index: pear/SOAP/test/test.utility.php +++ pear/SOAP/test/test.utility.php <?php require_once("SOAP/Parser.php"); require_once("SOAP/Value.php"); require_once("SOAP/Message.php"); function number_compare($f1, $f2) { # figure out which has the least fractional digits preg_match('/.*?\.(.*)/',$f1,$m1); preg_match('/.*?\.(.*)/',$f2,$m2); #print_r($m1); # always use at least 2 digits of precision $d = max(min(strlen($m1[1]),strlen($m2[1])),2); $f1 = round($f1, $d); $f2 = round($f2, $d); return bccomp($f1, $f2, $d) == 0; } function string_compare($e1, $e2) { if (is_numeric($e1) && is_numeric($e2)) { return number_compare($e1, $e2); } # handle dateTime comparison $e1_type = gettype($e1); $e2_type = gettype($e2); $ok = FALSE; if ($e1_type == "string") { $dt = new SOAP_Type_dateTime(); $ok = $dt->compare($e1, $e2) == 0; } return $ok || $e1 == $e2 || strcasecmp(trim($e1), trim($e2)) == 0; } function array_compare(&$ar1, &$ar2) { if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return FALSE; # first a shallow diff $diff = array_diff($ar1, $ar2); if (count($diff) == 0) return TRUE; # diff failed, do a full check of the array foreach ($ar1 as $k => $v) { #print "comparing $v == $ar2[$k]\n"; if (gettype($v) == "array") { if (!array_compare($v, $ar2[$k])) return FALSE; } else { if (!string_compare($v, $ar2[$k])) return FALSE; } } return TRUE; } function parseMessage($msg) { # strip line endings $msg = preg_replace('/\r|\n/', '', $msg); $response = new SOAP_Parser($msg); $return = $response->getResponse(); $v = $return->decode(); if (gettype($v) == 'array' && count($v)==1) { return array_shift($v); } return $v; } ?>