1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5
6from gi.repository import Gtk, Gdk
7
8from tests import TestCase, skipIf
9from quodlibet.qltk.getstring import GetStringDialog
10from quodlibet.qltk import is_wayland
11
12
13class _ClipboadTestClass(GetStringDialog):
14    _OK = True
15
16    def _verify_clipboard(self, text):
17        if self._OK:
18            return text
19
20
21@skipIf(is_wayland(), "blocks under wayland for some reason")
22class TGetStringDialog(TestCase):
23    def setUp(self):
24        parent = Gtk.Window()
25        self.gsd1 = GetStringDialog(parent, "title", "enter a string")
26        self.gsd2 = _ClipboadTestClass(parent, "title", "enter a string")
27
28    def test_getstring(self):
29        ret = self.gsd1.run(text="foobar", test=True)
30        self.failUnlessEqual(ret, "foobar")
31
32    def test_tooltip(self):
33        foo = GetStringDialog(Gtk.Window(), "title", "", tooltip="foo bar")
34        self.failUnlessEqual(foo._val.get_tooltip_text(), "foo bar")
35
36    def test_clipboard(self):
37        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
38        clipboard.set_text("42", -1)
39        ret = self.gsd2.run(text="24", clipboard=True, test=True)
40        self.failUnlessEqual(ret, "42")
41        clipboard.clear()
42
43    def tearDown(self):
44        self.gsd1.destroy()
45        self.gsd2.destroy()
46