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: * Creates MAR from the passed files, compares it to the reference MAR. michael@0: * michael@0: * @param refMARFileName The name of the MAR file that should match michael@0: * @param files The files that should go in the created MAR michael@0: * @param checkNoMAR If true return an error if a file already exists michael@0: */ michael@0: function run_one_test(refMARFileName, files, checkNoMAR) { michael@0: if (checkNoMAR === undefined) { michael@0: checkNoMAR = true; michael@0: } michael@0: michael@0: // Ensure the MAR we will create doesn't already exist. michael@0: let outMAR = tempDir.clone(); michael@0: outMAR.append("out.mar"); michael@0: if (checkNoMAR) { michael@0: do_check_false(outMAR.exists()); michael@0: } michael@0: michael@0: // Create the actual MAR file. michael@0: createMAR(outMAR, do_get_file("data"), files); michael@0: michael@0: // Get the reference MAR data. michael@0: let refMAR = do_get_file("data/" + refMARFileName); michael@0: let refMARData = getBinaryFileData(refMAR); michael@0: michael@0: // Verify the data of the MAR is what it should be. michael@0: let outMARData = getBinaryFileData(outMAR); michael@0: compareBinaryData(outMARData, refMARData); michael@0: } michael@0: michael@0: // Define the unit tests to run. michael@0: let tests = { michael@0: // Test creating a MAR file with a 0 byte file. michael@0: test_zero_sized: function() { michael@0: return run_one_test(refMARPrefix + "0_sized_mar.mar", ["0_sized_file"]); michael@0: }, michael@0: // Test creating a MAR file with a 1 byte file. michael@0: test_one_byte: function() { michael@0: return run_one_test(refMARPrefix + "1_byte_mar.mar", ["1_byte_file"]); michael@0: }, michael@0: // Test creating a MAR file with binary data. michael@0: test_binary_data: function() { michael@0: return run_one_test(refMARPrefix + "binary_data_mar.mar", michael@0: ["binary_data_file"]); michael@0: }, michael@0: // Test creating a MAR file with multiple files inside of it. michael@0: test_multiple_file: function() { michael@0: return run_one_test(refMARPrefix + "multiple_file_mar.mar", michael@0: ["0_sized_file", "1_byte_file", "binary_data_file"]); michael@0: }, michael@0: // Test creating a MAR file on top of a different one that already exists michael@0: // at the location the new one will be created at. michael@0: test_overwrite_already_exists: function() { michael@0: let differentFile = do_get_file("data/1_byte_mar.mar"); michael@0: let outMARDir = tempDir.clone(); michael@0: differentFile.copyTo(outMARDir, "out.mar"); michael@0: return run_one_test(refMARPrefix + "binary_data_mar.mar", michael@0: ["binary_data_file"], false); michael@0: }, michael@0: // Between each test make sure the out MAR does not exist. michael@0: cleanup_per_test: function() { michael@0: let outMAR = tempDir.clone(); michael@0: outMAR.append("out.mar"); michael@0: if (outMAR.exists()) { michael@0: outMAR.remove(false); 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: }