|
1 | 1 | using System; |
| 2 | +using System.Buffers; |
2 | 3 | using System.Linq; |
3 | 4 | using System.Threading.Tasks; |
4 | 5 | using Docnet.Core.Converters; |
@@ -339,6 +340,75 @@ public void GetImage_WhenAnnotationsRendered_ShouldHaveDifferentBytes(string fil |
339 | 340 | }); |
340 | 341 | } |
341 | 342 |
|
| 343 | + [Theory] |
| 344 | + [InlineData(Input.FromFile, "Docs/simple_3.pdf", null, 1)] |
| 345 | + [InlineData(Input.FromFile, "Docs/simple_0.pdf", null, 18)] |
| 346 | + [InlineData(Input.FromFile, "Docs/protected_0.pdf", "password", 0)] |
| 347 | + [InlineData(Input.FromBytes, "Docs/simple_3.pdf", null, 1)] |
| 348 | + [InlineData(Input.FromBytes, "Docs/simple_0.pdf", null, 18)] |
| 349 | + [InlineData(Input.FromBytes, "Docs/protected_0.pdf", "password", 0)] |
| 350 | + public void WriteImageToBufferWithResultByteAndNoRenderFlags_WhenCalled_ShouldReturnNonZeroRawByteArray(Input type, string filePath, string password, int pageIndex) |
| 351 | + { |
| 352 | + ExecuteForDocument(type, filePath, password, 1, pageIndex, pageReader => |
| 353 | + { |
| 354 | + |
| 355 | + var height = pageReader.GetPageHeight(); |
| 356 | + var stride = 4 * pageReader.GetPageWidth(); //4 is for B-G-R-A format |
| 357 | + |
| 358 | + var bytes = new byte[stride * height]; |
| 359 | + |
| 360 | + pageReader.WriteImageToBuffer(0, bytes); |
| 361 | + |
| 362 | + Assert.True(bytes.Length > 0); |
| 363 | + Assert.NotEmpty(bytes.Where(x => x != 0)); |
| 364 | + }); |
| 365 | + } |
| 366 | + |
| 367 | + [Theory] |
| 368 | + [InlineData(Input.FromFile, "Docs/simple_3.pdf", null, 1)] |
| 369 | + [InlineData(Input.FromFile, "Docs/simple_0.pdf", null, 18)] |
| 370 | + [InlineData(Input.FromFile, "Docs/protected_0.pdf", "password", 0)] |
| 371 | + [InlineData(Input.FromBytes, "Docs/simple_3.pdf", null, 1)] |
| 372 | + [InlineData(Input.FromBytes, "Docs/simple_0.pdf", null, 18)] |
| 373 | + [InlineData(Input.FromBytes, "Docs/protected_0.pdf", "password", 0)] |
| 374 | + public void WriteImageToBufferWithResultByteWithLowerLengthAndNoRenderFlags_WhenCalled_ShouldReturnException(Input type, string filePath, string password, int pageIndex) |
| 375 | + { |
| 376 | + ExecuteForDocument(type, filePath, password, 1, pageIndex, pageReader => |
| 377 | + { |
| 378 | + var height = pageReader.GetPageHeight(); |
| 379 | + var stride = 4 * pageReader.GetPageWidth(); //4 is for B-G-R-A format |
| 380 | + |
| 381 | + var bytes = new byte[stride * height - 1]; |
| 382 | + |
| 383 | + |
| 384 | + Assert.Throws<DocnetException>(() => pageReader.WriteImageToBuffer(0, bytes)); |
| 385 | + }); |
| 386 | + } |
| 387 | + |
| 388 | + [Theory] |
| 389 | + [InlineData(Input.FromFile, "Docs/simple_3.pdf", null, 1)] |
| 390 | + [InlineData(Input.FromFile, "Docs/simple_0.pdf", null, 18)] |
| 391 | + [InlineData(Input.FromFile, "Docs/protected_0.pdf", "password", 0)] |
| 392 | + [InlineData(Input.FromBytes, "Docs/simple_3.pdf", null, 1)] |
| 393 | + [InlineData(Input.FromBytes, "Docs/simple_0.pdf", null, 18)] |
| 394 | + [InlineData(Input.FromBytes, "Docs/protected_0.pdf", "password", 0)] |
| 395 | + public void WriteImageToBufferWithResultFromArrayPoolNoRenderFlags_WhenCalled_ShouldReturnNonZeroRawByteArray(Input type, string filePath, string password, int pageIndex) |
| 396 | + { |
| 397 | + ExecuteForDocument(type, filePath, password, 1, pageIndex, pageReader => |
| 398 | + { |
| 399 | + var height = pageReader.GetPageHeight(); |
| 400 | + var stride = 4 * pageReader.GetPageWidth(); //4 is for B-G-R-A format |
| 401 | + var arrayPool = ArrayPool<byte>.Shared; |
| 402 | + var bytes = arrayPool.Rent(stride * height); |
| 403 | + |
| 404 | + pageReader.WriteImageToBuffer(0, bytes); |
| 405 | + |
| 406 | + Assert.True(bytes.Length > 0); |
| 407 | + Assert.NotEmpty(bytes.Where(x => x != 0)); |
| 408 | + arrayPool.Return(bytes); |
| 409 | + }); |
| 410 | + } |
| 411 | + |
342 | 412 | private static int GetNonZeroByteCount(Input type, string filePath, LibFixture fixture) |
343 | 413 | { |
344 | 414 | using (var reader = fixture.GetDocReader(type, filePath, null, 1000, 1000)) |
|
0 commit comments