1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
from bzrlib.tests import TestCase, TestCaseInTempDir
 
 
18
from bzrlib.plugins.gtk.olive import Preferences
 
 
22
# FIXME: need to make sure that this also tests writing/reading.
 
 
23
class TestPreferences(TestCaseInTempDir):
 
 
25
        super(TestPreferences, self).setUp()
 
 
26
        self.prefs = Preferences(os.path.join(self.test_dir, 'prefs'))
 
 
28
    def test_create(self):
 
 
31
    def test_add_bookmark(self):
 
 
32
        """make sure a bookmark can be added. This function is only supposed 
 
 
33
        to store the location, not try to access it. """
 
 
34
        self.assertTrue(self.prefs.add_bookmark("file://foobar"))
 
 
35
        self.assertTrue("file://foobar" in self.prefs.get_bookmarks())
 
 
37
    def test_add_bookmark_twice(self):
 
 
38
        """Adding an already present bookmark will result in False being 
 
 
40
        self.assertTrue(self.prefs.add_bookmark("file://foobar"))
 
 
41
        self.assertFalse(self.prefs.add_bookmark("file://foobar"))
 
 
43
    def test_set_bookmark_title(self):
 
 
44
        """Test setting a title for an existing bookmark."""
 
 
45
        self.prefs.add_bookmark("file://foobar")
 
 
46
        self.prefs.set_bookmark_title("file://foobar", "My Bookmark")
 
 
48
    def test_remove_bookmark(self):
 
 
49
        """Test removing a bookmark."""
 
 
50
        self.prefs.add_bookmark("http://example.com/branch")
 
 
51
        self.prefs.remove_bookmark("http://example.com/branch")
 
 
52
        self.assertFalse("http://example.com/branch" in self.prefs.get_bookmarks())
 
 
54
    def test_get_bookmarks_empty(self):
 
 
55
        """Test whether a new Preferences() object has an empty bookmarks 
 
 
57
        self.assertEqual([], self.prefs.get_bookmarks())
 
 
59
    def test_get_bookmark_title_set(self):
 
 
60
        """Test getting a title for an existing bookmark."""
 
 
61
        self.prefs.add_bookmark("file://foobar")
 
 
62
        self.prefs.set_bookmark_title("file://foobar", "My Bookmark")
 
 
63
        self.assertEqual("My Bookmark", self.prefs.get_bookmark_title("file://foobar"))
 
 
65
    def test_get_bookmark_title_implicit(self):
 
 
66
        """Test getting a bookmark title for a bookmark that doesn't
 
 
68
        self.prefs.add_bookmark("file://bla")
 
 
69
        self.assertEqual("file://bla", self.prefs.get_bookmark_title("file://bla"))
 
 
71
    def test_set_preference(self):
 
 
72
        """Check whether setting preferences works."""
 
 
73
        self.prefs.set_preference("foo", True)
 
 
74
        self.prefs.set_preference("foo", False)
 
 
75
        self.prefs.set_preference("foo", "bloe")
 
 
77
    def test_get_preference_bool(self):
 
 
78
        """Check whether a preference can be retrieved."""
 
 
79
        self.prefs.set_preference("foo", True)
 
 
80
        self.assertEqual(True, self.prefs.get_preference("foo", "bool"))
 
 
82
    def test_get_preference_str(self):
 
 
83
        """Check whether a string preference can be retrieved."""
 
 
84
        self.prefs.set_preference("bla", "bloe")
 
 
85
        self.assertEqual("bloe", self.prefs.get_preference("bla"))
 
 
87
    def test_get_preference_nonexistant(self):
 
 
88
        """Check whether get_preference returns None for nonexisting 
 
 
90
        self.assertEqual(None, self.prefs.get_preference("foo"))