Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions autotests/dfm-search-tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QTest>

Check warning on line 5 in autotests/dfm-search-tests/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 5 in autotests/dfm-search-tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// Test object creation functions are defined in their respective .cpp files
extern QObject *create_tst_DfmSearch();
extern QObject *create_tst_SearchUtils();
extern QObject *create_tst_TimeRangeFilter();
extern QObject *create_tst_TextSearchAPI();

int main(int argc, char *argv[])
{
int result = 0;

// Test object creation functions are defined in their respective .cpp files
extern QObject *create_tst_DfmSearch();
extern QObject *create_tst_SearchUtils();
extern QObject *create_tst_TimeRangeFilter();

// Run all test objects
QObject *testObj1 = create_tst_DfmSearch();
result |= QTest::qExec(testObj1, argc, argv);
Expand All @@ -26,5 +27,9 @@
result |= QTest::qExec(testObj3, argc, argv);
delete testObj3;

QObject *testObj4 = create_tst_TextSearchAPI();
result |= QTest::qExec(testObj4, argc, argv);
delete testObj4;

return result;
}
330 changes: 330 additions & 0 deletions autotests/dfm-search-tests/tst_textsearch_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QTest>

Check warning on line 5 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 5 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-search/searchoptions.h>

Check warning on line 6 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-search/searchoptions.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 6 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-search/searchoptions.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-search/searchresult.h>

Check warning on line 7 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-search/searchresult.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 7 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-search/searchresult.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-search/textsearchapi.h>

Check warning on line 8 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-search/textsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-search/textsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-search/contentsearchapi.h>

Check warning on line 9 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-search/contentsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-search/contentsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-search/ocrtextsearchapi.h>

Check warning on line 10 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-search/ocrtextsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-search/ocrtextsearchapi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace DFMSEARCH;

class tst_TextSearchAPI : public QObject
{
Q_OBJECT

private Q_SLOTS:

Check warning on line 18 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.

Check warning on line 18 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
void initTestCase();
void cleanupTestCase();

// TextSearchOptionsAPI tests
void textSearchOptions_defaultValues();
void textSearchOptions_setMaxPreviewLength();
void textSearchOptions_setSearchResultHighlightEnabled();
void textSearchOptions_setFullTextRetrievalEnabled();

// TextSearchResultAPI tests
void textSearchResult_highlightedContent();
void textSearchResult_filename();
void textSearchResult_isHidden();
void textSearchResult_modifyTimestamp();
void textSearchResult_birthTimestamp();

// ContentOptionsAPI tests
void contentOptions_inheritance();
void contentOptions_setFilenameContentMixedAndSearchEnabled();

// ContentResultAPI tests
void contentResult_inheritance();

// OcrTextOptionsAPI tests
void ocrTextOptions_inheritance();
void ocrTextOptions_defaultValues();
void ocrTextOptions_setFilenameOcrContentMixedAndSearchEnabled();

// OcrTextResultAPI tests
void ocrTextResult_inheritance();
void ocrTextResult_ocrContent();
};

void tst_TextSearchAPI::initTestCase()
{
}

void tst_TextSearchAPI::cleanupTestCase()
{
}

// ==================== TextSearchOptionsAPI Tests ====================

void tst_TextSearchAPI::textSearchOptions_defaultValues()
{
SearchOptions options;
TextSearchOptionsAPI api(options);

// 默认值在构造函数中设置,但基类构造函数不设置默认值
// 默认值由子类设置
QCOMPARE(api.maxPreviewLength(), 0);
QCOMPARE(api.isSearchResultHighlightEnabled(), false);
QCOMPARE(api.isFullTextRetrievalEnabled(), false);
}

void tst_TextSearchAPI::textSearchOptions_setMaxPreviewLength()
{
SearchOptions options;
TextSearchOptionsAPI api(options);

api.setMaxPreviewLength(100);
QCOMPARE(api.maxPreviewLength(), 100);

api.setMaxPreviewLength(500);
QCOMPARE(api.maxPreviewLength(), 500);

api.setMaxPreviewLength(0);
QCOMPARE(api.maxPreviewLength(), 0);
}

