aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/BrowserTestExtension/tests/inputvalues.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-05-14 17:02:49 +0000
committerMaximilian Krambach <[email protected]>2018-05-14 17:02:49 +0000
commit6b4caee039af6fd97912426aff143745bf7e191a (patch)
tree45da77db56e9a6f1d460cc0d871eeecaeebe75f8 /lang/js/BrowserTestExtension/tests/inputvalues.js
parentjs: remove non-browser tests (diff)
downloadgpgme-6b4caee039af6fd97912426aff143745bf7e191a.tar.gz
gpgme-6b4caee039af6fd97912426aff143745bf7e191a.zip
js: Testing lare messages
-- * Some assumption on messages were wrong. Now the tests use more reasonable sizes. * bigString now uses the full utf8-extent, with the exception of U+0000. This code gets dropped during the encryption-decryption process.
Diffstat (limited to 'lang/js/BrowserTestExtension/tests/inputvalues.js')
-rw-r--r--lang/js/BrowserTestExtension/tests/inputvalues.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
index 38ee6aad..52e3a7b0 100644
--- a/lang/js/BrowserTestExtension/tests/inputvalues.js
+++ b/lang/js/BrowserTestExtension/tests/inputvalues.js
@@ -59,14 +59,27 @@ var inputvalues = {
}
};
-// (Pseudo-)Random String from a Uint8Array, given approx. size in Megabytes
-function bigString(megabytes){
- let maxlength = 1024 * 1024 * megabytes;
+// (Pseudo-)Random String covering all of utf8.
+function bigString(length){
+ var uint = '';
+ let arr = [];
+ for (let i= 0; i < length; i++){
+ arr.push(String.fromCharCode(
+ Math.floor(Math.random() * 10174) + 1)
+ );
+ }
+ return arr.join('');
+}
+
+function fixedLengthString(megabytes){
+ let maxlength = 1024 * 1024 * megabytes / 2;
let uint = new Uint8Array(maxlength);
- for (let i= 0; i < maxlength; i++){
- uint[i] = Math.random() * Math.floor(256);
+ for (let i = 0; i < maxlength; i++){
+ uint[i] = Math.floor(Math.random()* 256);
}
- return new TextDecoder('utf-8').decode(uint);
+ let td = new TextDecoder('ascii');
+ let result = td.decode(uint);
+ return result;
}
// (Pseudo-)Random Uint8Array, given size in Megabytes
@@ -82,19 +95,19 @@ function bigUint8(megabytes){
// (Pseudo-)Random string with very limited charset (ascii only, no control chars)
function bigBoringString(megabytes){
let maxlength = 1024 * 1024 * megabytes;
- let string = '';
+ let string = [];
let chars = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let i= 0; i < maxlength; i++){
- string = string + chars[Math.floor(Math.random() * chars.length)];
+ string.push(chars[Math.floor(Math.random() * chars.length)]);
}
- return string;
+ return string.join('');
}
// Some String with simple chars, with different characteristics, but still
// expected to occur in an averag message
function slightlyLessBoringString(megabytes, set){
let maxlength = 1024 * 1024 * megabytes;
- let string = '';
+ let string = [];
let chars = '';
if (set ===1 ) {
chars = '\n\"\r \'';
@@ -108,9 +121,9 @@ function slightlyLessBoringString(megabytes, set){
chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \'';
}
for (let i= 0; i < maxlength; i++){
- string = string + chars[Math.floor(Math.random() * chars.length)];
+ string.push(chars[Math.floor(Math.random() * chars.length)]);
}
- return string;
+ return string.join('');
}
// Data encrypted with testKey