#include "projecttest.h"
#include <QtTest/QTest>

using namespace Project;

TestCase::ProjectTest::ProjectTest(Project::ProjectManager *ins)
    : instance(ins)
{

}

void TestCase::ProjectTest::testSuffix()
{
    QVERIFY(instance->suffix() != "");

    auto path_def = instance->fmtedProjectPath("./", "somepath");
    for(auto idx=0; idx<100; ++idx)
        QVERIFY(path_def == instance->fmtedProjectPath("./", "somepath"));
}

void TestCase::ProjectTest::testNewProject()
{
    auto path = instance->fmtedProjectPath("./", "test_project_define");
    QFile f(path);
    if(f.exists())
        f.remove();

    instance->newProject("./", "test_project_define");
    QVERIFY(f.exists());

    ProjectException *x=nullptr;
    try {
        instance->newProject("./", "test_project_define");
    }  catch (ProjectException *ex) {
        x = ex;
    }
    QVERIFY(x!=nullptr);
}

void TestCase::ProjectTest::testOpenProject()
{
    auto path = instance->fmtedProjectPath("./", "test_project_define");
    QFile f(path);
    if(!f.exists()){
        instance->newProject("./", "test_project_define");
        instance->closeProject();
    }
    instance->openProject(path);
    QVERIFY(instance->projectName() == "test_project_define");
}

void TestCase::ProjectTest::testIsOpen()
{
    auto path = instance->fmtedProjectPath("./", "test_proj");
    QFile f(path);
    if(f.exists())
        f.remove();

    instance->newProject("./", "test_proj");
    QVERIFY(instance->isOpen());
    instance->closeProject();
    QVERIFY(!instance->isOpen());
}