void tst_TextSearchAPI::textSearchOptions_setSearchResultHighlightEnabled()
{
SearchOptions options;
TextSearchOptionsAPI api(options);

api.setSearchResultHighlightEnabled(true);
QCOMPARE(api.isSearchResultHighlightEnabled(), true);

api.setSearchResultHighlightEnabled(false);
QCOMPARE(api.isSearchResultHighlightEnabled(), false);
}

void tst_TextSearchAPI::textSearchOptions_setFullTextRetrievalEnabled()
{
SearchOptions options;
TextSearchOptionsAPI api(options);

api.setFullTextRetrievalEnabled(true);
QCOMPARE(api.isFullTextRetrievalEnabled(), true);

api.setFullTextRetrievalEnabled(false);
QCOMPARE(api.isFullTextRetrievalEnabled(), false);
}

// ==================== TextSearchResultAPI Tests ====================

void tst_TextSearchAPI::textSearchResult_highlightedContent()
{
SearchResult result("/test/path");
TextSearchResultAPI api(result);

QVERIFY(api.highlightedContent().isEmpty());

api.setHighlightedContent("test <b>highlighted</b> content");
QCOMPARE(api.highlightedContent(), QString("test <b>highlighted</b> content"));

api.setHighlightedContent("");
QVERIFY(api.highlightedContent().isEmpty());
}

void tst_TextSearchAPI::textSearchResult_filename()
{
SearchResult result("/test/path");
TextSearchResultAPI api(result);

QVERIFY(api.filename().isEmpty());

api.setFilename("test.txt");
QCOMPARE(api.filename(), QString("test.txt"));

api.setFilename("");
QVERIFY(api.filename().isEmpty());
}

void tst_TextSearchAPI::textSearchResult_isHidden()
{
SearchResult result("/test/path");
TextSearchResultAPI api(result);

QCOMPARE(api.isHidden(), false);

api.setIsHidden(true);
QCOMPARE(api.isHidden(), true);

api.setIsHidden(false);
QCOMPARE(api.isHidden(), false);
}

void tst_TextSearchAPI::textSearchResult_modifyTimestamp()
{
SearchResult result("/test/path");
TextSearchResultAPI api(result);

QCOMPARE(api.modifyTimestamp(), 0);

api.setModifyTimestamp(1700000000);
QCOMPARE(api.modifyTimestamp(), 1700000000);
QVERIFY(!api.modifyTimeString().isEmpty());

api.setModifyTimestamp(0);
QCOMPARE(api.modifyTimestamp(), 0);
}

void tst_TextSearchAPI::textSearchResult_birthTimestamp()
{
SearchResult result("/test/path");
TextSearchResultAPI api(result);

QCOMPARE(api.birthTimestamp(), 0);

api.setBirthTimestamp(1600000000);
QCOMPARE(api.birthTimestamp(), 1600000000);
QVERIFY(!api.birthTimeString().isEmpty());

api.setBirthTimestamp(0);
QCOMPARE(api.birthTimestamp(), 0);
}

// ==================== ContentOptionsAPI Tests ====================

void tst_TextSearchAPI::contentOptions_inheritance()
{
SearchOptions options;
ContentOptionsAPI api(options);

// 验证继承自 TextSearchOptionsAPI
api.setMaxPreviewLength(300);
QCOMPARE(api.maxPreviewLength(), 300);

api.setSearchResultHighlightEnabled(true);
QCOMPARE(api.isSearchResultHighlightEnabled(), true);

api.setFullTextRetrievalEnabled(false);
QCOMPARE(api.isFullTextRetrievalEnabled(), false);
}

void tst_TextSearchAPI::contentOptions_setFilenameContentMixedAndSearchEnabled()
{
SearchOptions options;
ContentOptionsAPI api(options);

QCOMPARE(api.isFilenameContentMixedAndSearchEnabled(), false);

api.setFilenameContentMixedAndSearchEnabled(true);
QCOMPARE(api.isFilenameContentMixedAndSearchEnabled(), true);

api.setFilenameContentMixedAndSearchEnabled(false);
QCOMPARE(api.isFilenameContentMixedAndSearchEnabled(), false);
}

