test_ioutil.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. var Cc = Components.classes;
  6. var Ci = Components.interfaces;
  7. var Cr = Components.results;
  8. const util = Cc["@mozilla.org/io-util;1"].getService(Ci.nsIIOUtil);
  9. function run_test()
  10. {
  11. try {
  12. util.inputStreamIsBuffered(null);
  13. do_throw("inputStreamIsBuffered should have thrown");
  14. } catch (e) {
  15. do_check_eq(e.result, Cr.NS_ERROR_INVALID_POINTER);
  16. }
  17. try {
  18. util.outputStreamIsBuffered(null);
  19. do_throw("outputStreamIsBuffered should have thrown");
  20. } catch (e) {
  21. do_check_eq(e.result, Cr.NS_ERROR_INVALID_POINTER);
  22. }
  23. var s = Cc["@mozilla.org/io/string-input-stream;1"]
  24. .createInstance(Ci.nsIStringInputStream);
  25. var body = "This is a test";
  26. s.setData(body, body.length);
  27. do_check_eq(util.inputStreamIsBuffered(s), true);
  28. }