소스 검색

Gzip tests added

n1073645 5 년 전
부모
커밋
5fd2512a9b
3개의 변경된 파일91개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 2
      src/core/operations/Gzip.mjs
  2. 1 0
      tests/operations/index.mjs
  3. 89 0
      tests/operations/tests/Gzip.mjs

+ 1 - 2
src/core/operations/Gzip.mjs

@@ -6,7 +6,6 @@
 
 
 import Operation from "../Operation.mjs";
 import Operation from "../Operation.mjs";
 import {COMPRESSION_TYPE, ZLIB_COMPRESSION_TYPE_LOOKUP} from "../lib/Zlib.mjs";
 import {COMPRESSION_TYPE, ZLIB_COMPRESSION_TYPE_LOOKUP} from "../lib/Zlib.mjs";
-// import zlibAndGzip from "zlibjs/bin/zlib_and_gzip.min.js";
 import gzip from "zlibjs/bin/gzip.min.js";
 import gzip from "zlibjs/bin/gzip.min.js";
 
 
 const Zlib = gzip.Zlib;
 const Zlib = gzip.Zlib;
@@ -79,7 +78,7 @@ class Gzip extends Operation {
         }
         }
         const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
         const gzipObj = new Zlib.Gzip(new Uint8Array(input), options);
         const compressed = new Uint8Array(gzipObj.compress());
         const compressed = new Uint8Array(gzipObj.compress());
-        if (options.flags.comment) {
+        if (options.flags.comment && !(compressed[3] & 0x10)) {
             compressed[3] |= 0x10;
             compressed[3] |= 0x10;
         }
         }
         return compressed.buffer;
         return compressed.buffer;

+ 1 - 0
tests/operations/index.mjs

@@ -41,6 +41,7 @@ import "./tests/DateTime.mjs";
 import "./tests/ExtractEmailAddresses.mjs";
 import "./tests/ExtractEmailAddresses.mjs";
 import "./tests/Fork.mjs";
 import "./tests/Fork.mjs";
 import "./tests/FromDecimal.mjs";
 import "./tests/FromDecimal.mjs";
+import "./tests/Gzip.mjs";
 import "./tests/Hash.mjs";
 import "./tests/Hash.mjs";
 import "./tests/HaversineDistance.mjs";
 import "./tests/HaversineDistance.mjs";
 import "./tests/Hexdump.mjs";
 import "./tests/Hexdump.mjs";

+ 89 - 0
tests/operations/tests/Gzip.mjs

@@ -0,0 +1,89 @@
+/**
+ * Gzip tests.
+ *
+ * @author n1073645 [n1073645@gmail.com]
+ *
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+
+import TestRegister from "../../lib/TestRegister.mjs";
+
+TestRegister.addTests([
+    {
+        name: "Gzip: No comment, no checksum and no filename",
+        input: "The quick brown fox jumped over the slow dog",
+        expectedOutput: "0dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
+        recipeConfig: [
+            {
+                op: "Gzip",
+                args: ["Dynamic Huffman Coding", "", "", false]
+            },
+            {
+                op: "Drop bytes",
+                args: [0, 10, false]
+            },
+            {
+                op: "To Hex",
+                args: ["None"]
+            }
+        ]
+    },
+    {
+        name: "Gzip: No comment, no checksum and has a filename",
+        input: "The quick brown fox jumped over the slow dog",
+        expectedOutput: "636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
+        recipeConfig: [
+            {
+                op: "Gzip",
+                args: ["Dynamic Huffman Coding", "comment", "", false]
+            },
+            {
+                op: "Drop bytes",
+                args: [0, 10, false]
+            },
+            {
+                op: "To Hex",
+                args: ["None"]
+            }
+        ]
+    },
+    {
+        name: "Gzip: Has a comment, no checksum and no filename",
+        input: "The quick brown fox jumped over the slow dog",
+        expectedOutput: "636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
+        recipeConfig: [
+            {
+                op: "Gzip",
+                args: ["Dynamic Huffman Coding", "", "comment", false]
+            },
+            {
+                op: "Drop bytes",
+                args: [0, 10, false]
+            },
+            {
+                op: "To Hex",
+                args: ["None"]
+            }
+        ]
+    },
+    {
+        name: "Gzip: Has a comment, no checksum and has a filename",
+        input: "The quick brown fox jumped over the slow dog",
+        expectedOutput: "66696c656e616d6500636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
+        recipeConfig: [
+            {
+                op: "Gzip",
+                args: ["Dynamic Huffman Coding", "filename", "comment", false]
+            },
+            {
+                op: "Drop bytes",
+                args: [0, 10, false]
+            },
+            {
+                op: "To Hex",
+                args: ["None"]
+            }
+        ]
+    },
+]);