/// <summary> /// Checks that the given stream contains the content /// we expect to find in it. /// </summary> static public void CheckBinaryStream(CvsStream cvsStream, bool isCompressed) { int len; String numStr; String msg; // Rewind the memory stream so we can check what was written to it cvsStream.Position = 0; if (isCompressed) { // First char should be a 'z' Assert.AreEqual(cvsStream.ReadByte(), 'z'); } // Read the first line which should be the line length numStr = cvsStream.ReadLine(); len = Int32.Parse(numStr); msg = String.Format("Expected length of {0} but got length {1}", GetBinaryLen(BINARY_BLOCKS), len); Assert.AreEqual(GetBinaryLen(BINARY_BLOCKS), len); // Check what was written to the memory stream matches the file we generated for (int n = 0; n < GetBinaryLen(BINARY_BLOCKS); n++) { byte actual = (byte)cvsStream.ReadByte(); byte wanted = GenerateBinaryByte(n); msg = String.Format("n:{0} actual:0x{1:X2} wanted:0x{2:X2}", n, actual, wanted); Assert.AreEqual(wanted, actual, msg); } }
/// <summary> /// Checks that the given stream contains the content /// we expect to find in it. /// </summary> static public void CheckTextStream(CvsStream cvsStream, bool isCompressed) { int linefeedChars = 1; // this stream is intended for cvs int len; String numStr; String msg; // Rewind the memory stream so we can check what was written to it cvsStream.Position = 0; if (isCompressed) { // First char should be a 'z' Assert.AreEqual(cvsStream.ReadByte(), 'z'); } // Read the first line which should be the line length numStr = cvsStream.ReadLine(); len = Int32.Parse(numStr); msg = String.Format("Expected length of {0} but got length {1}", GetTextLen(TEXT_BLOCKS, linefeedChars), len); Assert.AreEqual(GetTextLen(TEXT_BLOCKS, linefeedChars), len); // Check what was written to the memory stream matches the file we generated for (int n = 0; n < GetTextLen(TEXT_BLOCKS, linefeedChars); n++) { byte actual = (byte)cvsStream.ReadByte(); byte wanted = GenerateTextByte(n, linefeedChars); msg = String.Format("n:{0} actual:{1} wanted:{2}", n, actual, wanted); Assert.AreEqual(wanted, actual, msg); } }
private void HandleResponses() { SortedList modules = new SortedList(); while (true) { string responseStr = inputStream.ReadToFirstWS(); if (LOGGER.IsDebugEnabled) { LOGGER.Debug("Response : " + responseStr); } if (responseStr.Length == 0) { SendMessage("server timed out"); break; } IResponse response = ResponseFactory.CreateResponse(responseStr.Substring(0, responseStr.Length - 1)); if (LOGGER.IsDebugEnabled) { LOGGER.Debug("cvs server: " + response); } if (response == null) { if (responseStr.EndsWith(" ")) { inputStream.ReadLine(); } break; } response.Process(inputStream, this); if (response.IsTerminating) { break; } if (null != response && null != response.ResponseString) { try { this.ResponseMessageEvent(this, new MessageEventArgs(response, response.GetType().Name)); } catch (NullReferenceException) { LOGGER.Debug("No one is listening to the response message event."); } } } }