Files
FWS-DiskCleaner/tests/test-helpers.h
T
BlackAngelTV 977b1c35a9 feat: add treemap disk space analyzer
Users need to see at a glance what fills a disk and to remove the largest
entries without digging through a file manager. The treemap makes sizes
comparable, the scan runs off the UI thread, and removing an entry updates
the tree in place instead of rescanning.
2026-11-27 07:41:04 +01:00

46 lines
989 B
C++

#pragma once
#include "core/disk-node.h"
#include "core/disk-scanner.h"
#include <QDir>
#include <QFile>
#include <memory>
// Test helpers only: they keep the fixtures readable without hiding behaviour.
namespace test_helpers {
inline bool writeFile(const QString &path, int bytes)
{
QFile file(path);
if (!file.open(QIODevice::WriteOnly)) {
return false;
}
return file.write(QByteArray(bytes, 'x')) == bytes;
}
inline DiskNode *childNamed(const DiskNode &node, const QString &name)
{
for (const auto &child : node.children) {
if (child->name == name) {
return child.get();
}
}
return nullptr;
}
inline std::shared_ptr<DiskNode> scan(const QString &path, ScanStats *stats = nullptr)
{
DiskScanner scanner(path);
scanner.start();
if (!scanner.wait(30000)) {
return nullptr;
}
if (stats) {
*stats = scanner.stats();
}
return scanner.takeTree();
}
} // namespace test_helpers