Changeset View
Changeset View
Standalone View
Standalone View
autotests/kbookmarkmenutest.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include <kbookmarkmenu.h> | 20 | #include <kbookmarkmenu.h> | ||
21 | #include <kbookmarkowner.h> | 21 | #include <kbookmarkowner.h> | ||
22 | #include <kbookmarkmanager.h> | 22 | #include <kbookmarkmanager.h> | ||
23 | #include <KXmlGui/kactioncollection.h> | 23 | #include <KXmlGui/kactioncollection.h> | ||
24 | 24 | | |||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QMenu> | 26 | #include <QMenu> | ||
27 | #include <QStandardPaths> | ||||
27 | #include <QStringLiteral> | 28 | #include <QStringLiteral> | ||
28 | #include <QTest> | 29 | #include <QTest> | ||
29 | 30 | | |||
30 | class TestKBookmarkOwner; | 31 | class TestKBookmarkOwner; | ||
31 | 32 | | |||
32 | class KBookmarkMenuTest : public QObject | 33 | class KBookmarkMenuTest : public QObject | ||
33 | { | 34 | { | ||
34 | Q_OBJECT | 35 | Q_OBJECT | ||
35 | private Q_SLOTS: | 36 | private Q_SLOTS: | ||
36 | void tabsOpen_data(); | 37 | void tabsOpen_data(); | ||
37 | void tabsOpen(); | 38 | void tabsOpen(); | ||
38 | void tabsOpenChanges(); | 39 | void tabsOpenChanges(); | ||
39 | }; | 40 | }; | ||
40 | 41 | | |||
42 | static bool hasBookmarkEditorInstalled() | ||||
dfaure: prepend static (good practice in general so the symbol isn't exported, although in a test… | |||||
43 | { | ||||
44 | static bool isInstalled = !QStandardPaths::findExecutable(QStringLiteral("keditbookmarks")).isEmpty(); | ||||
This code could put the result into a (local) static bool variable, to cache the result, but no big deal for a unittest. dfaure: This code could put the result into a (local) static bool variable, to cache the result, but no… | |||||
45 | return isInstalled; | ||||
46 | } | ||||
47 | | ||||
dfaure: prepend static | |||||
48 | static int actionCountWithoutBookmarkTabsAsFolder() | ||||
49 | { | ||||
50 | return hasBookmarkEditorInstalled() ? 3 : 2; | ||||
51 | } | ||||
52 | | ||||
dfaure: prepend static | |||||
53 | static int actionCountWithBookmarkTabsAsFolder() | ||||
54 | { | ||||
55 | return hasBookmarkEditorInstalled() ? 4 : 3; | ||||
56 | } | ||||
57 | | ||||
41 | class TestKBookmarkOwner final : public KBookmarkOwner | 58 | class TestKBookmarkOwner final : public KBookmarkOwner | ||
42 | { | 59 | { | ||
43 | public: | 60 | public: | ||
44 | explicit TestKBookmarkOwner(bool supportsTabs_); | 61 | explicit TestKBookmarkOwner(bool supportsTabs_); | ||
45 | void openBookmark(const KBookmark &bm, Qt::MouseButtons mb, Qt::KeyboardModifiers km) override; | 62 | void openBookmark(const KBookmark &bm, Qt::MouseButtons mb, Qt::KeyboardModifiers km) override; | ||
46 | bool supportsTabs() const override; | 63 | bool supportsTabs() const override; | ||
47 | private: | 64 | private: | ||
48 | const bool m_supportsTabs; | 65 | const bool m_supportsTabs; | ||
Show All 10 Lines | |||||
59 | 76 | | |||
60 | bool TestKBookmarkOwner::supportsTabs() const | 77 | bool TestKBookmarkOwner::supportsTabs() const | ||
61 | { | 78 | { | ||
62 | return m_supportsTabs; | 79 | return m_supportsTabs; | ||
63 | } | 80 | } | ||
64 | 81 | | |||
65 | #define VERIFY_MENU_WITHOUT_BOOKMARK_TABS_AS_FOLDER() \ | 82 | #define VERIFY_MENU_WITHOUT_BOOKMARK_TABS_AS_FOLDER() \ | ||
66 | do { \ | 83 | do { \ | ||
67 | QCOMPARE(menu->actions().count(), 3); \ | 84 | QCOMPARE(menu->actions().count(), actionCountWithoutBookmarkTabsAsFolder()); \ | ||
68 | QCOMPARE(menu->actions().at(0)->text(), QStringLiteral("&Add Bookmark")); \ | 85 | QCOMPARE(menu->actions().at(0)->text(), QStringLiteral("&Add Bookmark")); \ | ||
69 | QCOMPARE(menu->actions().at(1)->text(), QStringLiteral("New Bookmark Folder...")); \ | 86 | QCOMPARE(menu->actions().at(1)->text(), QStringLiteral("New Bookmark Folder...")); \ | ||
87 | if (hasBookmarkEditorInstalled()) { \ | ||||
70 | QCOMPARE(menu->actions().at(2)->text(), QStringLiteral("&Edit Bookmarks...")); \ | 88 | QCOMPARE(menu->actions().at(2)->text(), QStringLiteral("&Edit Bookmarks...")); \ | ||
89 | } \ | ||||
71 | } while (false) | 90 | } while (false) | ||
72 | 91 | | |||
73 | #define VERIFY_MENU_WITH_BOOKMARK_TABS_AS_FOLDER() \ | 92 | #define VERIFY_MENU_WITH_BOOKMARK_TABS_AS_FOLDER() \ | ||
74 | do { \ | 93 | do { \ | ||
75 | QCOMPARE(menu->actions().count(), 4); \ | 94 | QCOMPARE(menu->actions().count(), actionCountWithBookmarkTabsAsFolder()); \ | ||
76 | QCOMPARE(menu->actions().at(0)->text(), QStringLiteral("&Add Bookmark")); \ | 95 | QCOMPARE(menu->actions().at(0)->text(), QStringLiteral("&Add Bookmark")); \ | ||
77 | QCOMPARE(menu->actions().at(1)->text(), QStringLiteral("Bookmark Tabs as Folder...")); \ | 96 | QCOMPARE(menu->actions().at(1)->text(), QStringLiteral("Bookmark Tabs as Folder...")); \ | ||
78 | QCOMPARE(menu->actions().at(2)->text(), QStringLiteral("New Bookmark Folder...")); \ | 97 | QCOMPARE(menu->actions().at(2)->text(), QStringLiteral("New Bookmark Folder...")); \ | ||
98 | if (hasBookmarkEditorInstalled()) { \ | ||||
79 | QCOMPARE(menu->actions().at(3)->text(), QStringLiteral("&Edit Bookmarks...")); \ | 99 | QCOMPARE(menu->actions().at(3)->text(), QStringLiteral("&Edit Bookmarks...")); \ | ||
100 | } \ | ||||
80 | } while (false) | 101 | } while (false) | ||
81 | 102 | | |||
82 | void KBookmarkMenuTest::tabsOpen_data() | 103 | void KBookmarkMenuTest::tabsOpen_data() | ||
83 | { | 104 | { | ||
84 | QTest::addColumn<bool>("supportsTabs"); | 105 | QTest::addColumn<bool>("supportsTabs"); | ||
85 | QTest::addColumn<int>("numberOfOpenTabs"); | 106 | QTest::addColumn<int>("numberOfOpenTabs"); | ||
86 | 107 | | |||
87 | const bool TabsNotSupported(false); | 108 | const bool TabsNotSupported(false); | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
prepend static (good practice in general so the symbol isn't exported, although in a test program it doesn't make much difference). It becomes a readability difference to me, if I don't see static I wonder which other file wants to call this.