michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function run_test() { michael@0: michael@0: /** michael@0: * Extracts a MAR and makes sure each file matches the reference files. michael@0: * michael@0: * @param marFileName The name of the MAR file to extract michael@0: * @param files The files that the extracted MAR should contain michael@0: */ michael@0: function run_one_test(marFileName, files) { michael@0: // Get the MAR file that we will be extracting michael@0: let mar = do_get_file("data/" + marFileName); michael@0: michael@0: // Get the path that we will extract to michael@0: let outDir = tempDir.clone(); michael@0: outDir.append("out"); michael@0: do_check_false(outDir.exists()); michael@0: outDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0777); michael@0: michael@0: // Get the ref files and the files that will be extracted. michael@0: let outFiles = []; michael@0: let refFiles = []; michael@0: for (let i = 0; i < files.length; i++) { michael@0: let outFile = outDir.clone(); michael@0: outFile.append(files[i]); michael@0: do_check_false(outFile.exists()); michael@0: michael@0: outFiles.push(outFile); michael@0: refFiles.push(do_get_file("data/" + files[i])); michael@0: } michael@0: michael@0: // Extract the MAR contents into the ./out dir. michael@0: extractMAR(mar, outDir); michael@0: michael@0: // Compare to make sure the extracted files are the same. michael@0: for (let i = 0; i < files.length; i++) { michael@0: do_check_true(outFiles[i].exists()); michael@0: let refFileData = getBinaryFileData(refFiles[i]); michael@0: let outFileData = getBinaryFileData(outFiles[i]); michael@0: compareBinaryData(refFileData, outFileData); michael@0: } michael@0: } michael@0: michael@0: // Define the unit tests to run. michael@0: let tests = { michael@0: // Test extracting a MAR file with a 0 byte file. michael@0: test_zero_sized: function() { michael@0: return run_one_test("0_sized_mar.mar", ["0_sized_file"]); michael@0: }, michael@0: // Test extracting a MAR file with a 1 byte file. michael@0: test_one_byte: function() { michael@0: return run_one_test("1_byte_mar.mar", ["1_byte_file"]); michael@0: }, michael@0: // Test extracting a MAR file with binary data. michael@0: test_binary_data: function() { michael@0: return run_one_test("binary_data_mar.mar", ["binary_data_file"]); michael@0: }, michael@0: // Test extracting a MAR without a product information block (PIB) which michael@0: // contains binary data. michael@0: test_no_pib: function() { michael@0: return run_one_test("no_pib_mar.mar", ["binary_data_file"]); michael@0: }, michael@0: // Test extracting a MAR without a product information block (PIB) that is michael@0: // signed and which contains binary data. michael@0: test_no_pib_signed: function() { michael@0: return run_one_test("signed_no_pib_mar.mar", ["binary_data_file"]); michael@0: }, michael@0: // Test extracting a MAR with a product information block (PIB) that is michael@0: // signed and which contains binary data. michael@0: test_pib_signed: function() { michael@0: return run_one_test("signed_pib_mar.mar", ["binary_data_file"]); michael@0: }, michael@0: // Test extracting a MAR file with multiple files inside of it. michael@0: test_multiple_file: function() { michael@0: return run_one_test("multiple_file_mar.mar", michael@0: ["0_sized_file", "1_byte_file", "binary_data_file"]); michael@0: }, michael@0: // Between each test make sure the out directory and its subfiles do michael@0: // not exist. michael@0: cleanup_per_test: function() { michael@0: let outDir = tempDir.clone(); michael@0: outDir.append("out"); michael@0: if (outDir.exists()) { michael@0: outDir.remove(true); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: // Run all the tests michael@0: do_check_eq(run_tests(tests), Object.keys(tests).length - 1); michael@0: }