Verify in a test that StringStream doesn't duplicate the string being streamed in...
authorChuck Hagenbuch <chuck@horde.org>
Tue, 13 Oct 2009 03:04:14 +0000 (23:04 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 13 Oct 2009 03:05:51 +0000 (23:05 -0400)
framework/Support/test/Horde/Support/StringStreamTest.php [new file with mode: 0644]

diff --git a/framework/Support/test/Horde/Support/StringStreamTest.php b/framework/Support/test/Horde/Support/StringStreamTest.php
new file mode 100644 (file)
index 0000000..8ab437b
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Support
+ * @subpackage UnitTests
+ * @copyright  2008-2009 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+
+/**
+ * @group      support
+ * @category   Horde
+ * @package    Support
+ * @subpackage UnitTests
+ * @copyright  2008-2009 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+class Horde_Support_StringStreamTest extends PHPUnit_Framework_TestCase
+{
+    public function testMemoryUsage()
+    {
+        $dummy = '';
+        $dummy = new Horde_Support_StringStream($dummy);
+
+        $bytes = 1024 * 1024;
+        $string = str_repeat('*', $bytes);
+        $memoryUsage = memory_get_usage();
+
+        $stream = new Horde_Support_StringStream($string);
+        $memoryUsage2 = memory_get_usage();
+        $this->assertLessThan($memoryUsage + $bytes, $memoryUsage2);
+
+        $fp = $stream->fopen();
+        $memoryUsage3 = memory_get_usage();
+        $this->assertLessThan($memoryUsage + $bytes, $memoryUsage3);
+
+        while (!feof($fp)) { fread($fp, 1024); }
+        $memoryUsage4 = memory_get_usage();
+        $this->assertLessThan($memoryUsage + $bytes, $memoryUsage4);
+    }
+}