mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor!: use Finalizer
to automatically free allocated memory for objects (#48)
BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
parent
94c40f9a94
commit
a3213a88a2
103 changed files with 2278 additions and 2595 deletions
|
@ -26,9 +26,7 @@ void main() {
|
|||
|
||||
group('Odb', () {
|
||||
test('successfully initializes', () {
|
||||
final odb = repo.odb;
|
||||
expect(odb, isA<Odb>());
|
||||
odb.free();
|
||||
expect(repo.odb, isA<Odb>());
|
||||
});
|
||||
|
||||
test('throws when trying to get odb and error occurs', () {
|
||||
|
@ -36,9 +34,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new odb with no backends', () {
|
||||
final odb = Odb.create();
|
||||
expect(odb, isA<Odb>());
|
||||
odb.free();
|
||||
expect(Odb.create(), isA<Odb>());
|
||||
});
|
||||
|
||||
test('adds disk alternate', () {
|
||||
|
@ -46,33 +42,22 @@ void main() {
|
|||
odb.addDiskAlternate(p.join(repo.path, 'objects'));
|
||||
|
||||
expect(odb.contains(repo[blobSha]), true);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('reads object', () {
|
||||
final oid = repo[blobSha];
|
||||
final odb = repo.odb;
|
||||
final object = odb.read(oid);
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
|
||||
expect(object.oid, oid);
|
||||
expect(object.oid, repo[blobSha]);
|
||||
expect(object.type, GitObject.blob);
|
||||
expect(object.data, blobContent);
|
||||
expect(object.size, 13);
|
||||
|
||||
object.free();
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to read object and error occurs', () {
|
||||
final odb = repo.odb;
|
||||
|
||||
expect(
|
||||
() => odb.read(repo['0' * 40]),
|
||||
() => repo.odb.read(repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test("returns list of all objects oid's in database", () {
|
||||
|
@ -80,8 +65,6 @@ void main() {
|
|||
|
||||
expect(odb.objects, isNot(isEmpty));
|
||||
expect(odb.objects.contains(repo[commitSha]), true);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get list of all objects and error occurs', () {
|
||||
|
@ -92,8 +75,6 @@ void main() {
|
|||
() => odb.objects,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('writes data', () {
|
||||
|
@ -103,19 +84,13 @@ void main() {
|
|||
|
||||
expect(odb.contains(oid), true);
|
||||
expect(object.data, 'testing');
|
||||
|
||||
object.free();
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write with invalid object type', () {
|
||||
final odb = repo.odb;
|
||||
expect(
|
||||
() => odb.write(type: GitObject.any, data: 'testing'),
|
||||
() => repo.odb.write(type: GitObject.any, data: 'testing'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write alternate odb to disk', () {
|
||||
|
@ -126,15 +101,20 @@ void main() {
|
|||
() => odb.write(type: GitObject.blob, data: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
odb.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => repo.odb.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory for odbObject object', () {
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
expect(() => object.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of OdbObject object', () {
|
||||
final odb = repo.odb;
|
||||
final object = odb.read(repo[blobSha]);
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
expect(object.toString(), contains('OdbObject{'));
|
||||
odb.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue