B2G/gecko/xpcom/tests/unit/test_storagestream.js
/**
 * Basic functionality test for storagestream: write data to it, get an input
 * stream, and read the data back to see that it matches.
 */
Basic functionality test for storagestream: write data to it, get an input
stream, and read the data back to see that it matches.
Basic functionality test for storagestream : write data to it get an input stream and read the data back to see that it matches .
function test4()
{
  var bytes = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74];
  var ss = Cc["@mozilla.org/storagestream;1"]
             .createInstance(Ci.nsIStorageStream);
  ss.init(1024, 1024, null);
  var outStream = ss.getOutputStream(0);
  var bos = Cc["@mozilla.org/binaryoutputstream;1"]
              .createInstance(Ci.nsIBinaryOutputStream);
  bos.setOutputStream(outStream);
  bos.writeByteArray(bytes, bytes.length);
  bos.close();
  var inp = ss.newInputStream(0);
  var bis = BIS(inp);
  var count = 0;
  while (count < bytes.length)
  {
    var data = bis.read8(1);
    do_check_eq(data, bytes[count++]);
  }
  var threw = false;
  try
  {
    data = bis.read8(1);
  }
  catch (e)
  {
    if (e.result != Cr.NS_ERROR_FAILURE)
      do_throw("wrong error thrown: " + e);
    threw = true;
  }
  if (!threw)
    do_throw("should have thrown but instead returned: '" + data + "'");
}
function test4 ( ) { var bytes = [ 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 ] ; var ss = Cc [ "@mozilla.org/storagestream;1" ] . createInstance ( Ci . nsIStorageStream ) ; ss . init ( 1024 , 1024 , null ) ; var outStream = ss . getOutputStream ( 0 ) ; var bos = Cc [ "@mozilla.org/binaryoutputstream;1" ] . createInstance ( Ci . nsIBinaryOutputStream ) ; bos . setOutputStream ( outStream ) ; bos . writeByteArray ( bytes , bytes . length ) ; bos . close ( ) ; var inp = ss . newInputStream ( 0 ) ; var bis = BIS ( inp ) ; var count = 0 ; while ( count < bytes . length ) { var data = bis . read8 ( 1 ) ; do_check_eq ( data , bytes [ count ++ ] ) ; } var threw = false ; try { data = bis . read8 ( 1 ) ; } catch ( e ) { if ( e . result != Cr . NS_ERROR_FAILURE ) do_throw ( "wrong error thrown: " + e ) ; threw = true ; } if ( ! threw ) do_throw ( "should have thrown but instead returned: '" + data + "'" ) ; }
Basic functionality test for storagestream: write data to it, get an input
 stream, and read the data back to see that it matches.
Basic functionality test for storagestream : write data to it get an input stream and read the data back to see that it matches .