Fixed TST_VMeasurements tests in Windows.

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2016-06-01 20:14:42 +03:00
parent 8c5f14937d
commit bcdedaf659

View File

@ -57,10 +57,17 @@ void TST_VMeasurements::CreateEmptyStandardFile()
QSharedPointer<VMeasurements>(new VMeasurements(mUnit, size, height, data.data())); QSharedPointer<VMeasurements>(new VMeasurements(mUnit, size, height, data.data()));
QTemporaryFile file; QTemporaryFile file;
QString fileName;
// In Windows we have problems when we try to open QSaveFile when QTemporaryFile with the same name is already open.
if (file.open()) if (file.open())
{ {
// So, before we try to open file in m->SaveDocument function we need to close it and remove.
// Just closing - is not enough, if we just close QTemporaryFile we get "access denied" in Windows.
fileName = file.fileName();
file.close();
file.remove();
QString error; QString error;
const bool result = m->SaveDocument(file.fileName(), error); const bool result = m->SaveDocument(fileName, error);
QVERIFY2(result, error.toUtf8().constData()); QVERIFY2(result, error.toUtf8().constData());
} }
@ -71,7 +78,7 @@ void TST_VMeasurements::CreateEmptyStandardFile()
try try
{ {
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, file.fileName()); VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, fileName);
} }
catch (VException &e) catch (VException &e)
{ {
@ -93,10 +100,14 @@ void TST_VMeasurements::CreateEmptyIndividualFile()
QSharedPointer<VMeasurements>(new VMeasurements(mUnit, data.data())); QSharedPointer<VMeasurements>(new VMeasurements(mUnit, data.data()));
QTemporaryFile file; QTemporaryFile file;
QString fileName;
if (file.open()) if (file.open())
{ {
fileName = file.fileName();
file.close();
file.remove();
QString error; QString error;
const bool result = m->SaveDocument(file.fileName(), error); const bool result = m->SaveDocument(fileName, error);
QVERIFY2(result, error.toUtf8().constData()); QVERIFY2(result, error.toUtf8().constData());
} }
@ -107,7 +118,7 @@ void TST_VMeasurements::CreateEmptyIndividualFile()
try try
{ {
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, file.fileName()); VDomDocument::ValidateXML(VVITConverter::CurrentSchema, fileName);
} }
catch (VException &e) catch (VException &e)
{ {
@ -141,10 +152,14 @@ void TST_VMeasurements::ValidPMCodesStandardFile()
m->SetPMSystem(code); m->SetPMSystem(code);
QTemporaryFile file; QTemporaryFile file;
QString fileName;
if (file.open()) if (file.open())
{ {
fileName = file.fileName();
file.close();
file.remove();
QString error; QString error;
const bool result = m->SaveDocument(file.fileName(), error); const bool result = m->SaveDocument(fileName, error);
const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i)); const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i));
QVERIFY2(result, qUtf8Printable(message)); QVERIFY2(result, qUtf8Printable(message));
@ -156,7 +171,7 @@ void TST_VMeasurements::ValidPMCodesStandardFile()
try try
{ {
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, file.fileName()); VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, fileName);
} }
catch (VException &e) catch (VException &e)
{ {
@ -188,10 +203,14 @@ void TST_VMeasurements::ValidPMCodesIndividualFile()
m->SetPMSystem(code); m->SetPMSystem(code);
QTemporaryFile file; QTemporaryFile file;
QString fileName;
if (file.open()) if (file.open())
{ {
fileName = file.fileName();
file.close();
file.remove();
QString error; QString error;
const bool result = m->SaveDocument(file.fileName(), error); const bool result = m->SaveDocument(fileName, error);
const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i)); const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i));
QVERIFY2(result, qUtf8Printable(message)); QVERIFY2(result, qUtf8Printable(message));
@ -203,7 +222,7 @@ void TST_VMeasurements::ValidPMCodesIndividualFile()
try try
{ {
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, file.fileName()); VDomDocument::ValidateXML(VVITConverter::CurrentSchema, fileName);
} }
catch (VException &e) catch (VException &e)
{ {