// ==================== ContentResultAPI Tests ====================

void tst_TextSearchAPI::contentResult_inheritance()
{
SearchResult result("/test/path");
ContentResultAPI api(result);

// 验证继承自 TextSearchResultAPI
api.setHighlightedContent("content match");
QCOMPARE(api.highlightedContent(), QString("content match"));

api.setFilename("document.pdf");
QCOMPARE(api.filename(), QString("document.pdf"));

api.setIsHidden(true);
QCOMPARE(api.isHidden(), true);

api.setModifyTimestamp(1700000000);
QCOMPARE(api.modifyTimestamp(), 1700000000);

api.setBirthTimestamp(1600000000);
QCOMPARE(api.birthTimestamp(), 1600000000);
}

// ==================== OcrTextOptionsAPI Tests ====================

void tst_TextSearchAPI::ocrTextOptions_inheritance()
{
SearchOptions options;
OcrTextOptionsAPI api(options);

// 验证继承自 TextSearchOptionsAPI
api.setMaxPreviewLength(250);
QCOMPARE(api.maxPreviewLength(), 250);

api.setSearchResultHighlightEnabled(true);
QCOMPARE(api.isSearchResultHighlightEnabled(), true);

api.setFullTextRetrievalEnabled(false);
QCOMPARE(api.isFullTextRetrievalEnabled(), false);
}

void tst_TextSearchAPI::ocrTextOptions_defaultValues()
{
SearchOptions options;
OcrTextOptionsAPI api(options);

// 验证默认值
QCOMPARE(api.maxPreviewLength(), 200);
QCOMPARE(api.isSearchResultHighlightEnabled(), false);
QCOMPARE(api.isFullTextRetrievalEnabled(), true);
QCOMPARE(api.isFilenameOcrContentMixedAndSearchEnabled(), false);
}

void tst_TextSearchAPI::ocrTextOptions_setFilenameOcrContentMixedAndSearchEnabled()
{
SearchOptions options;
OcrTextOptionsAPI api(options);

QCOMPARE(api.isFilenameOcrContentMixedAndSearchEnabled(), false);

api.setFilenameOcrContentMixedAndSearchEnabled(true);
QCOMPARE(api.isFilenameOcrContentMixedAndSearchEnabled(), true);

api.setFilenameOcrContentMixedAndSearchEnabled(false);
QCOMPARE(api.isFilenameOcrContentMixedAndSearchEnabled(), false);
}

// ==================== OcrTextResultAPI Tests ====================

void tst_TextSearchAPI::ocrTextResult_inheritance()
{
SearchResult result("/test/path");
OcrTextResultAPI api(result);

// 验证继承自 TextSearchResultAPI
api.setHighlightedContent("OCR match");
QCOMPARE(api.highlightedContent(), QString("OCR match"));

api.setFilename("image.png");
QCOMPARE(api.filename(), QString("image.png"));

api.setIsHidden(true);
QCOMPARE(api.isHidden(), true);

api.setModifyTimestamp(1700000000);
QCOMPARE(api.modifyTimestamp(), 1700000000);

api.setBirthTimestamp(1600000000);
QCOMPARE(api.birthTimestamp(), 1600000000);
}

void tst_TextSearchAPI::ocrTextResult_ocrContent()
{
SearchResult result("/test/path");
OcrTextResultAPI api(result);

QVERIFY(api.ocrContent().isEmpty());

api.setOcrContent("This is extracted OCR text from image");
QCOMPARE(api.ocrContent(), QString("This is extracted OCR text from image"));

api.setOcrContent("");
QVERIFY(api.ocrContent().isEmpty());
}

QObject *create_tst_TextSearchAPI()
{
return new tst_TextSearchAPI();
}

#include "tst_textsearch_api.moc"

Check warning on line 330 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "tst_textsearch_api.moc" not found.

Check warning on line 330 in autotests/dfm-search-tests/tst_textsearch_api.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "tst_textsearch_api.moc" not found.
Loading
Loading