cleanup veilid-flutter

This commit is contained in:
Christien Rioux 2024-05-02 14:15:42 -04:00
parent b948c53863
commit 439d2641f1
16 changed files with 275 additions and 291 deletions

View file

@ -3,8 +3,8 @@ import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:veilid/veilid.dart';
const testDb = "__dart_test_db";
const testNonexistentDb = "__dart_test_nonexistent_db";
const testDb = '__dart_test_db';
const testNonexistentDb = '__dart_test_nonexistent_db';
Future<void> testDeleteTableDbNonExistent() async {
expect(await Veilid.instance.deleteTableDB(testNonexistentDb), isFalse);
@ -16,7 +16,7 @@ Future<void> testOpenDeleteTableDb() async {
final tdb = await Veilid.instance.openTableDB(testDb, 1);
try {
await expectLater(() async => await Veilid.instance.deleteTableDB(testDb),
await expectLater(() async => Veilid.instance.deleteTableDB(testDb),
throwsA(isA<VeilidAPIException>()));
} finally {
tdb.close();
@ -32,11 +32,11 @@ Future<void> testOpenTwiceTableDb() async {
final tdb2 = await Veilid.instance.openTableDB(testDb, 1);
// delete should fail because open
await expectLater(() async => await Veilid.instance.deleteTableDB(testDb),
await expectLater(() async => Veilid.instance.deleteTableDB(testDb),
throwsA(isA<VeilidAPIException>()));
tdb.close();
// delete should fail because open
await expectLater(() async => await Veilid.instance.deleteTableDB(testDb),
await expectLater(() async => Veilid.instance.deleteTableDB(testDb),
throwsA(isA<VeilidAPIException>()));
tdb2.close();
@ -53,10 +53,10 @@ Future<void> testOpenTwiceTableDbStoreLoad() async {
final tdb2 = await Veilid.instance.openTableDB(testDb, 1);
try {
// store into first db copy
await tdb.store(0, utf8.encode("asdf"), utf8.encode("1234"));
await tdb.store(0, utf8.encode('asdf'), utf8.encode('1234'));
// load from second db copy
expect(
await tdb2.load(0, utf8.encode("asdf")), equals(utf8.encode("1234")));
await tdb2.load(0, utf8.encode('asdf')), equals(utf8.encode('1234')));
} finally {
tdb2.close();
}
@ -77,14 +77,14 @@ Future<void> testOpenTwiceTableDbStoreDeleteLoad() async {
final tdb2 = await Veilid.instance.openTableDB(testDb, 1);
try {
// store into first db copy
await tdb.store(0, utf8.encode("asdf"), utf8.encode("1234"));
await tdb.store(0, utf8.encode('asdf'), utf8.encode('1234'));
// delete from second db copy and clean up
await tdb2.delete(0, utf8.encode("asdf"));
await tdb2.delete(0, utf8.encode('asdf'));
} finally {
tdb2.close();
}
// load from first db copy
expect(await tdb.load(0, utf8.encode("asdf")), isNull);
expect(await tdb.load(0, utf8.encode('asdf')), isNull);
} finally {
tdb.close();
}
@ -100,7 +100,7 @@ Future<void> testResizeTableDb() async {
final tdb = await Veilid.instance.openTableDB(testDb, 1);
try {
// reopen the db with more columns should fail if it is already open
await expectLater(() async => await Veilid.instance.openTableDB(testDb, 2),
await expectLater(() async => Veilid.instance.openTableDB(testDb, 2),
throwsA(isA<VeilidAPIException>()));
} finally {
tdb.close();
@ -109,18 +109,18 @@ Future<void> testResizeTableDb() async {
final tdb2 = await Veilid.instance.openTableDB(testDb, 2);
try {
// write something to second column
await tdb2.store(1, utf8.encode("qwer"), utf8.encode("5678"));
await tdb2.store(1, utf8.encode('qwer'), utf8.encode('5678'));
// reopen the db with fewer columns
final tdb3 = await Veilid.instance.openTableDB(testDb, 1);
try {
// Should fail access to second column
await expectLater(() async => await tdb3.load(1, utf8.encode("qwer")),
await expectLater(() async => tdb3.load(1, utf8.encode('qwer')),
throwsA(isA<VeilidAPIException>()));
// Should succeed with access to second column
expect(
await tdb2.load(1, utf8.encode("qwer")), equals(utf8.encode("5678")));
await tdb2.load(1, utf8.encode('qwer')), equals(utf8.encode('5678')));
} finally {
tdb3.close();
}