File: h.t

package info (click to toggle)
libglib-perl 1%3A1.140-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 980 kB
  • ctags: 312
  • sloc: perl: 2,481; ansic: 564; makefile: 53
file content (144 lines) | stat: -rw-r--r-- 4,993 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# BookmarkFile
#
use strict;
use warnings;
use Glib ':constants';
use Test::More tests => 27;

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", 27
		unless Glib->CHECK_VERSION (2, 11, 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');
	
	my @groups = $bookmark_file->get_groups($uri);
	is (@groups, 2, 'check add group');

	$bookmark_file->remove_group($uri, 'Stuff');
	ok (!$bookmark_file->has_group($uri, 'Stuff'), 'check has_group');
	
	$bookmark_file->add_application($uri, 'Gedit', 'gedit %u');
	ok ($bookmark_file->has_application($uri, 'Gedit'), 'check add_application');
	ok (!$bookmark_file->has_application($uri, 'Vim'), 'check has_application');

	$bookmark_file->add_application($uri, 'Vim', 'gvim %f');
	$bookmark_file->add_application($uri, 'Gedit', 'gedit %u');

	my ($exec, $count, $stamp) = $bookmark_file->get_app_info($uri, 'Gedit');
	is ($exec, "gedit $uri", 'check get_app_info/1');
	is ($count, '2', 'check get_app_info/2');
	
	my $now = time ();
	$bookmark_file->set_app_info($uri, 'Vim', 'gvim %f', 42, $now);
	is ($now, $bookmark_file->get_modified($uri),
	    'check set_app_info/1');

	(undef, $count, $stamp) = $bookmark_file->get_app_info($uri, 'Vim');
	is ($count, 42, 'check set_app_info/2');
	is ($stamp, $now, 'check set_app_info/3');

	$bookmark_file->set_app_info($uri, 'Gedit', '', 0, 1);
	ok (!$bookmark_file->has_application($uri, 'Gedit'),
	    'check set_app_info/4');

	$bookmark_file->remove_application($uri, 'Vim');
	ok (!$bookmark_file->has_application($uri, 'Vim'),
	    'check remove_application');

	my $new_uri =  'file:///tmp/some-other-test.txt';
	$bookmark_file->move_item($uri, $new_uri);
	ok ($bookmark_file->has_item($new_uri), 'check move_item/1');
	ok (!$bookmark_file->has_item($uri), 'check move_item/2');
	
	$bookmark_file->move_item($new_uri, undef);
	ok (!$bookmark_file->has_item($new_uri), 'check move_item/3');

	$bookmark_file->remove_item($uris[0]);
	is ($bookmark_file->get_size, 0, 'check_remove_item');
}

__END__

Copyright (C) 2006 by the gtk2-perl team (see the file AUTHORS for the
full list)

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Library General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU Library General Public License for more
details.

You should have received a copy of the GNU Library General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA  02111-1307  USA.