summaryrefslogtreecommitdiff
path: root/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader')
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/GenericFixedWidthReaderTest.php43
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/UsAsciiReaderTest.php52
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/Utf8ReaderTest.php65
3 files changed, 160 insertions, 0 deletions
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/GenericFixedWidthReaderTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/GenericFixedWidthReaderTest.php
new file mode 100644
index 0000000..3f7a46c
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/GenericFixedWidthReaderTest.php
@@ -0,0 +1,43 @@
+<?php
+
+class Swift_CharacterReader_GenericFixedWidthReaderTest extends \PHPUnit_Framework_TestCase
+{
+ public function testInitialByteSizeMatchesWidth()
+ {
+ $reader = new Swift_CharacterReader_GenericFixedWidthReader(1);
+ $this->assertSame(1, $reader->getInitialByteSize());
+
+ $reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
+ $this->assertSame(4, $reader->getInitialByteSize());
+ }
+
+ public function testValidationValueIsBasedOnOctetCount()
+ {
+ $reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
+
+ $this->assertSame(
+ 1, $reader->validateByteSequence(array(0x01, 0x02, 0x03), 3)
+ ); //3 octets
+
+ $this->assertSame(
+ 2, $reader->validateByteSequence(array(0x01, 0x0A), 2)
+ ); //2 octets
+
+ $this->assertSame(
+ 3, $reader->validateByteSequence(array(0xFE), 1)
+ ); //1 octet
+
+ $this->assertSame(
+ 0, $reader->validateByteSequence(array(0xFE, 0x03, 0x67, 0x9A), 4)
+ ); //All 4 octets
+ }
+
+ public function testValidationFailsIfTooManyOctets()
+ {
+ $reader = new Swift_CharacterReader_GenericFixedWidthReader(6);
+
+ $this->assertSame(-1, $reader->validateByteSequence(
+ array(0xFE, 0x03, 0x67, 0x9A, 0x10, 0x09, 0x85), 7
+ )); //7 octets
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/UsAsciiReaderTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/UsAsciiReaderTest.php
new file mode 100644
index 0000000..0d56736
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/UsAsciiReaderTest.php
@@ -0,0 +1,52 @@
+<?php
+
+class Swift_CharacterReader_UsAsciiReaderTest extends \PHPUnit_Framework_TestCase
+{
+ /*
+
+ for ($c = '', $size = 1; false !== $bytes = $os->read($size); ) {
+ $c .= $bytes;
+ $size = $v->validateCharacter($c);
+ if (-1 == $size) {
+ throw new Exception( ... invalid char .. );
+ } elseif (0 == $size) {
+ return $c; //next character in $os
+ }
+ }
+
+ */
+
+ private $_reader;
+
+ protected function setUp()
+ {
+ $this->_reader = new Swift_CharacterReader_UsAsciiReader();
+ }
+
+ public function testAllValidAsciiCharactersReturnZero()
+ {
+ for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
+ $this->assertSame(
+ 0, $this->_reader->validateByteSequence(array($ordinal), 1)
+ );
+ }
+ }
+
+ public function testMultipleBytesAreInvalid()
+ {
+ for ($ordinal = 0x00; $ordinal <= 0x7F; $ordinal += 2) {
+ $this->assertSame(
+ -1, $this->_reader->validateByteSequence(array($ordinal, $ordinal + 1), 2)
+ );
+ }
+ }
+
+ public function testBytesAboveAsciiRangeAreInvalid()
+ {
+ for ($ordinal = 0x80; $ordinal <= 0xFF; ++$ordinal) {
+ $this->assertSame(
+ -1, $this->_reader->validateByteSequence(array($ordinal), 1)
+ );
+ }
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/Utf8ReaderTest.php b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/Utf8ReaderTest.php
new file mode 100644
index 0000000..ec17eeb
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterReader/Utf8ReaderTest.php
@@ -0,0 +1,65 @@
+<?php
+
+class Swift_CharacterReader_Utf8ReaderTest extends \PHPUnit_Framework_TestCase
+{
+ private $_reader;
+
+ protected function setUp()
+ {
+ $this->_reader = new Swift_CharacterReader_Utf8Reader();
+ }
+
+ public function testLeading7BitOctetCausesReturnZero()
+ {
+ for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
+ $this->assertSame(
+ 0, $this->_reader->validateByteSequence(array($ordinal), 1)
+ );
+ }
+ }
+
+ public function testLeadingByteOf2OctetCharCausesReturn1()
+ {
+ for ($octet = 0xC0; $octet <= 0xDF; ++$octet) {
+ $this->assertSame(
+ 1, $this->_reader->validateByteSequence(array($octet), 1)
+ );
+ }
+ }
+
+ public function testLeadingByteOf3OctetCharCausesReturn2()
+ {
+ for ($octet = 0xE0; $octet <= 0xEF; ++$octet) {
+ $this->assertSame(
+ 2, $this->_reader->validateByteSequence(array($octet), 1)
+ );
+ }
+ }
+
+ public function testLeadingByteOf4OctetCharCausesReturn3()
+ {
+ for ($octet = 0xF0; $octet <= 0xF7; ++$octet) {
+ $this->assertSame(
+ 3, $this->_reader->validateByteSequence(array($octet), 1)
+ );
+ }
+ }
+
+ public function testLeadingByteOf5OctetCharCausesReturn4()
+ {
+ for ($octet = 0xF8; $octet <= 0xFB; ++$octet) {
+ $this->assertSame(
+ 4, $this->_reader->validateByteSequence(array($octet), 1)
+ );
+ }
+ }
+
+ public function testLeadingByteOf6OctetCharCausesReturn5()
+ {
+ for ($octet = 0xFC; $octet <= 0xFD; ++$octet) {
+ $this->assertSame(
+ 5, $this->_reader->validateByteSequence(array($octet), 1)
+ );
+ }
+ }
+}