Ejemplo n.º 1
0
        public void HelperFunctions()
        {
            string s = "this is a teststring so that we can find something from the beginning";

            byte[]       sBinary = Encoding.ASCII.GetBytes(s);
            MemoryStream stream  = new MemoryStream(sBinary);

            byte[] sFirstFind = Encoding.ASCII.GetBytes("this");
            stream.Position = 0L;
            bool result = OSDParser.FindByteArray(stream, sFirstFind);

            Assert.AreEqual(true, result);
            Assert.AreEqual(4L, stream.Position);

            stream.Position = 10L;
            byte[] sSecondFind = Encoding.ASCII.GetBytes("teststring");
            result = OSDParser.FindByteArray(stream, sSecondFind);
            Assert.AreEqual(true, result);
            Assert.AreEqual(20L, stream.Position);

            stream.Position = 25L;
            byte[] sThirdNotFind = Encoding.ASCII.GetBytes("notfound");
            result = OSDParser.FindByteArray(stream, sThirdNotFind);
            Assert.AreEqual(false, result);
            Assert.AreEqual(25L, stream.Position);

            stream.Position = 60L;
            byte[] sFourthNotFound = Encoding.ASCII.GetBytes("beginningAndMore");
            result = OSDParser.FindByteArray(stream, sFourthNotFound);
            Assert.AreEqual(false, result);
            Assert.AreEqual(60L, stream.Position);

            byte[]       sFrontWhiteSpace = Encoding.ASCII.GetBytes("   \t\t\n\rtest");
            MemoryStream streamTwo        = new MemoryStream(sFrontWhiteSpace);

            OSDParser.SkipWhiteSpace(streamTwo);
            Assert.AreEqual(7L, streamTwo.Position);

            byte[]       sMiddleWhiteSpace = Encoding.ASCII.GetBytes("test \t\t\n\rtest");
            MemoryStream streamThree       = new MemoryStream(sMiddleWhiteSpace);

            streamThree.Position = 4L;
            OSDParser.SkipWhiteSpace(streamThree);
            Assert.AreEqual(9L, streamThree.Position);

            byte[]       sNoWhiteSpace = Encoding.ASCII.GetBytes("testtesttest");
            MemoryStream streamFour    = new MemoryStream(sNoWhiteSpace);

            OSDParser.SkipWhiteSpace(streamFour);
            Assert.AreEqual(0L, streamFour.Position);
        }