From 2f6c4d5a8dab4c9aeb635259ee7cb14dbef30999 Mon Sep 17 00:00:00 2001 From: Yegor Pelykh Date: Tue, 26 Mar 2024 17:50:14 +0200 Subject: [PATCH] test: Added tests for using PNM decoder --- test/_input/pnm/test.pbm | 10 +++++++++ test/_input/pnm/test.pgm | 10 +++++++++ test/_input/pnm/test.ppm | 8 +++++++ test/_input/pnm/z00n2c08.pnm | Bin 0 -> 3085 bytes test/_utils/test-section.ts | 1 + test/_utils/test-utils.ts | 2 ++ test/format/format.pnm.test.ts | 38 +++++++++++++++++++++++++++++++++ 7 files changed, 69 insertions(+) create mode 100644 test/_input/pnm/test.pbm create mode 100644 test/_input/pnm/test.pgm create mode 100644 test/_input/pnm/test.ppm create mode 100644 test/_input/pnm/z00n2c08.pnm create mode 100644 test/format/format.pnm.test.ts diff --git a/test/_input/pnm/test.pbm b/test/_input/pnm/test.pbm new file mode 100644 index 0000000..73c7a5b --- /dev/null +++ b/test/_input/pnm/test.pbm @@ -0,0 +1,10 @@ +P1 +24 # PBM example +7 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 +0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 +0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 +0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 +0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/test.pgm b/test/_input/pnm/test.pgm new file mode 100644 index 0000000..ba47572 --- /dev/null +++ b/test/_input/pnm/test.pgm @@ -0,0 +1,10 @@ +P2 +24 7 +15 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 +0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 +0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/test.ppm b/test/_input/pnm/test.ppm new file mode 100644 index 0000000..ecd1b91 --- /dev/null +++ b/test/_input/pnm/test.ppm @@ -0,0 +1,8 @@ +P3 +# example from the man page +4 4 +15 + 0 0 0 0 0 0 0 0 0 15 0 15 + 0 0 0 0 15 7 0 0 0 0 0 0 + 0 0 0 0 0 0 0 15 7 0 0 0 +15 0 15 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/_input/pnm/z00n2c08.pnm b/test/_input/pnm/z00n2c08.pnm new file mode 100644 index 0000000000000000000000000000000000000000..55da3c5cc11c622acf51c3f14a151aaadfa55e23 GIT binary patch literal 3085 zcmWNTA+V*o7DSgkH42OSNF?*>eSt)xej%|)Bod26BC$v$GBP$YGBP$YGQY>%se8|X zWbf|P{lEYI`RDI{{`vdo@4x^4DTQ1}g;)p$UvLFmFom!17M{XgxC&?CDC~u;uojlW zT$l=DVJP&4uFw{mLS3i|zXFAl$(fXinUL`rm$4a>`7&?j$=sPMb7qdrp4l>MX35N% zDKlnk7)VG}0tCEmo7xD!|6OdN?lu_e~Tl9&@y zVoVH)KG7xGM3bl!RpOU^q^d-6Bt>E*M0~_WY{W#q$QyYgcjStkkt4E4w#XV;B6DPl zjFBPIN4iKGX(Dx`ioaj1h;<3%Knlb_2>5^t*nkOqfj963?!Xl|14m#FY=Jef1m?gL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_NM7-20E#p_frQ|H%C=hg;cds@~ literal 0 HcmV?d00001 diff --git a/test/_utils/test-section.ts b/test/_utils/test-section.ts index ff5960a..2b21cfc 100644 --- a/test/_utils/test-section.ts +++ b/test/_utils/test-section.ts @@ -12,6 +12,7 @@ export enum TestSection { ico, jpeg, png, + pnm, tiff, tga, transform, diff --git a/test/_utils/test-utils.ts b/test/_utils/test-utils.ts index ed708f1..dc3260d 100644 --- a/test/_utils/test-utils.ts +++ b/test/_utils/test-utils.ts @@ -47,6 +47,8 @@ export abstract class TestUtils { return 'jpg'; case TestSection.png: return 'png'; + case TestSection.pnm: + return 'pnm'; case TestSection.tiff: return 'tiff'; case TestSection.tga: diff --git a/test/format/format.pnm.test.ts b/test/format/format.pnm.test.ts new file mode 100644 index 0000000..f6bdc45 --- /dev/null +++ b/test/format/format.pnm.test.ts @@ -0,0 +1,38 @@ +/** @format */ + +import { encodePng, PnmDecoder } from '../../src'; +import { TestFolder } from '../_utils/test-folder'; +import { TestSection } from '../_utils/test-section'; +import { TestUtils } from '../_utils/test-utils'; + +describe('Format: PNM', () => { + const resFiles = TestUtils.listFiles(TestFolder.input, TestSection.pnm); + + for (const file of resFiles) { + test(`pnm ${file.fileName}`, () => { + const input = TestUtils.readFromFilePath(file.path); + const decoder = new PnmDecoder(); + + const isValidFile = decoder.isValidFile(input); + expect(isValidFile).toBeTruthy(); + + const image = decoder.decode({ + bytes: input, + }); + expect(image).toBeDefined(); + if (image === undefined) { + return; + } + + const output = encodePng({ + image: image, + }); + TestUtils.writeToFile( + TestFolder.output, + TestSection.pnm, + `${file.fileName}.png`, + output + ); + }); + } +});