Skip to content

Commit

Permalink
get set all prop types (#854)
Browse files Browse the repository at this point in the history
* fixup publish workflow text

* add a test for all property types

* add changelog
  • Loading branch information
blagoev authored Aug 19, 2022
1 parent 8eb3b65 commit 2f3e709
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Fixed
* Lifted a limitation that only allowed non-nullable primary keys. ([#458](https://github.com/realm/realm-dart/issues/458))
* Fix boolean values get/set after ffigen update. ([#854](https://github.com/realm/realm-dart/pull/854))

### Compatibility
* Realm Studio: 12.0.0 or later.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ extension on Pointer<realm_value_t> {
case realm_value_type.RLM_TYPE_INT:
return ref.values.integer;
case realm_value_type.RLM_TYPE_BOOL:
return ref.values.boolean != 0;
return ref.values.boolean;
case realm_value_type.RLM_TYPE_STRING:
return ref.values.string.data.cast<Utf8>().toRealmDartString(length: ref.values.string.size)!;
case realm_value_type.RLM_TYPE_FLOAT:
Expand Down
44 changes: 43 additions & 1 deletion test/realm_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Future<void> main([List<String>? args]) async {
expect(json, contains('"property with spaces":{ "table": "class_myRemappedClass", "key": 0}'));
});

test('RealmObject read/write bool value', () {
test('RealmObject read/write bool value with json', () {
var config = Configuration.local([BoolValue.schema]);
var realm = getRealm(config);

Expand Down Expand Up @@ -560,4 +560,46 @@ Future<void> main([List<String>? args]) async {
expect(equals1.single.stringProp, equals('1'));
expect(equals1.single.dateProp, equals(date1));
});

test('get/set all property types', () {
final config = Configuration.local([AllTypes.schema]);
final realm = getRealm(config);

var date = DateTime.now().toUtc();
var objectId = ObjectId();
var uuid = Uuid.v4();

final object = realm.write(() {
return realm.add(AllTypes('cde', false, date, 0.1, objectId, uuid, 4));
});

expect(object.stringProp, 'cde');
expect(object.boolProp, false);
expect(object.dateProp, date);
expect(object.doubleProp, 0.1);
expect(object.objectIdProp, objectId);
expect(object.uuidProp, uuid);
expect(object.intProp, 4);

date = DateTime.now().add(Duration(days: 1)).toUtc();
objectId = ObjectId();
uuid = Uuid.v4();
realm.write(() {
object.stringProp = "abc";
object.boolProp = true;
object.dateProp = date;
object.doubleProp = 1.1;
object.objectIdProp = objectId;
object.uuidProp = uuid;
object.intProp = 5;
});

expect(object.stringProp, 'abc');
expect(object.boolProp, true);
expect(object.dateProp, date);
expect(object.doubleProp, 1.1);
expect(object.objectIdProp, objectId);
expect(object.uuidProp, uuid);
expect(object.intProp, 5);
});
}

0 comments on commit 2f3e709

Please sign in to comment.