Index: qunit/tests/io.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/qunit/tests/io.js |
@@ -0,0 +1,80 @@ |
+ /* Copyright (C) 2006-2016 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+ |
+(function() |
+{ |
+ var IO = require("io").IO; |
kzar
2016/08/22 15:38:33
You're requiring the same module twice here, I don
Oleksandr
2016/08/31 21:54:36
Done.
|
+ var io = require("io"); |
+ module("IO validation"); |
+ |
+ test("Test writing entry larger than 1Mb but smaller than 5Mb", function(assert) |
kzar
2016/08/22 15:38:33
Nit: If we're just supporting Edge anyway I guess
Oleksandr
2016/08/31 21:54:36
Done.
|
+ { |
+ var testDataOver1Mb = new Array(30000); |
+ testReadWrite(testDataOver1Mb, "testFile1Mb", assert); |
+ expect(2); |
+ }); |
+ |
+ test("Test writing entry larger than 5Mb", function(assert) |
+ { |
+ var testDataOver5Mb = new Array(300000); |
kzar
2016/08/22 15:38:33
Indentation seems wrong, should be two spaces.
Oleksandr
2016/08/31 21:54:36
Done.
|
+ testReadWrite(testDataOver5Mb, "testFile5Mb", assert); |
+ expect(2); |
+ }); |
+ |
+ function DummyParser() |
+ { |
+ readData = new Array(); |
+ }; |
+ DummyParser.prototype = |
+ { |
+ readData: new Array(), |
kzar
2016/08/22 15:38:33
Why not array literal? (Same elsewhere.)
Oleksandr
2016/08/31 21:54:36
Done.
|
+ process: function (line) { |
+ this.readData.push(line); |
+ } |
+ }; |
+ |
+ function testReadWrite(data, fileName, assert) |
kzar
2016/08/22 15:38:33
Please put the testReadWrite function above where
|
+ { |
+ // For debugging purposes clear the storage |
kzar
2016/08/22 15:38:32
Will this trash the user's saved filters? Also thi
Oleksandr
2016/08/31 21:54:36
This was just a comment I forgot to remove. The co
|
+ var fileWritten = assert.async(); |
+ for (var index = 0; index < data.length; index++) { |
+ data[index] = "test string " + index; |
+ } |
+ IO.writeToFile(IO.resolveFilePath(fileName), data, |
+ function() { }); |
+ setTimeout(function() |
+ { |
+ fileWritten(); |
+ |
+ var fileRead = assert.async(); |
+ var dummyParser = new DummyParser(); |
+ dummyParser.readData = []; |
+ IO.readFromFile(IO.resolveFilePath(fileName), |
kzar
2016/08/22 15:38:33
Nit: Mind indenting this like so?
IO.readFromFile
Oleksandr
2016/08/31 21:54:36
Done.
|
+ dummyParser, |
+ function() |
+ { |
+ equal(dummyParser.readData.length, data.length, |
+ "Check if read entry is the same size as written"); |
+ equal(dummyParser.readData[20000], data[20000], |
+ "Check if read entry element is the same as written"); |
+ fileRead(); |
+ }); |
+ |
+ }, |
+ 1000); |
+ |
+ } |
+})(); |