| OLD | NEW |
| 1 #region Copyright notice and license | 1 #region Copyright notice and license |
| 2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
| 3 // Copyright 2008 Google Inc. All rights reserved. | 3 // Copyright 2008 Google Inc. All rights reserved. |
| 4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
| 5 // | 5 // |
| 6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
| 8 // met: | 8 // met: |
| 9 // | 9 // |
| 10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 Assert.AreEqual(125, cin.Position); | 380 Assert.AreEqual(125, cin.Position); |
| 381 // Field 3: fixed numeric value: 501 | 381 // Field 3: fixed numeric value: 501 |
| 382 tag = cin.ReadTag(); | 382 tag = cin.ReadTag(); |
| 383 Assert.AreEqual(3, tag >> 3); | 383 Assert.AreEqual(3, tag >> 3); |
| 384 Assert.AreEqual(126, cin.Position); | 384 Assert.AreEqual(126, cin.Position); |
| 385 Assert.AreEqual(501, cin.ReadSFixed32()); | 385 Assert.AreEqual(501, cin.ReadSFixed32()); |
| 386 Assert.AreEqual(130, cin.Position); | 386 Assert.AreEqual(130, cin.Position); |
| 387 Assert.IsTrue(cin.IsAtEnd); | 387 Assert.IsTrue(cin.IsAtEnd); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 |
| 391 [Test] |
| 392 public void Dispose_DisposesUnderlyingStream() |
| 393 { |
| 394 var memoryStream = new MemoryStream(); |
| 395 Assert.IsTrue(memoryStream.CanWrite); |
| 396 using (var cos = new CodedOutputStream(memoryStream)) |
| 397 { |
| 398 cos.WriteRawByte(0); |
| 399 Assert.AreEqual(0, memoryStream.Position); // Not flushed yet |
| 400 } |
| 401 Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data f
rom CodedOutputStream to MemoryStream |
| 402 Assert.IsFalse(memoryStream.CanWrite); // Disposed |
| 403 } |
| 404 |
| 405 [Test] |
| 406 public void Dispose_WithLeaveOpen() |
| 407 { |
| 408 var memoryStream = new MemoryStream(); |
| 409 Assert.IsTrue(memoryStream.CanWrite); |
| 410 using (var cos = new CodedOutputStream(memoryStream, true)) |
| 411 { |
| 412 cos.WriteRawByte(0); |
| 413 Assert.AreEqual(0, memoryStream.Position); // Not flushed yet |
| 414 } |
| 415 Assert.AreEqual(1, memoryStream.Position); // Flushed data from Code
dOutputStream to MemoryStream |
| 416 Assert.IsTrue(memoryStream.CanWrite); // We left the stream open |
| 417 } |
| 390 } | 418 } |
| 391 } | 419 } |
| OLD | NEW |