nlopess         Tue Jun 27 22:54:29 2006 UTC

  Modified files:              
    /php-src/ext/libxml/tests   .cvsignore 001.phpt 002.phpt 003.phpt 
                                004.phpt test.xml 
  Log:
  MFB: new tests
  
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/.cvsignore?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/.cvsignore
diff -u /dev/null php-src/ext/libxml/tests/.cvsignore:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/.cvsignore Tue Jun 27 22:54:29 2006
@@ -0,0 +1,6 @@
+phpt.*
+*.diff
+*.log
+*.exp
+*.out
+*.php
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/001.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/001.phpt
diff -u /dev/null php-src/ext/libxml/tests/001.phpt:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/001.phpt   Tue Jun 27 22:54:29 2006
@@ -0,0 +1,31 @@
+--TEST--
+libxml_use_internal_errors()
+--SKIPIF--
+<?php if (!extension_loaded('libxml')) die('skip'); ?>
+--FILE--
+<?php
+
+var_dump(libxml_use_internal_errors(false));
+var_dump(libxml_use_internal_errors(true));
+var_dump(libxml_use_internal_errors());
+var_dump(libxml_use_internal_errors(new stdclass));
+
+var_dump(libxml_get_errors());
+var_dump(libxml_get_last_error());
+
+var_dump(libxml_clear_errors());
+
+echo "Done\n";
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+bool(true)
+
+Warning: libxml_use_internal_errors() expects parameter 1 to be boolean, 
object given in %s001.php on line 6
+NULL
+array(0) {
+}
+bool(false)
+NULL
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/002.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/002.phpt
diff -u /dev/null php-src/ext/libxml/tests/002.phpt:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/002.phpt   Tue Jun 27 22:54:29 2006
@@ -0,0 +1,113 @@
+--TEST--
+libxml_get_errors()
+--SKIPIF--
+<?php if (!extension_loaded('simplexml')) die('skip'); ?>
+--FILE--
+<?php
+
+var_dump(libxml_use_internal_errors(true));
+
+$xmlstr = <<< XML
+<?xml version='1.0' standalone='yes'?>
+    <movies>
+        <movie>
+            <titles>PHP: Behind the Parser</title>
+        </movie>
+    </movies>
+XML;
+
+$doc = simplexml_load_string($xmlstr);
+$xml = explode("\n", $xmlstr);
+
+if (!$doc) {
+       $errors = libxml_get_errors();
+
+       foreach ($errors as $error) {
+               echo display_xml_error($error, $xml);
+       }
+
+       var_dump(libxml_get_last_error());
+}
+
+
+function display_xml_error($error, $xml)
+{
+       $return  = $xml[$error->line - 1] . "\n";
+       $return .= str_repeat('-', $error->column) . "^\n";
+
+       switch ($error->level) {
+               case LIBXML_ERR_WARNING:
+                       $return .= "Warning $error->code: ";
+                       break;
+               case LIBXML_ERR_ERROR:
+                       $return .= "Error $error->code: ";
+                       break;
+               case LIBXML_ERR_FATAL:
+                       $return .= "Fatal Error $error->code: ";
+                       break;
+       }
+
+       $return .= trim($error->message) . "\n  Line: $error->line" . "\n  
Column: $error->column";
+
+       if ($error->file) {
+               $return .= "\n  File: $error->file";
+       }
+
+       return "$return\n\n--------------------------------------------\n\n";
+}
+
+
+echo "Done\n";
+?>
+--EXPECTF--
+bool(false)
+            <titles>PHP: Behind the Parser</title>
+%s
+Fatal Error 76: Opening and ending tag mismatch: titles line 4 and title
+  Line: 4
+  Column: %d
+
+--------------------------------------------
+
+object(LibXMLError)#%d (6) {
+  ["level"]=>
+  int(3)
+  ["code"]=>
+  int(76)
+  ["column"]=>
+  int(%d)
+  ["message"]=>
+  string(57) "Opening and ending tag mismatch: titles line 4 and title
+"
+  ["file"]=>
+  string(0) ""
+  ["line"]=>
+  int(4)
+}
+Done
+--UEXPECTF--
+bool(false)
+            <titles>PHP: Behind the Parser</title>
+%s
+Fatal Error 76: Opening and ending tag mismatch: titles line 4 and title
+  Line: 4
+  Column: %d
+
+--------------------------------------------
+
+object(LibXMLError)#%d (6) {
+  [u"level"]=>
+  int(3)
+  [u"code"]=>
+  int(76)
+  [u"column"]=>
+  int(%d)
+  [u"message"]=>
+  string(57) "Opening and ending tag mismatch: titles line 4 and title
+"
+  [u"file"]=>
+  string(0) ""
+  [u"line"]=>
+  int(4)
+}
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/003.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/003.phpt
diff -u /dev/null php-src/ext/libxml/tests/003.phpt:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/003.phpt   Tue Jun 27 22:54:29 2006
@@ -0,0 +1,28 @@
+--TEST--
+libxml_use_internal_errors() memory leaks
+--SKIPIF--
+<?php if (!extension_loaded('simplexml')) die('skip'); ?>
+--FILE--
+<?php
+var_dump(libxml_use_internal_errors(true));
+
+$xmlstr = <<< XML
+<?xml version='1.0' standalone='yes'?>
+    <movies>
+        <movie>
+            <titles>PHP: Behind the Parser</title>
+        </movie>
+    </movies>
+XML;
+
+simplexml_load_string($xmlstr);
+
+// test memleaks here
+var_dump(libxml_use_internal_errors(false));
+
+echo "Done\n";
+?>
+--EXPECTF--
+bool(false)
+bool(true)
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/004.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/004.phpt
diff -u /dev/null php-src/ext/libxml/tests/004.phpt:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/004.phpt   Tue Jun 27 22:54:29 2006
@@ -0,0 +1,57 @@
+--TEST--
+libxml_set_streams_context()
+--SKIPIF--
+<?php if (!extension_loaded('dom')) die('skip'); ?>
+--FILE--
+<?php
+
+$ctxs = array(
+       NULL,
+       'bogus',
+       123,
+       new stdclass,
+       array('a'),
+       stream_context_create(),
+       stream_context_create(array('file')),
+       stream_context_create(array('file' => array('some_opt' => 'aaa')))
+);
+
+
+foreach ($ctxs as $ctx) {
+       var_dump(libxml_set_streams_context($ctx));
+       $dom = new DOMDocument();
+       var_dump($dom->load(dirname(__FILE__).'/test.xml'));
+}
+
+echo "Done\n";
+
+?>
+--EXPECTF--
+Warning: stream_context_create(): options should have the form 
["wrappername"]["optionname"] = $value in %s004.php on line 10
+NULL
+
+Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context 
resource in %s004.php on line 18
+bool(true)
+NULL
+
+Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context 
resource in %s004.php on line 18
+bool(true)
+NULL
+
+Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context 
resource in %s004.php on line 18
+bool(true)
+NULL
+
+Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context 
resource in %s004.php on line 18
+bool(true)
+NULL
+
+Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context 
resource in %s004.php on line 18
+bool(true)
+NULL
+bool(true)
+NULL
+bool(true)
+NULL
+bool(true)
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/tests/test.xml?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/libxml/tests/test.xml
diff -u /dev/null php-src/ext/libxml/tests/test.xml:1.2
--- /dev/null   Tue Jun 27 22:54:29 2006
+++ php-src/ext/libxml/tests/test.xml   Tue Jun 27 22:54:29 2006
@@ -0,0 +1,8 @@
+<library>
+       <book>
+               <title>PHP made simple</title>
+       </book>
+       <book>
+               <title>learn PHP easily</title>
+       </book>
+</library>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to