summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Upload/AssemblyStreamTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Upload/AssemblyStreamTest.php')
-rw-r--r--apps/dav/tests/unit/Upload/AssemblyStreamTest.php66
1 files changed, 63 insertions, 3 deletions
diff --git a/apps/dav/tests/unit/Upload/AssemblyStreamTest.php b/apps/dav/tests/unit/Upload/AssemblyStreamTest.php
index ea875886af7..66aea40ef22 100644
--- a/apps/dav/tests/unit/Upload/AssemblyStreamTest.php
+++ b/apps/dav/tests/unit/Upload/AssemblyStreamTest.php
@@ -35,18 +35,78 @@ class AssemblyStreamTest extends \Test\TestCase {
$this->assertEquals($expected, $content);
}
+ /**
+ * @dataProvider providesNodes()
+ */
+ public function testGetContentsFread($expected, $nodes) {
+ $stream = \OCA\DAV\Upload\AssemblyStream::wrap($nodes);
+
+ $content = '';
+ while (!feof($stream)) {
+ $content .= fread($stream, 3);
+ }
+
+ $this->assertEquals($expected, $content);
+ }
+
function providesNodes() {
+ $data8k = $this->makeData(8192);
+ $dataLess8k = $this->makeData(8191);
return[
- 'one node only' => ['1234567890', [
+ 'one node zero bytes' => [
+ '', [
+ $this->buildNode('0', '')
+ ]],
+ 'one node only' => [
+ '1234567890', [
$this->buildNode('0', '1234567890')
]],
- 'two nodes' => ['1234567890', [
+ 'one node buffer boundary' => [
+ $data8k, [
+ $this->buildNode('0', $data8k)
+ ]],
+ 'two nodes' => [
+ '1234567890', [
$this->buildNode('1', '67890'),
$this->buildNode('0', '12345')
- ]]
+ ]],
+ 'two nodes end on buffer boundary' => [
+ $data8k . $data8k, [
+ $this->buildNode('1', $data8k),
+ $this->buildNode('0', $data8k)
+ ]],
+ 'two nodes with one on buffer boundary' => [
+ $data8k . $dataLess8k, [
+ $this->buildNode('1', $dataLess8k),
+ $this->buildNode('0', $data8k)
+ ]],
+ 'two nodes on buffer boundary plus one byte' => [
+ $data8k . 'X' . $data8k, [
+ $this->buildNode('1', $data8k),
+ $this->buildNode('0', $data8k . 'X')
+ ]],
+ 'two nodes on buffer boundary plus one byte at the end' => [
+ $data8k . $data8k . 'X', [
+ $this->buildNode('1', $data8k . 'X'),
+ $this->buildNode('0', $data8k)
+ ]],
];
}
+ private function makeData($count) {
+ $data = '';
+ $base = '1234567890';
+ $j = 0;
+ for ($i = 0; $i < $count; $i++) {
+ $data .= $base[$j];
+ $j++;
+ if (!isset($base[$j])) {
+ $j = 0;
+ }
+ }
+ return $data;
+ }
+
private function buildNode($name, $data) {
$node = $this->getMockBuilder('\Sabre\DAV\File')
->setMethods(['getName', 'get', 'getSize'])