QtNovelUI/WordsIDE/contentpresenttest.cpp

65 lines
1.9 KiB
C++
Raw Permalink Normal View History

2023-02-26 14:44:00 +00:00
#include "contentpresenttest.h"
#include <QtTest/QTest>
using namespace TestCase;
2023-08-27 14:09:46 +00:00
using namespace Components;
2023-02-26 14:44:00 +00:00
2023-08-27 14:09:46 +00:00
ContentPresentTest::ContentPresentTest(FilePresent *view) : inst(view) {}
2023-02-26 14:44:00 +00:00
void ContentPresentTest::test_Suffixes()
{
QVERIFY(inst->suffixes().count());
}
void ContentPresentTest::test_NewInst_Widget()
{
auto new_inst = inst->newInst();
QVERIFY(new_inst != nullptr);
QVERIFY(typeid (new_inst) == typeid(inst));
QVERIFY(new_inst->widget() != nullptr);
delete new_inst;
}
void ContentPresentTest::test_ApplySetting()
{
auto ninst = inst->newInst();
ninst->applySetting("新命名");
QVERIFY(ninst->name() == QString("新命名"));
delete ninst;
}
void ContentPresentTest::test_Create_Load_SaveAs()
{
QDir curr("./");
for(auto &s : inst->suffixes()){
2023-02-26 16:22:44 +00:00
if(s == "*")
continue;
2023-02-26 14:44:00 +00:00
auto files = curr.entryInfoList(QStringList() << s, QDir::Files);
for(auto &x:files)
curr.remove(x.fileName());
auto mark = inst->create(curr, "新建测试文档", s);
QVERIFY(std::get<0>(mark) || QFileInfo::exists(std::get<1>(mark)));
mark = inst->create(curr, "新建测试文档", s);
QVERIFY(!std::get<0>(mark));
auto nins = inst->newInst();
QVERIFY(nins->relativeTargetPath(curr) == "");
QVERIFY(nins->absoluteTargetPath() == "");
2023-02-26 14:44:00 +00:00
nins->load(QFileInfo(curr.absoluteFilePath(std::get<1>(mark))));
QVERIFY(nins->relativeTargetPath(curr) != "");
QVERIFY(nins->absoluteTargetPath() != "");
2023-02-26 14:44:00 +00:00
auto a = std::get<1>(mark);
auto b = nins->relativeTargetPath(curr);
2023-02-26 14:44:00 +00:00
QVERIFY(a == b || a=="./"+b || "./"+a == b);
nins->saveAs("./另存测试文档." + s);
QVERIFY(QFileInfo::exists("./另存测试文档." + s));
nins->load(QFileInfo("./另存测试文档." + s));
delete nins;
}
}