Glib

 view release on metacpan or  search on metacpan

t/h.t  view on Meta::CPAN

#
# BookmarkFile
#
use strict;
use warnings;
use Glib ':constants';
use Test::More tests => 30;

our $str = <<__EOB__
<?xml version="1.0" encoding="UTF-8"?>
<xbel version="1.0"
      xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks"
      xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info"
>
  <bookmark href="file:///tmp/test-file.txt" added="2006-03-22T18:54:00Z" modified="2006-03-22T18:54:00Z" visited="2006-03-22T18:54:00Z">
    <title>Test File</title>
    <desc>Some test file</desc>
    <info>
      <metadata owner="http://freedesktop.org">
        <mime:mime-type type="text/plain"/>
        <bookmark:applications>
          <bookmark:application name="Gedit" exec="gedit %u" timestamp="1143053640" count="1"/>
        </bookmark:applications>
      </metadata>
    </info>
  </bookmark>
</xbel>
__EOB__
;

SKIP: {
	skip "Glib::BookmarkFile is new in glib 2.12.0", 30
		unless Glib->CHECK_VERSION (2, 12, 0);
	
	ok (defined Glib::BookmarkFile->new (), 'test constructor');

	my $bookmark_file = Glib::BookmarkFile->new;
	isa_ok ($bookmark_file, 'Glib::BookmarkFile', 'test ISA');

	my $size;
	$size = $bookmark_file->get_size;
	is ($size, 0, 'we have no bookmarks');

	$bookmark_file->load_from_data ($str);

	$size = $bookmark_file->get_size;
	is ($size, 1, 'we have one bookmark');
	
	my @uris = $bookmark_file->get_uris;
	is (@uris, $size, 'check size');
	eq_array (\@uris, [ 'file:///tmp/test-file.txt' ]);

	ok ($bookmark_file->has_item($uris[0]),
	    'check has item');
	
	is ($bookmark_file->get_title($uris[0]), 'Test File',
	    'check get_title');
	$bookmark_file->set_title($uris[0], 'Test file');
	is ($bookmark_file->get_title($uris[0]), 'Test file',
	    'check set_title');

	is ($bookmark_file->get_description($uris[0]), 'Some test file',
	    'check get_description');
	$bookmark_file->set_description($uris[0], 'Foo');
	is ($bookmark_file->get_description($uris[0]), 'Foo',
	    'check set_description');

	is ($bookmark_file->get_mime_type($uris[0]), 'text/plain',
	    'check get_mime_type');
	$bookmark_file->set_mime_type($uris[0], 'image/png');
	is ($bookmark_file->get_mime_type($uris[0]), 'image/png',
	    'check set_mime_type');
	
	my $uri = 'file:///tmp/another-file.txt';
	$bookmark_file->set_title($uri, 'Another file');
	$bookmark_file->set_description($uri, 'Yet another test file');

	$bookmark_file->add_group($uri, 'Editors');
	$bookmark_file->add_group($uri, 'Stuff');



( run in 1.453 second using v1.01-cache-2.11-cpan-39bf76dae61 )