B2G/gecko/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
/**
 * Utility function for comparing two files (or a prefix of two files).
 *
 * This function returns nothing but fails of both files (or prefixes)
 * are not identical.
 *
 * @param {string} test The name of the test (used for logging).
 * @param {string} sourcePath The name of the first file.
 * @param {string} destPath The name of the second file.
 * @param {number=} prefix If specified, only compare the |prefix|
 * first bytes of |sourcePath| and |destPath|.
 */
Utility function for comparing two files (or a prefix of two files).
This function returns nothing but fails of both files (or prefixes)
are not identical.

@param {string} test The name of the test (used for logging).
@param {string} sourcePath The name of the first file.
@param {string} destPath The name of the second file.
Utility function for comparing two files ( or a prefix of two files ) . This function returns nothing but fails of both files ( or prefixes ) are not identical . @param { string } test The name of the test ( used for logging ) . @param { string } sourcePath The name of the first file . @param { string } destPath The name of the second file .
function compare_files(test, sourcePath, destPath, prefix)
{
  ok(true, test + ": Comparing " + sourcePath + " and " + destPath);
  let source = OS.File.open(sourcePath);
  let dest = OS.File.open(destPath);
  ok(true, "Files are open");
  let sourceResult, destResult;
  try {
    if (prefix != undefined) {
      sourceResult = source.read(prefix);
      destResult = dest.read(prefix);
    } else {
      sourceResult = source.read();
      destResult = dest.read();
    }
    is(sourceResult.length, destResult.length, test + ": Both files have the same size");
    for (let i = 0; i < sourceResult.length; ++i) {
      if (sourceResult[i] != destResult[i]) {
        is(sourceResult[i] != destResult[i], test + ": Comparing char " + i);
        break;
      }
    }
  } finally {
    source.close();
    dest.close();
  }
  ok(true, test + ": Comparison complete");
}
function compare_files ( test , sourcePath , destPath , prefix ) { ok ( true , test + ": Comparing " + sourcePath + " and " + destPath ) ; let source = OS . File . open ( sourcePath ) ; let dest = OS . File . open ( destPath ) ; ok ( true , "Files are open" ) ; let sourceResult , destResult ; try { if ( prefix != undefined ) { sourceResult = source . read ( prefix ) ; destResult = dest . read ( prefix ) ; } else { sourceResult = source . read ( ) ; destResult = dest . read ( ) ; } is ( sourceResult . length , destResult . length , test + ": Both files have the same size" ) ; for ( let i = 0 ; i < sourceResult . length ; ++ i ) { if ( sourceResult [ i ] != destResult [ i ] ) { is ( sourceResult [ i ] != destResult [ i ] , test + ": Comparing char " + i ) ; break ; } } } finally { source . close ( ) ; dest . close ( ) ; } ok ( true , test + ": Comparison complete" ) ; }
Utility function for comparing two files (or a prefix of two files).
Utility function for comparing two files ( or a prefix of two files ) .