|
| 1 | +import 'dart:convert'; |
| 2 | + |
| 3 | +import 'package:bson/bson.dart'; |
| 4 | +import 'package:sqlite3/common.dart'; |
| 5 | +import 'package:test/test.dart'; |
| 6 | + |
| 7 | +import 'utils/native_test_utils.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('text lines', () { |
| 11 | + _syncTests(isBson: false); |
| 12 | + }); |
| 13 | + |
| 14 | + group('bson lines', () { |
| 15 | + _syncTests(isBson: true); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +void _syncTests<T>({ |
| 20 | + required bool isBson, |
| 21 | +}) { |
| 22 | + late CommonDatabase db; |
| 23 | + |
| 24 | + setUp(() async { |
| 25 | + db = openTestDatabase() |
| 26 | + ..select('select powersync_init();') |
| 27 | + ..select('select powersync_replace_schema(?)', [json.encode(_schema)]); |
| 28 | + }); |
| 29 | + |
| 30 | + tearDown(() { |
| 31 | + db.dispose(); |
| 32 | + }); |
| 33 | + |
| 34 | + List<Object?> invokeControl(String operation, Object? data) { |
| 35 | + final [row] = |
| 36 | + db.select('SELECT powersync_control(?, ?)', [operation, data]); |
| 37 | + return jsonDecode(row.columnAt(0)); |
| 38 | + } |
| 39 | + |
| 40 | + List<Object?> syncLine(Object? line) { |
| 41 | + if (isBson) { |
| 42 | + return invokeControl('line_binary', BsonCodec.serialize(line).byteList); |
| 43 | + } else { |
| 44 | + return invokeControl('line_text', jsonEncode(line)); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + test('starting stream', () { |
| 49 | + final result = invokeControl('start', null); |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | +const _schema = { |
| 54 | + 'tables': [ |
| 55 | + { |
| 56 | + 'name': 'items', |
| 57 | + 'columns': [ |
| 58 | + {'name': 'col', 'type': 'text'} |
| 59 | + ], |
| 60 | + } |
| 61 | + ] |
| 62 | +}; |
| 63 | + |
| 64 | +const _bucketDescriptions = { |
| 65 | + 'prio0': {'priority': 0}, |
| 66 | + 'prio1': {'priority': 1}, |
| 67 | + 'prio2': {'priority': 2}, |
| 68 | + 'prio3': {'priority': 3}, |
| 69 | +}; |
0 commit comments