File indexing completed on 2025-01-05 03:58:16
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-01-12 0007 * Description : a test for the searchtextbar 0008 * 0009 * SPDX-FileCopyrightText: 2010 by Johannes Wienke <languitar at semipol dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "searchtextbar_utest.h" 0016 0017 // Qt includes 0018 0019 #include <QStandardItemModel> 0020 #include <QTest> 0021 #include <qtestkeyboard.h> 0022 0023 // Local includes 0024 0025 0026 using namespace Digikam; 0027 using namespace QTest; 0028 0029 QTEST_MAIN(SearchTextBarTest) 0030 0031 SearchTextBarTest::SearchTextBarTest(QObject* const parent) 0032 : QObject(parent) 0033 { 0034 callCount = 0; 0035 } 0036 0037 void SearchTextBarTest::testHighlighting() 0038 { 0039 SearchTextBar textBar(nullptr, QLatin1String("test")); 0040 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0041 0042 // highlighting shall only occur if text is entered 0043 textBar.slotSearchResult(true); 0044 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0045 0046 textBar.setText(QLatin1String("test")); 0047 0048 textBar.slotSearchResult(true); 0049 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::HAS_RESULT); 0050 textBar.slotSearchResult(false); 0051 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NO_RESULT); 0052 0053 textBar.setHighlightOnResult(false); 0054 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0055 textBar.slotSearchResult(true); 0056 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0057 textBar.slotSearchResult(false); 0058 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0059 0060 textBar.setHighlightOnResult(true); 0061 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NEUTRAL); 0062 textBar.slotSearchResult(true); 0063 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::HAS_RESULT); 0064 textBar.slotSearchResult(false); 0065 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NO_RESULT); 0066 0067 // re-eetting highlighting to true must not change highlight state 0068 textBar.setHighlightOnResult(true); 0069 QCOMPARE(textBar.getCurrentHighlightState(), SearchTextBar::NO_RESULT); 0070 } 0071 0072 void SearchTextBarTest::testSearchTextSettings() 0073 { 0074 SearchTextBar textBar(nullptr, QLatin1String("test")); 0075 0076 SearchTextSettings defaultSettings; 0077 QCOMPARE(textBar.searchTextSettings(), defaultSettings); 0078 0079 callCount = 0; 0080 0081 connect(&textBar, SIGNAL(signalSearchTextSettings(SearchTextSettings)), 0082 this, SLOT(newSearchTextSettings(SearchTextSettings))); 0083 0084 const QString textEntered = QLatin1String("hello world"); 0085 keyClicks(&textBar, textEntered); 0086 0087 QTest::qWait(2000); 0088 0089 QCOMPARE(textBar.searchTextSettings().caseSensitive, defaultSettings.caseSensitive); 0090 QCOMPARE(textBar.searchTextSettings().text, textEntered); 0091 0092 QVERIFY(callCount >= 1); 0093 QCOMPARE(lastSearchTextSettings.caseSensitive, defaultSettings.caseSensitive); 0094 QCOMPARE(lastSearchTextSettings.text, textEntered); 0095 0096 /** @todo test case modifications, but how to click context menu? */ 0097 } 0098 0099 void SearchTextBarTest::newSearchTextSettings(const SearchTextSettings& settings) 0100 { 0101 lastSearchTextSettings = settings; 0102 callCount++; 0103 } 0104 0105 #include "moc_searchtextbar_utest.cpp"