71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#include "contentpresenttest.h"
|
|
#include <QtTest/QTest>
|
|
|
|
using namespace TestCase;
|
|
|
|
|
|
ContentPresentTest::ContentPresentTest(MakeTools::ContentPresent *view)
|
|
: inst(view)
|
|
{
|
|
|
|
}
|
|
|
|
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()){
|
|
if(s == "*")
|
|
continue;
|
|
|
|
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->targetPath(curr) == "");
|
|
QVERIFY(nins->absulateTargetPath() == "");
|
|
nins->load(QFileInfo(curr.absoluteFilePath(std::get<1>(mark))));
|
|
QVERIFY(nins->getText() == "");
|
|
QVERIFY(nins->targetPath(curr) != "");
|
|
QVERIFY(nins->absulateTargetPath() != "");
|
|
auto a = std::get<1>(mark);
|
|
auto b = nins->targetPath(curr);
|
|
QVERIFY(a == b || a=="./"+b || "./"+a == b);
|
|
|
|
nins->saveAs("./另存测试文档." + s);
|
|
QVERIFY(QFileInfo::exists("./另存测试文档." + s));
|
|
|
|
nins->load(QFileInfo("./另存测试文档." + s));
|
|
QVERIFY(nins->getText() == "");
|
|
delete nins;
|
|
}
|
|
}
|