wont work until we have propery object store support

This commit is contained in:
Ari Lazier 2015-10-21 20:36:21 -07:00
parent 0df214ad21
commit fc631c3e6f
3 changed files with 37 additions and 6 deletions

View File

@ -49,10 +49,20 @@ static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyOb
static JSStringRef nameString = JSStringCreateWithUTF8CString("name"); static JSStringRef nameString = JSStringCreateWithUTF8CString("name");
static JSStringRef typeString = JSStringCreateWithUTF8CString("type"); static JSStringRef typeString = JSStringCreateWithUTF8CString("type");
static JSStringRef objectTypeString = JSStringCreateWithUTF8CString("objectType"); static JSStringRef objectTypeString = JSStringCreateWithUTF8CString("objectType");
static JSStringRef optionalString = JSStringCreateWithUTF8CString("optional");
Property prop; Property prop;
prop.name = RJSValidatedStringProperty(ctx, propertyObject, nameString); prop.name = RJSValidatedStringProperty(ctx, propertyObject, nameString);
prop.is_nullable = false;
JSValueRef optionalValue = JSObjectGetProperty(ctx, propertyObject, optionalString, NULL);
if (!JSValueIsUndefined(ctx, optionalValue)) {
if (!JSValueIsBoolean(ctx, optionalValue)) {
throw std::runtime_error("Property expected to be of type boolean");
}
prop.is_nullable = JSValueToBoolean(ctx, optionalValue);
}
std::string type = RJSValidatedStringProperty(ctx, propertyObject, typeString); std::string type = RJSValidatedStringProperty(ctx, propertyObject, typeString);
if (type == "PropTypesBOOL") { if (type == "PropTypesBOOL") {
prop.type = PropertyTypeBool; prop.type = PropertyTypeBool;
@ -75,19 +85,14 @@ static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyOb
else if (type == "PropTypesDATA") { else if (type == "PropTypesDATA") {
prop.type = PropertyTypeData; prop.type = PropertyTypeData;
} }
else if (type == "PropTypesOBJECT") {
prop.type = PropertyTypeObject;
prop.object_type = RJSValidatedStringProperty(ctx, propertyObject, objectTypeString);
prop.is_nullable = true;
}
else if (type == "PropTypesLIST") { else if (type == "PropTypesLIST") {
prop.type = PropertyTypeArray; prop.type = PropertyTypeArray;
prop.object_type = RJSValidatedStringProperty(ctx, propertyObject, objectTypeString); prop.object_type = RJSValidatedStringProperty(ctx, propertyObject, objectTypeString);
} }
else { else {
prop.type = PropertyTypeObject; prop.type = PropertyTypeObject;
prop.object_type = type;
prop.is_nullable = true; prop.is_nullable = true;
prop.object_type = type == "PropTypesOBJECT" ? RJSValidatedStringProperty(ctx, propertyObject, objectTypeString) : type;
} }
return prop; return prop;
} }

View File

@ -47,6 +47,19 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(object.nonexistent, undefined); TestCase.assertEqual(object.nonexistent, undefined);
}, },
testNullableBasicTypesPropertyGetters: function() {
var basicTypesValues = [null, null, null, null, null, null, null];
var realm = new Realm({schema: [schemas.NullableBasicTypes]});
var object = null;
realm.write(function() {
object = realm.create('NullableBasicTypesObject', basicTypesValues);
});
for (var i = 0; i < schemas.BasicTypes.properties.length; i++) {
var prop = schemas.BasicTypes.properties[i];
TestCase.assertEqual(object[prop.name], null);
}
},
testBasicTypesPropertySetters: function() { testBasicTypesPropertySetters: function() {
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA']; var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
var realm = new Realm({schema: [schemas.BasicTypes]}); var realm = new Realm({schema: [schemas.BasicTypes]});

View File

@ -53,6 +53,19 @@ exports.BasicTypes = {
] ]
}; };
exports.NullableBasicTypes = {
name: 'NullableBasicTypes',
properties: [
{name: 'boolCol', type: Realm.Types.BOOL, optional: true},
{name: 'intCol', type: Realm.Types.INT, optional: true},
{name: 'floatCol', type: Realm.Types.FLOAT, optional: true},
{name: 'doubleCol', type: Realm.Types.DOUBLE, optional: true},
{name: 'stringCol', type: Realm.Types.STRING, optional: true},
{name: 'dateCol', type: Realm.Types.DATE, optional: true},
{name: 'dataCol', type: Realm.Types.DATA, optional: true},
]
};
exports.LinkTypes = { exports.LinkTypes = {
name: 'LinkTypesObject', name: 'LinkTypesObject',
properties: [ properties: [