2016-02-18 19:59:34 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-08-14 15:18:49 +00:00
|
|
|
|
2015-08-13 16:12:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-08 23:19:19 +00:00
|
|
|
var Realm = require('realm');
|
2015-10-14 22:25:58 +00:00
|
|
|
var BaseTest = require('./base-test');
|
2015-10-06 07:57:35 +00:00
|
|
|
var TestCase = require('./asserts');
|
|
|
|
var schemas = require('./schemas');
|
|
|
|
|
2015-11-16 11:26:33 +00:00
|
|
|
var RANDOM_DATA = new Uint8Array([
|
2015-11-16 21:48:37 +00:00
|
|
|
0xd8, 0x21, 0xd6, 0xe8, 0x00, 0x57, 0xbc, 0xb2, 0x6a, 0x15, 0x77, 0x30, 0xac, 0x77, 0x96, 0xd9,
|
|
|
|
0x67, 0x1e, 0x40, 0xa7, 0x6d, 0x52, 0x83, 0xda, 0x07, 0x29, 0x9c, 0x70, 0x38, 0x48, 0x4e, 0xff,
|
2015-11-16 11:26:33 +00:00
|
|
|
]);
|
|
|
|
|
2015-10-14 22:25:58 +00:00
|
|
|
module.exports = BaseTest.extend({
|
2015-08-13 16:12:48 +00:00
|
|
|
testBasicTypesPropertyGetters: function() {
|
2015-10-14 09:12:50 +00:00
|
|
|
var realm = new Realm({schema: [schemas.BasicTypes]});
|
2015-11-16 11:26:33 +00:00
|
|
|
var object;
|
|
|
|
|
2015-11-02 20:02:53 +00:00
|
|
|
var basicTypesValues = {
|
|
|
|
boolCol: true,
|
|
|
|
intCol: 1,
|
|
|
|
floatCol: 1.1,
|
|
|
|
doubleCol: 1.11,
|
|
|
|
stringCol: 'string',
|
|
|
|
dateCol: new Date(1),
|
|
|
|
dataCol: RANDOM_DATA,
|
|
|
|
};
|
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
realm.write(function() {
|
|
|
|
object = realm.create('BasicTypesObject', basicTypesValues);
|
|
|
|
});
|
2015-08-13 16:12:48 +00:00
|
|
|
|
2015-11-02 20:02:53 +00:00
|
|
|
for (var name in schemas.BasicTypes.properties) {
|
|
|
|
var prop = schemas.BasicTypes.properties[name];
|
|
|
|
var type = typeof prop == 'object' ? prop.type : prop;
|
|
|
|
|
|
|
|
if (type == Realm.Types.FLOAT || type == Realm.Types.DOUBLE) {
|
|
|
|
TestCase.assertEqualWithTolerance(object[name], basicTypesValues[name], 0.000001);
|
2015-10-12 08:59:34 +00:00
|
|
|
}
|
2015-11-02 20:02:53 +00:00
|
|
|
else if (type == Realm.Types.DATA) {
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object[name]), RANDOM_DATA);
|
2015-11-16 11:26:33 +00:00
|
|
|
}
|
2015-11-02 20:02:53 +00:00
|
|
|
else if (type == Realm.Types.DATE) {
|
|
|
|
TestCase.assertEqual(object[name].getTime(), basicTypesValues[name].getTime());
|
2015-10-12 08:59:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-11-02 20:02:53 +00:00
|
|
|
TestCase.assertEqual(object[name], basicTypesValues[name]);
|
2015-10-12 08:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-27 10:13:21 +00:00
|
|
|
|
|
|
|
TestCase.assertEqual(object.nonexistent, undefined);
|
2015-08-13 16:12:48 +00:00
|
|
|
},
|
2015-10-22 03:36:21 +00:00
|
|
|
testNullableBasicTypesPropertyGetters: function() {
|
|
|
|
var realm = new Realm({schema: [schemas.NullableBasicTypes]});
|
2015-11-02 20:02:53 +00:00
|
|
|
var object, nullObject;
|
|
|
|
|
|
|
|
var basicTypesValues = {
|
|
|
|
boolCol: true,
|
|
|
|
intCol: 1,
|
|
|
|
floatCol: 1.1,
|
|
|
|
doubleCol: 1.11,
|
|
|
|
stringCol: 'string',
|
|
|
|
dateCol: new Date(1),
|
|
|
|
dataCol: RANDOM_DATA,
|
|
|
|
};
|
|
|
|
|
2015-10-22 03:36:21 +00:00
|
|
|
realm.write(function() {
|
|
|
|
object = realm.create('NullableBasicTypesObject', basicTypesValues);
|
2015-11-02 20:02:53 +00:00
|
|
|
|
|
|
|
nullObject = realm.create('NullableBasicTypesObject', {
|
|
|
|
boolCol: null,
|
|
|
|
intCol: null,
|
|
|
|
floatCol: null,
|
|
|
|
doubleCol: null,
|
|
|
|
stringCol: null,
|
|
|
|
dateCol: null,
|
|
|
|
dataCol: null,
|
|
|
|
});
|
2015-10-22 03:36:21 +00:00
|
|
|
});
|
|
|
|
|
2015-11-02 20:02:53 +00:00
|
|
|
for (var name in schemas.BasicTypes.properties) {
|
|
|
|
var prop = schemas.BasicTypes.properties[name];
|
|
|
|
var type = typeof prop == 'object' ? prop.type : prop;
|
|
|
|
|
|
|
|
TestCase.assertEqual(nullObject[name], null);
|
2015-10-27 17:04:56 +00:00
|
|
|
|
2015-11-02 20:02:53 +00:00
|
|
|
if (type == Realm.Types.FLOAT || type == Realm.Types.DOUBLE) {
|
|
|
|
TestCase.assertEqualWithTolerance(object[name], basicTypesValues[name], 0.000001);
|
2015-10-27 17:04:56 +00:00
|
|
|
}
|
2015-11-02 20:02:53 +00:00
|
|
|
else if (type == Realm.Types.DATA) {
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object[name]), RANDOM_DATA);
|
2015-11-16 11:26:33 +00:00
|
|
|
}
|
2015-11-02 20:02:53 +00:00
|
|
|
else if (type == Realm.Types.DATE) {
|
|
|
|
TestCase.assertEqual(object[name].getTime(), basicTypesValues[name].getTime());
|
2015-10-27 17:04:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-11-02 20:02:53 +00:00
|
|
|
TestCase.assertEqual(object[name], basicTypesValues[name]);
|
2015-10-27 17:04:56 +00:00
|
|
|
}
|
2015-10-22 03:36:21 +00:00
|
|
|
}
|
2015-10-27 17:04:56 +00:00
|
|
|
|
2015-10-22 03:36:21 +00:00
|
|
|
},
|
2015-08-13 16:12:48 +00:00
|
|
|
testBasicTypesPropertySetters: function() {
|
2015-10-14 09:12:50 +00:00
|
|
|
var realm = new Realm({schema: [schemas.BasicTypes]});
|
2015-11-02 20:02:53 +00:00
|
|
|
var obj;
|
|
|
|
|
|
|
|
var basicTypesValues = {
|
|
|
|
boolCol: true,
|
|
|
|
intCol: 1,
|
|
|
|
floatCol: 1.1,
|
|
|
|
doubleCol: 1.11,
|
|
|
|
stringCol: 'string',
|
|
|
|
dateCol: new Date(1),
|
|
|
|
dataCol: new ArrayBuffer(),
|
|
|
|
};
|
2015-10-12 09:02:23 +00:00
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
realm.write(function() {
|
|
|
|
obj = realm.create('BasicTypesObject', basicTypesValues);
|
|
|
|
obj.boolCol = false;
|
|
|
|
obj.intCol = 2;
|
|
|
|
obj.floatCol = 2.2;
|
|
|
|
obj.doubleCol = 2.22;
|
|
|
|
obj.stringCol = 'STRING';
|
|
|
|
obj.dateCol = new Date(2);
|
2015-11-16 11:26:33 +00:00
|
|
|
obj.dataCol = RANDOM_DATA;
|
2015-10-12 08:59:34 +00:00
|
|
|
});
|
2015-10-12 09:02:23 +00:00
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
TestCase.assertEqual(obj.boolCol, false, 'wrong bool value');
|
|
|
|
TestCase.assertEqual(obj.intCol, 2, 'wrong int value');
|
|
|
|
TestCase.assertEqualWithTolerance(obj.floatCol, 2.2, 0.000001, 'wrong float value');
|
2015-11-02 20:02:53 +00:00
|
|
|
TestCase.assertEqualWithTolerance(obj.doubleCol, 2.22, 0.000001, 'wrong double value');
|
2015-10-12 08:59:34 +00:00
|
|
|
TestCase.assertEqual(obj.stringCol, 'STRING', 'wrong string value');
|
|
|
|
TestCase.assertEqual(obj.dateCol.getTime(), 2, 'wrong date value');
|
2015-11-16 11:26:33 +00:00
|
|
|
TestCase.assertArraysEqual(new Uint8Array(obj.dataCol), RANDOM_DATA, 'wrong data value');
|
2015-10-12 19:59:40 +00:00
|
|
|
|
2015-10-12 23:50:45 +00:00
|
|
|
realm.write(function() {
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = 'cat';
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.intCol = 'dog';
|
|
|
|
});
|
2015-10-22 03:20:51 +00:00
|
|
|
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.intCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.intCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.floatCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.floatCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.doubleCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.doubleCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.stringCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.stringCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.dateCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.dateCol = undefined;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.dataCol = null;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.dataCol = undefined;
|
|
|
|
});
|
2015-10-12 23:50:45 +00:00
|
|
|
});
|
|
|
|
|
2015-10-12 19:59:40 +00:00
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = true;
|
|
|
|
}, 'can only set property values in a write transaction');
|
|
|
|
|
|
|
|
TestCase.assertEqual(obj.boolCol, false, 'bool value changed outside transaction');
|
2015-08-13 16:12:48 +00:00
|
|
|
},
|
2015-10-27 17:28:34 +00:00
|
|
|
testNullableBasicTypesPropertySetters: function() {
|
|
|
|
var realm = new Realm({schema: [schemas.NullableBasicTypes]});
|
2015-11-02 18:08:23 +00:00
|
|
|
var obj, obj1;
|
2015-10-27 17:28:34 +00:00
|
|
|
|
2015-11-02 20:02:53 +00:00
|
|
|
var basicTypesValues = {
|
|
|
|
boolCol: true,
|
|
|
|
intCol: 1,
|
|
|
|
floatCol: 1.1,
|
|
|
|
doubleCol: 1.11,
|
|
|
|
stringCol: 'string',
|
|
|
|
dateCol: new Date(1),
|
|
|
|
dataCol: RANDOM_DATA,
|
|
|
|
};
|
|
|
|
|
2015-10-27 17:28:34 +00:00
|
|
|
realm.write(function() {
|
|
|
|
obj = realm.create('NullableBasicTypesObject', basicTypesValues);
|
2015-11-02 18:08:23 +00:00
|
|
|
obj1 = realm.create('NullableBasicTypesObject', basicTypesValues);
|
2015-11-02 20:02:53 +00:00
|
|
|
|
2015-10-30 19:08:31 +00:00
|
|
|
for (var name in schemas.NullableBasicTypes.properties) {
|
|
|
|
obj[name] = null;
|
|
|
|
obj1[name] = undefined;
|
2015-10-27 17:28:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-30 19:08:31 +00:00
|
|
|
for (var name in schemas.NullableBasicTypes.properties) {
|
|
|
|
TestCase.assertEqual(obj[name], null);
|
|
|
|
TestCase.assertEqual(obj1[name], null);
|
2015-10-27 17:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
realm.write(function() {
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = 'cat';
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.intCol = 'dog';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.boolCol = null;
|
|
|
|
}, 'can only set property values in a write transaction');
|
|
|
|
},
|
2015-08-13 16:12:48 +00:00
|
|
|
testLinkTypesPropertyGetters: function() {
|
2015-10-14 09:12:50 +00:00
|
|
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
2015-10-12 08:59:34 +00:00
|
|
|
var obj = null;
|
2015-11-02 20:02:53 +00:00
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
realm.write(function() {
|
2015-11-02 20:02:53 +00:00
|
|
|
obj = realm.create('LinkTypesObject', {
|
|
|
|
objectCol: {doubleCol: 1},
|
|
|
|
objectCol1: null,
|
|
|
|
arrayCol: [{doubleCol: 3}],
|
|
|
|
});
|
2015-10-12 08:59:34 +00:00
|
|
|
});
|
2015-08-13 16:12:48 +00:00
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
var objVal = obj.objectCol;
|
|
|
|
TestCase.assertEqual(typeof objVal, 'object');
|
|
|
|
TestCase.assertNotEqual(objVal, null);
|
|
|
|
TestCase.assertEqual(objVal.doubleCol, 1);
|
2015-08-13 16:12:48 +00:00
|
|
|
|
|
|
|
TestCase.assertEqual(obj.objectCol1, null);
|
|
|
|
|
2015-10-12 08:59:34 +00:00
|
|
|
var arrayVal = obj.arrayCol;
|
|
|
|
TestCase.assertEqual(typeof arrayVal, 'object');
|
|
|
|
TestCase.assertNotEqual(arrayVal, null);
|
|
|
|
TestCase.assertEqual(arrayVal.length, 1);
|
|
|
|
TestCase.assertEqual(arrayVal[0].doubleCol, 3);
|
2015-08-13 16:12:48 +00:00
|
|
|
},
|
|
|
|
testLinkTypesPropertySetters: function() {
|
2015-10-06 07:57:35 +00:00
|
|
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
2015-10-28 17:21:32 +00:00
|
|
|
var objects = realm.objects('TestObject');
|
2015-11-02 20:02:53 +00:00
|
|
|
var obj;
|
2015-10-28 17:21:32 +00:00
|
|
|
|
2015-08-13 16:12:48 +00:00
|
|
|
realm.write(function() {
|
2015-11-02 20:02:53 +00:00
|
|
|
obj = realm.create('LinkTypesObject', {
|
|
|
|
objectCol: {doubleCol: 1},
|
|
|
|
objectCol1: null,
|
|
|
|
arrayCol: [{doubleCol: 3}],
|
|
|
|
});
|
2015-08-13 16:12:48 +00:00
|
|
|
});
|
2015-11-02 20:02:53 +00:00
|
|
|
|
2015-10-28 17:21:32 +00:00
|
|
|
TestCase.assertEqual(objects.length, 2);
|
2015-08-13 16:12:48 +00:00
|
|
|
|
2015-10-12 09:02:23 +00:00
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
obj.objectCol1 = obj.objectCol;
|
|
|
|
}, 'can only set property values in a write transaction');
|
|
|
|
|
2015-08-13 16:12:48 +00:00
|
|
|
// set/reuse object property
|
|
|
|
realm.write(function() {
|
|
|
|
obj.objectCol1 = obj.objectCol;
|
|
|
|
});
|
|
|
|
TestCase.assertEqual(obj.objectCol1.doubleCol, 1);
|
|
|
|
//TestCase.assertEqual(obj.objectCol, obj.objectCol1);
|
2015-10-28 17:21:32 +00:00
|
|
|
TestCase.assertEqual(objects.length, 2);
|
2015-08-13 16:12:48 +00:00
|
|
|
|
|
|
|
realm.write(function() {
|
2015-09-04 22:43:26 +00:00
|
|
|
obj.objectCol = null;
|
2015-08-13 16:12:48 +00:00
|
|
|
obj.objectCol1 = null;
|
|
|
|
});
|
|
|
|
TestCase.assertEqual(obj.objectCol, null);
|
|
|
|
TestCase.assertEqual(obj.objectCol1, null);
|
|
|
|
|
|
|
|
// set object as JSON
|
|
|
|
realm.write(function() {
|
2015-11-02 20:02:53 +00:00
|
|
|
obj.objectCol = {doubleCol: 1};
|
2015-08-13 16:12:48 +00:00
|
|
|
});
|
2015-08-14 17:47:56 +00:00
|
|
|
TestCase.assertEqual(obj.objectCol.doubleCol, 1);
|
2015-10-28 17:21:32 +00:00
|
|
|
TestCase.assertEqual(objects.length, 3);
|
2015-08-14 17:47:56 +00:00
|
|
|
|
|
|
|
// set array property
|
|
|
|
realm.write(function() {
|
2015-11-02 20:02:53 +00:00
|
|
|
obj.arrayCol = [
|
|
|
|
obj.arrayCol[0],
|
|
|
|
obj.objectCol,
|
|
|
|
realm.create('TestObject', {doubleCol: 2}),
|
|
|
|
];
|
2015-08-14 17:47:56 +00:00
|
|
|
});
|
2015-11-02 20:02:53 +00:00
|
|
|
|
2015-10-28 17:21:32 +00:00
|
|
|
TestCase.assertEqual(objects.length, 4);
|
2015-08-14 17:47:56 +00:00
|
|
|
TestCase.assertEqual(obj.arrayCol.length, 3);
|
|
|
|
TestCase.assertEqual(obj.arrayCol[0].doubleCol, 3);
|
|
|
|
TestCase.assertEqual(obj.arrayCol[1].doubleCol, 1);
|
|
|
|
TestCase.assertEqual(obj.arrayCol[2].doubleCol, 2);
|
2015-08-13 16:12:48 +00:00
|
|
|
},
|
2015-11-25 18:48:51 +00:00
|
|
|
testEnumerablePropertyNames: function() {
|
|
|
|
var realm = new Realm({schema: [schemas.BasicTypes]});
|
|
|
|
var object;
|
|
|
|
|
|
|
|
realm.write(function() {
|
2015-11-02 20:02:53 +00:00
|
|
|
object = realm.create('BasicTypesObject', {
|
|
|
|
boolCol: true,
|
|
|
|
intCol: 1,
|
|
|
|
floatCol: 1.1,
|
|
|
|
doubleCol: 1.11,
|
|
|
|
stringCol: 'string',
|
|
|
|
dateCol: new Date(1),
|
|
|
|
dataCol: RANDOM_DATA,
|
|
|
|
});
|
2015-11-25 18:48:51 +00:00
|
|
|
});
|
|
|
|
|
2015-10-30 19:08:31 +00:00
|
|
|
var propNames = Object.keys(schemas.BasicTypes.properties);
|
2015-11-25 18:48:51 +00:00
|
|
|
TestCase.assertArraysEqual(Object.keys(object), propNames, 'Object.keys');
|
|
|
|
|
|
|
|
for (var key in object) {
|
|
|
|
TestCase.assertEqual(key, propNames.shift());
|
|
|
|
}
|
|
|
|
|
|
|
|
TestCase.assertEqual(propNames.length, 0);
|
|
|
|
},
|
2015-11-16 11:26:33 +00:00
|
|
|
testDataProperties: function() {
|
|
|
|
var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});
|
|
|
|
var object;
|
|
|
|
|
|
|
|
// Should be be able to set a data property with a typed array.
|
|
|
|
realm.write(function() {
|
|
|
|
object = realm.create('DefaultValuesObject', {dataCol: RANDOM_DATA});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Data properties should return an instance of an ArrayBuffer.
|
|
|
|
TestCase.assertTrue(object.dataCol instanceof ArrayBuffer);
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object.dataCol), RANDOM_DATA);
|
|
|
|
|
|
|
|
// Should be able to also set a data property to an ArrayBuffer.
|
|
|
|
realm.write(function() {
|
|
|
|
object.dataCol = RANDOM_DATA.buffer;
|
|
|
|
});
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object.dataCol), RANDOM_DATA);
|
|
|
|
|
2015-11-16 21:48:37 +00:00
|
|
|
// Should be to set a data property to a DataView.
|
|
|
|
realm.write(function() {
|
|
|
|
object.dataCol = new DataView(RANDOM_DATA.buffer);
|
|
|
|
});
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object.dataCol), RANDOM_DATA);
|
|
|
|
|
|
|
|
// Test that a variety of size and slices of data still work.
|
|
|
|
[
|
|
|
|
[0, -1],
|
|
|
|
[0, -2],
|
|
|
|
[1, 0],
|
|
|
|
[1, -1],
|
|
|
|
[1, -2],
|
|
|
|
[2, 0],
|
|
|
|
[2, -1],
|
|
|
|
[2, -2],
|
|
|
|
].forEach(function(range) {
|
|
|
|
var array = RANDOM_DATA.subarray(range[0], range[1]);
|
|
|
|
realm.write(function() {
|
|
|
|
// Use a partial "view" of the underlying ArrayBuffer.
|
|
|
|
object.dataCol = new Uint8Array(RANDOM_DATA.buffer, range[0], array.length);
|
|
|
|
});
|
|
|
|
TestCase.assertArraysEqual(new Uint8Array(object.dataCol), array, range.join('...'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test other TypedArrays to make sure they all work for setting data properties.
|
|
|
|
[
|
|
|
|
Int8Array,
|
|
|
|
Uint8ClampedArray,
|
|
|
|
Int16Array,
|
|
|
|
Uint16Array,
|
|
|
|
Int32Array,
|
|
|
|
Uint32Array,
|
|
|
|
Float32Array,
|
|
|
|
Float64Array,
|
|
|
|
].forEach(function(TypedArray) {
|
|
|
|
var array = new TypedArray(RANDOM_DATA.buffer);
|
|
|
|
realm.write(function() {
|
|
|
|
object.dataCol = array;
|
|
|
|
});
|
|
|
|
TestCase.assertArraysEqual(new TypedArray(object.dataCol), array, TypedArray.name);
|
|
|
|
});
|
|
|
|
|
2015-11-16 11:26:33 +00:00
|
|
|
realm.write(function() {
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
object.dataCol = true;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
object.dataCol = 1;
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
object.dataCol = 'data';
|
|
|
|
});
|
|
|
|
TestCase.assertThrows(function() {
|
|
|
|
object.dataCol = [1];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-10-14 22:25:58 +00:00
|
|
|
});
|