test: add recent search engine unit tests#328
Conversation
Added comprehensive unit tests for the RecentSearchEngine functionality to ensure proper operation of recent file search features. The tests cover various scenarios including: 1. Empty fetch handling 2. No filter conditions 3. Keyword filtering 4. File extension filtering 5. Time range filtering 6. Combined filters 7. DBus failure handling 8. Detailed result attributes 9. Result count limitation 10. Result found signals The test file tst_recent_search_engine.cpp was created with extensive test cases using the stubext library for mocking DBus calls. The RecentSearchStrategy was made testable by changing fetchRecentItems() access to protected to allow test subclasses to mock this function. test: 添加最近文件搜索引擎单元测试 为最近文件搜索功能添加了全面的单元测试,确保其各项功能正常工作。测试覆盖 了以下多种场景: 1. 空获取处理 2. 无过滤条件 3. 关键词过滤 4. 文件扩展名过滤 5. 时间范围过滤 6. 组合过滤条件 7. DBus调用失败处理 8. 详细结果属性 9. 结果数量限制 10. 结果找到信号 测试文件tst_recent_search_engine.cpp创建了详细的测试用例,使用stubext库 模拟DBus调用。通过将RecentSearchStrategy中的fetchRecentItems()方法访问权 限改为protected,使得测试子类可以模拟该方法以实现测试目的。
There was a problem hiding this comment.
Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // recentsearchstrategy.h
// 使用友元类替代修改访问权限,保持封装性
class RecentSearchStrategy : public BaseSearchStrategy
{
Q_OBJECT
#ifdef DFM_SEARCH_BUILD_TESTS
friend class TestableRecentStrategy;
#endif
public:
explicit RecentSearchStrategy(SearchOptions &options, QObject *parent = nullptr);
~RecentSearchStrategy() override;
void search(const SearchQuery &query) override;
void cancel() override;
private:
// 调用 DBus 获取最近使用记录;失败时返回空列表并记录 warning。
QList<RecentItem> fetchRecentItems();
// ── 过滤管道(每个阶段纯函数,便于测试与组合) ──
/**
* ...
*/
};
// tst_recent_search_engine.cpp
// 测试类无需使用 VADDR 宏,直接调用私有方法打桩(取决于stubext对友元和私有方法的支持情况)
class TestableRecentStrategy : public RecentSearchStrategy
{
public:
using RecentSearchStrategy::RecentSearchStrategy;
// 若 stubext 支持友元访问,可直接提供 this 指针与函数名字符串进行打桩
// 而不需要依赖 protected 权限暴露成员函数指针地址
}; |
Added comprehensive unit tests for the RecentSearchEngine functionality
to ensure proper operation of recent file search features. The tests
cover various scenarios including:
The test file tst_recent_search_engine.cpp was created with extensive
test cases using the stubext library for mocking DBus calls. The
RecentSearchStrategy was made testable by changing fetchRecentItems()
access to protected to allow test subclasses to mock this function.
test: 添加最近文件搜索引擎单元测试
为最近文件搜索功能添加了全面的单元测试,确保其各项功能正常工作。测试覆盖
了以下多种场景:
测试文件tst_recent_search_engine.cpp创建了详细的测试用例,使用stubext库
模拟DBus调用。通过将RecentSearchStrategy中的fetchRecentItems()方法访问权
限改为protected,使得测试子类可以模拟该方法以实现测试目的。