+subtest 'Maintenance' => sub {
+ my $kdbx = File::KDBX->new;
+ $kdbx->add_group;
+ $kdbx->add_group->add_group;
+ my $entry = $kdbx->add_group->add_entry;
+
+ cmp_ok $kdbx->remove_empty_groups, '==', 3, 'Remove two empty groups';
+ cmp_ok $kdbx->groups->count, '==', 2, 'Two groups remain';
+
+ $entry->begin_work;
+ $entry->commit;
+ cmp_ok $kdbx->prune_history(max_age => 5), '==', 0, 'Do not remove new historical entries';
+
+ $entry->begin_work;
+ $entry->commit;
+ $entry->history->[0]->last_modification_time(scalar gmtime - 86400 * 10);
+ cmp_ok $kdbx->prune_history(max_age => 5), '==', 1, 'Remove a historical entry';
+ cmp_ok scalar @{$entry->history}, '==', 1, 'One historical entry remains';
+
+ cmp_ok $kdbx->remove_unused_icons, '==', 0, 'No icons to remove';
+ $kdbx->add_custom_icon('fake image 1');
+ $kdbx->add_custom_icon('fake image 2');
+ $entry->custom_icon('fake image 3');
+ cmp_ok $kdbx->remove_unused_icons, '==', 2, 'Remove unused icons';
+ cmp_ok scalar @{$kdbx->custom_icons}, '==', 1, 'Only one icon remains';
+
+ my $icon_uuid = $kdbx->add_custom_icon('fake image');
+ $entry->custom_icon('fake image');
+ cmp_ok $kdbx->remove_duplicate_icons, '==', 1, 'Remove duplicate icons';
+ is $entry->custom_icon_uuid, $icon_uuid, 'Uses of removed icon change';
+};
+
+subtest 'Dumping to filesystem' => sub {
+ my $kdbx = File::KDBX->new;
+ $kdbx->add_entry(title => 'Foo', password => 'whatever');
+
+ my ($fh, $filepath) = tempfile('kdbx-XXXXXX', TMPDIR => 1, UNLINK => 1);
+ close($fh);
+
+ $kdbx->dump($filepath, 'a');
+
+ my $kdbx2 = File::KDBX->load($filepath, 'a');
+ my $entry = $kdbx2->entries->map(sub { $_->title.'/'.$_->expand_password })->next;
+ is $entry, 'Foo/whatever', 'Dump and load an entry';
+
+ $kdbx->dump($filepath, key => 'a', atomic => 0);
+
+ $kdbx2 = File::KDBX->load($filepath, 'a');
+ $entry = $kdbx2->entries->map(sub { $_->title.'/'.$_->expand_password })->next;
+ is $entry, 'Foo/whatever', 'Dump and load an entry (non-atomic)';
+};
+