Ejemplo n.º 1
0
        public void TestReadNCR(string sDebugStream, long ibStart, long ibLim, long lcbSwapBuffer,
                                string[] rgsNCRExpected, string[] rgsNonNCRExpected, long ibSeekExpected, string sExpectedException)
        {
            DebugStream      stm  = DebugStream.StmCreateFromString(sDebugStream + "aaaa\n");
            BufferedStreamEx stmx = new BufferedStreamEx(stm, ibStart, ibLim, lcbSwapBuffer);

            TestDelegate t = () =>
            {
                // to do this test, we will construct the string before and after NCRs. a null
                // in the expected string is where an NCR is expected.
                StringBuilder sb = new StringBuilder();
                byte          b;
                int           iNonNCR           = 0;
                int           iNCR              = 0;
                bool          fSkipNextNCRStart = false; // this means we have tried this &, and its not an NCR

                while (stmx.ReadByte(out b) != SwapBuffer.ReadByteBufferState.SourceDataExhausted)
                {
                    if (fSkipNextNCRStart || b != '&')
                    {
                        sb.Append((char)b);
                        fSkipNextNCRStart = false;
                        continue;
                    }

                    // read the possible NCR
                    string sAcceptedNCR;

                    if (!stmx.ReadNCR(out sAcceptedNCR))
                    {
                        fSkipNextNCRStart = true;
                        continue;
                    }

                    // we have an NCR!
                    // confirm we match the before NCR, the null placeholder for the NCR, and the NCR

                    Assert.AreEqual(rgsNonNCRExpected[iNonNCR++], sb.ToString());
                    Assert.AreEqual(rgsNonNCRExpected[iNonNCR++], null);   // there should be a null
                    Assert.AreEqual(rgsNCRExpected[iNCR++], sAcceptedNCR);
                    sb.Clear();
                    // and continue
                }

                // at this point there can't be any NCR's
                Assert.AreEqual(rgsNCRExpected.Length, iNCR);
                Assert.AreEqual(rgsNonNCRExpected[iNonNCR], sb.ToString());

                Assert.AreEqual(ibSeekExpected, stmx.Position());
            };

            if (sExpectedException != null)
            {
                RunTestExpectingException(t, sExpectedException);
            }
            else
            {
                t();
            }
        }
Ejemplo n.º 2
0
        /*----------------------------------------------------------------------------
        *       %%Function: TestReadLineWithStreamEndingAtFileLimit
        *       %%Qualified: TCore.StreamEx.BufferedStreamEx.TestReadLineWithStreamEndingAtFileLimit
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public static void TestReadLineWithStreamEndingAtFileLimit(string sDebugStream, long ibStart, long ibLim, long lcbSwapBuffer, string[] rgsExpected, long ibSeekExpected, string sExpectedException)
        {
            DebugStream      stm  = DebugStream.StmCreateFromString(sDebugStream);
            BufferedStreamEx stmx = new BufferedStreamEx(stm, ibStart, ibLim, lcbSwapBuffer);
            TestDelegate     t    = () =>
            {
                foreach (string s in rgsExpected)
                {
                    Assert.AreEqual(s, stmx.ReadLine());
                }

                Assert.AreEqual(ibSeekExpected, stmx.Position());
            };

            if (sExpectedException != null)
            {
                RunTestExpectingException(t, sExpectedException);
            }
            else
            {
                t();
            }
        }