/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

const PR_RDONLY = 0x1;

function new_file_input_stream(file) {
  var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
    Ci.nsIFileInputStream
  );
  stream.init(file, PR_RDONLY, 0, 0);
  return stream;
}

function new_line_input_stream(filename) {
  return new_file_input_stream(do_get_file(filename)).QueryInterface(
    Ci.nsILineInputStream
  );
}

var test_array = [
  { file: "data/test_readline1.txt", lines: [] },
  { file: "data/test_readline2.txt", lines: [""] },
  { file: "data/test_readline3.txt", lines: ["", "", "", "", ""] },
  { file: "data/test_readline4.txt", lines: ["1", "23", "456", "", "78901"] },
  {
    file: "data/test_readline5.txt",
    lines: [
      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxE",
      "",
    ],
  },
  {
    file: "data/test_readline8.txt",
    lines: [
      "[encoded data, 4096 characters]",
    ],
  },
];

function err(file, lineNo, msg) {
  do_throw('"' + file + '" line ' + lineNo + ", " + msg);
}

function run_test() {
  for (var test of test_array) {
    var lineStream = new_line_input_stream(test.file);
    var lineNo = 0;
    var more = false;
    var line = {};
    more = lineStream.readLine(line);
    for (var check of test.lines) {
      ++lineNo;
      if (lineNo == test.lines.length) {
        if (more) {
          err(
            test.file,
            lineNo,
            "There should be no more data after the last line"
          );
        }
      } else if (!more) {
        err(test.file, lineNo, "There should be more data after this line");
      }
      if (line.value != check) {
        err(
          test.file,
          lineNo,
          "Wrong value, got '" + line.value + "' expected '" + check + "'"
        );
      }
      dump(
        'ok "' +
          test.file +
          '" line ' +
          lineNo +
          " (length " +
          line.value.length +
          "): '" +
          line.value +
          "'\n"
      );
      more = lineStream.readLine(line);
    }
    if (more) {
      err(test.file, lineNo, "'more' should be false after reading all lines");
    }
    dump('ok "' + test.file + '" succeeded\n');
    lineStream.close();
  }
}
