示例#1
0
        private void compareReaderImplementations(string fileName, Encoding enc)
        {
            string          DataPath = "..\\..\\data\\";
            EncodingOptions encOpts  = new EncodingOptions();

            encOpts.Encoding = enc;

            Stream s1 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read);
            PositionAwareStreamReader r1 = new PositionAwareStreamReader(s1, encOpts, false);

            Stream s2 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read);
            PositionAwareStreamReader r2 = new PositionAwareStreamReader(s2, encOpts, true);

            for (int lineNum = 0;; lineNum++)
            {
                string line1 = r1.ReadLine();
                string line2 = r2.ReadLine();
                if (line1 == null && line2 == null)
                {
                    break;
                }
                Assert.AreEqual(line1, line2, "File " + fileName);
                Assert.AreEqual(r1.Position, r2.Position, "Zeile " + lineNum + ", File: " + fileName);
            }
        }
        void Read_All_Position(Encoding encoding)
        {
            MemoryStream stream = new MemoryStream(encoding.GetBytes(TestString));
            PositionAwareStreamReader reader = new PositionAwareStreamReader(stream, encoding);
            char[] buffer = new char[TestString.Length];

            Assert.AreEqual(TestString.Length, reader.Read(buffer, 0, buffer.Length));
            Assert.AreEqual(TestString, new string(buffer));
            Assert.AreEqual(TestString.Length, reader.Position);
        }
        void Read_Fragment_Position(Encoding encoding)
        {
            MemoryStream stream = new MemoryStream(encoding.GetBytes(TestString));
            PositionAwareStreamReader reader = new PositionAwareStreamReader(stream, encoding);
            int charsToRead = TestString.Length / 2;
            char[] buffer = new char[charsToRead];

            Assert.AreEqual(charsToRead, reader.Read(buffer, 0, charsToRead));
            Assert.AreEqual(TestString.Substring(0, charsToRead), new string(buffer));
            Assert.AreEqual(charsToRead, reader.Position);
        }
示例#4
0
        void Read_All_Position(Encoding encoding)
        {
            MemoryStream stream = new MemoryStream(encoding.GetBytes(TestString));
            PositionAwareStreamReader reader = new PositionAwareStreamReader(stream, encoding);

            char[] buffer = new char[TestString.Length];

            Assert.AreEqual(TestString.Length, reader.Read(buffer, 0, buffer.Length));
            Assert.AreEqual(TestString, new string(buffer));
            Assert.AreEqual(TestString.Length, reader.Position);
        }
示例#5
0
        void Read_Fragment_Position(Encoding encoding)
        {
            MemoryStream stream = new MemoryStream(encoding.GetBytes(TestString));
            PositionAwareStreamReader reader = new PositionAwareStreamReader(stream, encoding);
            int charsToRead = TestString.Length / 2;

            char[] buffer = new char[charsToRead];

            Assert.AreEqual(charsToRead, reader.Read(buffer, 0, charsToRead));
            Assert.AreEqual(TestString.Substring(0, charsToRead), new string(buffer));
            Assert.AreEqual(charsToRead, reader.Position);
        }
示例#6
0
        private void compareReaderImplementations(string fileName, Encoding enc, int maxPosition)
        {
            string          DataPath = "..\\..\\data\\";
            EncodingOptions encOpts  = new EncodingOptions();

            encOpts.Encoding = enc;

            using (Stream s1 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read))
                using (Stream s2 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read))
                {
                    PositionAwareStreamReader r1 = new PositionAwareStreamReader(s1, encOpts, false);

                    PositionAwareStreamReader r2 = new PositionAwareStreamReader(s2, encOpts, true);

                    for (int lineNum = 0;; lineNum++)
                    {
                        string line1 = r1.ReadLine();
                        string line2 = r2.ReadLine();
                        if (line1 == null && line2 == null)
                        {
                            break;
                        }

                        Assert.AreEqual(line1, line2, "File " + fileName);
                        if (r1.Position != maxPosition)
                        {
                            Assert.AreEqual(r1.Position, r2.Position, "Line " + lineNum + ", File: " + fileName);
                        }
                        else
                        {
                            //Its desired that the position of the new implementation is 2 bytes ahead to fix the problem of empty lines every time a new line is appended.
                            Assert.AreEqual(r1.Position, r2.Position - 2, "Line " + lineNum + ", File: " + fileName);
                        }
                    }
                }
        }