[tizen] Update bundle js tests after fix. 63/210063/1
authorMichal Michalski <m.michalski2@partner.samsung.com>
Mon, 15 Jul 2019 10:02:03 +0000 (12:02 +0200)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Mon, 15 Jul 2019 10:02:03 +0000 (12:02 +0200)
+ Added tests for regular arrays and Uint8Arrays.
+ Updated toJSON test after method modification.
+ Added tests for toString method.

[Verification] Tests pass for fixed bundle.

Change-Id: Idd9298b311fee56c4387c5f9c9fbd2b4984944b0
Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
src/tizen/js/ut/bundle_ut.js

index 6b03fd2..a35725f 100644 (file)
@@ -12,15 +12,29 @@ function TestJsonCtor() {
         key1: 'value',
         key2: ['value1', 'value2'],
         key3: new Uint8Array([1, 2, 3]),
-        key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+        key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
+        key5: [1,2,3],
+        key6: [[1,2,3],[4,5,6]],
+        key7: [],
+        key8: null,
+        key9: {}
     };
 
     var bundle = new tizen.Bundle(json);
-    var counter = 0;
-    forEachOwnProperty(bundle.data, function(k, v) {
-        counter++;
-    });
-    assertEqual(counter, 4, 'invalid number of entries');
+
+    assertEqual(bundle.data.key1, 'value', 'invalid value of key1');
+    assertArrayEqual(bundle.data.key2, ['value1', 'value2'], 'invalid value of key2');
+    assertArrayEqual(bundle.data.key3, new Uint8Array([1,2,3]), 'invalid value of key3');
+    assertEqual(bundle.data.key4.length, 2, 'not enough elements in key4');
+    assertArrayEqual(bundle.data.key4[0], new Uint8Array([1,2,3]), 'invalud value of key4[0]');
+    assertArrayEqual(bundle.data.key4[1], new Uint8Array([4,5,6]), 'invalud value of key4[1]');
+    assertArrayEqual(bundle.data.key5, new Uint8Array([1,2,3]), 'invalid value of key5');
+    assertEqual(bundle.data.key6.length, 2, 'invalid length of key6');
+    assertArrayEqual(bundle.data.key6[0], new Uint8Array([1,2,3]), 'invalud value of key6[0]');
+    assertArrayEqual(bundle.data.key6[1], new Uint8Array([4,5,6]), 'invalud value of key6[1]');
+    assertArrayEqual(bundle.data.key7, [], 'invalid value of key7');
+    assertEqual(bundle.data.key8, 'null', 'invalid value of key8');
+    assertEqual(bundle.data.key9, '[object Object]', 'invalid value of key9');
 }
 
 function TestSetter() {
@@ -97,35 +111,19 @@ function TestTypeOf() {
         key2: ['value1', 'value2'],
         key3: new Uint8Array([1, 2, 3]),
         key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
-        key5: []
+        key5: [],
+        key6: [1,2,3],
+        key7: [[1,2,3],[4,5,6]]
     };
 
     var bundle = new tizen.Bundle(json);
-    assertEqual(
-        bundle.typeOf('key1'),
-        tizen.BundleValueType.STRING,
-        'expected STRING type'
-    );
-    assertEqual(
-        bundle.typeOf('key2'),
-        tizen.BundleValueType.STRING_ARRAY,
-        'expected STRING_ARRAY type'
-    );
-    assertEqual(
-        bundle.typeOf('key3'),
-        tizen.BundleValueType.BYTES,
-        'expected BYTES type'
-    );
-    assertEqual(
-        bundle.typeOf('key4'),
-        tizen.BundleValueType.BYTES_ARRAY,
-        'expected BYTES_ARRAY'
-    );
-    assertEqual(
-        bundle.typeOf('key5'),
-        tizen.BundleValueType.STRING_ARRAY,
-        'empty array should be treated like STRING_ARRAY'
-    );
+    assertEqual(bundle.typeOf('key1'),tizen.BundleValueType.STRING,'expected STRING type');
+    assertEqual(bundle.typeOf('key2'),tizen.BundleValueType.STRING_ARRAY,'expected STRING_ARRAY type');
+    assertEqual(bundle.typeOf('key3'),tizen.BundleValueType.BYTES,'expected BYTES type');
+    assertEqual(bundle.typeOf('key4'), tizen.BundleValueType.BYTES_ARRAY,'expected BYTES_ARRAY');
+    assertEqual(bundle.typeOf('key5'), tizen.BundleValueType.STRING_ARRAY,'empty array should be treated like STRING_ARRAY');
+    assertEqual(bundle.typeOf('key6'), tizen.BundleValueType.BYTES, 'expected BYTES type');
+    assertEqual(bundle.typeOf('key7'), tizen.BundleValueType.BYTES_ARRAY, 'expected BYTES_ARRAY type');
 
     try {
         type = bundle.typeOf('notKey');
@@ -210,9 +208,30 @@ function TestToJson() {
         key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
     };
 
+    var result = (new tizen.Bundle(json)).toJSON();
+    assertEqual(json.key1, result.key1, 'key1 differs');
+    assertArrayEqual(json.key2, result.key2,  'key2 differs');
+    assertEqual(true, result.key3 instanceof Uint8Array, 'key3 not Uint8Array');
+    assertEqual(result.key4.length, json.key4.length, 'key4 length differs');
+    assertEqual(true, result.key4[0] instanceof Uint8Array, 'key4[0] element not Uint8Array');
+    assertEqual(true, result.key4[1] instanceof Uint8Array, 'key4[1] element not Uint8Array');
+    assertArrayEqual(json.key4[0], result.key4[0], 'key4[0] differs');
+    assertArrayEqual(json.key4[1], result.key4[1], 'key4[1] differs');
+}
+
+function TestToString() {
+    var json = {
+        key1: 'value',
+        key2: ['value1', 'value2'],
+        key3: new Uint8Array([1, 2, 3]),
+        key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
+        key5: [1,2,3],
+        key6: [[1,2,3],[4,5,6]]
+    };
     var bundle = new tizen.Bundle(json);
-    result = bundle.toJSON();
-    assertEqual(JSON.stringify(json), JSON.stringify(result), 'invalid json');
+    var expected = '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}'
+
+    assertEqual(bundle.toString(), expected, 'string forms differ');
 }
 
 var testcases = [
@@ -222,5 +241,6 @@ var testcases = [
     TestGetters,
     TestTypeOf,
     TestForEach,
-    TestToJson
+    TestToJson,
+    TestToString
 ];