Index: qunit/tests/io.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/qunit/tests/io.js |
@@ -0,0 +1,88 @@ |
+ /* 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; |
+ module("IO validation", |
kzar
2016/08/30 14:13:03
Nit: We would normally have the opening bracket on
Oleksandr
2016/08/31 21:54:38
Done.
|
+ { |
+ afterEach: function() |
+ { |
+ if (typeof browser != "undefined") |
kzar
2016/08/30 14:13:03
Nit: Mind checking for `== "undefined"` and switch
Oleksandr
2016/08/31 21:54:38
Done.
|
+ window.localStorage.removeItem("testfile"); |
+ else |
+ ext.storage.remove("testfile"); |
+ } |
+ }); |
+ |
+ function DummyParser() |
+ { |
+ readData = []; |
+ }; |
+ |
+ DummyParser.prototype = |
+ { |
+ readData: [], |
+ process: function (line) |
+ { |
+ this.readData.push(line); |
+ } |
+ }; |
+ |
+ function testReadWrite(data, fileName, assert) |
+ { |
+ var fileWritten = assert.async(); |
+ for (var index = 0; index < data.length; index++) |
+ { |
kzar
2016/08/30 14:13:03
Nit: No braces required here.
Oleksandr
2016/08/31 21:54:37
Done.
|
+ data[index] = "test string " + index; |
+ } |
+ IO.writeToFile(IO.resolveFilePath(fileName), data, () => {}); |
+ setTimeout(function() |
+ { |
+ fileWritten(); |
+ |
+ var fileRead = assert.async(); |
+ var dummyParser = new DummyParser(); |
+ dummyParser.readData = []; |
+ IO.readFromFile( |
+ IO.resolveFilePath(fileName), |
+ dummyParser, |
+ function() |
+ { |
+ equal(dummyParser.readData.length, data.length, |
kzar
2016/08/30 14:13:03
Nit: This is indented incorrectly. Please could yo
Oleksandr
2016/08/31 21:54:37
Done.
|
+ "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); |
+ } |
+ |
+ test("Test writing entry larger than 1Mb but smaller than 5Mb", (assert) => |
kzar
2016/08/30 14:13:03
Nit: The functions with one arguments using this s
Oleksandr
2016/08/31 21:54:37
Done.
|
+ { |
+ var testDataOver1Mb = new Array(30000); |
+ testReadWrite(testDataOver1Mb, "testFile", assert); |
+ expect(2); |
+ }); |
+ |
+ test("Test writing entry larger than 5Mb", (assert) => |
+ { |
+ var testDataOver5Mb = new Array(300000); |
+ testReadWrite(testDataOver5Mb, "testFile", assert); |
+ expect(2); |
+ }); |
+})(); |