From 6ee987947ce4bcbc8974cfe6f18e20a6f49a48f1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 17 Oct 2015 11:32:54 +0300 Subject: [PATCH] Tests that helps to check that all current pattern making systems match pattern inside XSD scheme. --HG-- branch : develop --- src/libs/vmisc/def.cpp | 127 +++++++++++-------- src/libs/vmisc/def.h | 1 + src/test/ValentinaTest/tst_vmeasurements.cpp | 98 ++++++++++++++ src/test/ValentinaTest/tst_vmeasurements.h | 2 + 4 files changed, 172 insertions(+), 56 deletions(-) diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index f61e9ee78..3915fe14a 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -972,68 +972,19 @@ QStringList AllGroupNames() //--------------------------------------------------------------------------------------------------------------------- void InitPMSystems(QComboBox *systemCombo) { + const QStringList listSystems = ListPMSystems(); QMap systems; - systems.insert(qApp->TrVars()->PMSystemName(p0_S), p0_S); - systems.insert(qApp->TrVars()->PMSystemName(p1_S), p1_S); - systems.insert(qApp->TrVars()->PMSystemName(p2_S), p2_S); - systems.insert(qApp->TrVars()->PMSystemName(p3_S), p3_S); - systems.insert(qApp->TrVars()->PMSystemName(p4_S), p4_S); - systems.insert(qApp->TrVars()->PMSystemName(p5_S), p5_S); - systems.insert(qApp->TrVars()->PMSystemName(p6_S), p6_S); - systems.insert(qApp->TrVars()->PMSystemName(p7_S), p7_S); - systems.insert(qApp->TrVars()->PMSystemName(p8_S), p8_S); - systems.insert(qApp->TrVars()->PMSystemName(p9_S), p9_S); - systems.insert(qApp->TrVars()->PMSystemName(p10_S), p10_S); - systems.insert(qApp->TrVars()->PMSystemName(p11_S), p11_S); - systems.insert(qApp->TrVars()->PMSystemName(p12_S), p12_S); - systems.insert(qApp->TrVars()->PMSystemName(p13_S), p13_S); - systems.insert(qApp->TrVars()->PMSystemName(p14_S), p14_S); - systems.insert(qApp->TrVars()->PMSystemName(p15_S), p15_S); - systems.insert(qApp->TrVars()->PMSystemName(p16_S), p16_S); - systems.insert(qApp->TrVars()->PMSystemName(p17_S), p17_S); - systems.insert(qApp->TrVars()->PMSystemName(p18_S), p18_S); - systems.insert(qApp->TrVars()->PMSystemName(p19_S), p19_S); - systems.insert(qApp->TrVars()->PMSystemName(p20_S), p20_S); - systems.insert(qApp->TrVars()->PMSystemName(p21_S), p21_S); - systems.insert(qApp->TrVars()->PMSystemName(p22_S), p22_S); - systems.insert(qApp->TrVars()->PMSystemName(p23_S), p23_S); - systems.insert(qApp->TrVars()->PMSystemName(p24_S), p24_S); - systems.insert(qApp->TrVars()->PMSystemName(p25_S), p25_S); - systems.insert(qApp->TrVars()->PMSystemName(p26_S), p26_S); - systems.insert(qApp->TrVars()->PMSystemName(p27_S), p27_S); - systems.insert(qApp->TrVars()->PMSystemName(p28_S), p28_S); - systems.insert(qApp->TrVars()->PMSystemName(p29_S), p29_S); - systems.insert(qApp->TrVars()->PMSystemName(p30_S), p30_S); - systems.insert(qApp->TrVars()->PMSystemName(p31_S), p31_S); - systems.insert(qApp->TrVars()->PMSystemName(p32_S), p32_S); - systems.insert(qApp->TrVars()->PMSystemName(p33_S), p33_S); - systems.insert(qApp->TrVars()->PMSystemName(p34_S), p34_S); - systems.insert(qApp->TrVars()->PMSystemName(p35_S), p35_S); - systems.insert(qApp->TrVars()->PMSystemName(p36_S), p36_S); - systems.insert(qApp->TrVars()->PMSystemName(p37_S), p37_S); - systems.insert(qApp->TrVars()->PMSystemName(p38_S), p38_S); - systems.insert(qApp->TrVars()->PMSystemName(p39_S), p39_S); - systems.insert(qApp->TrVars()->PMSystemName(p40_S), p40_S); - systems.insert(qApp->TrVars()->PMSystemName(p41_S), p41_S); - systems.insert(qApp->TrVars()->PMSystemName(p42_S), p42_S); - systems.insert(qApp->TrVars()->PMSystemName(p43_S), p43_S); - systems.insert(qApp->TrVars()->PMSystemName(p44_S), p44_S); - systems.insert(qApp->TrVars()->PMSystemName(p45_S), p45_S); - systems.insert(qApp->TrVars()->PMSystemName(p46_S), p46_S); - systems.insert(qApp->TrVars()->PMSystemName(p47_S), p47_S); - systems.insert(qApp->TrVars()->PMSystemName(p48_S), p48_S); - systems.insert(qApp->TrVars()->PMSystemName(p49_S), p49_S); - systems.insert(qApp->TrVars()->PMSystemName(p50_S), p50_S); - systems.insert(qApp->TrVars()->PMSystemName(p51_S), p51_S); - systems.insert(qApp->TrVars()->PMSystemName(p52_S), p52_S); - systems.insert(qApp->TrVars()->PMSystemName(p53_S), p53_S); - systems.insert(qApp->TrVars()->PMSystemName(p54_S), p54_S); + for (int i = 0; i < listSystems.size()-1; ++i) + { + systems.insert(qApp->TrVars()->PMSystemName(listSystems.at(i)), listSystems.at(i)); + } // * The default option (blank field or 'None') should appear at the top of the list. // * The list should be sorted alphabetically so users can find their system easily. SCASSERT(systemCombo != nullptr); - systemCombo->addItem(qApp->TrVars()->PMSystemName(p998_S), p998_S); + systemCombo->addItem(qApp->TrVars()->PMSystemName(listSystems.at(listSystems.size()-1)), + listSystems.at(listSystems.size()-1)); QMap::const_iterator i = systems.constBegin(); while (i != systems.constEnd()) @@ -1042,3 +993,67 @@ void InitPMSystems(QComboBox *systemCombo) ++i; } } + +//--------------------------------------------------------------------------------------------------------------------- +QStringList ListPMSystems() +{ + QStringList list; + list << p0_S + << p1_S + << p2_S + << p3_S + << p4_S + << p5_S + << p6_S + << p7_S + << p8_S + << p9_S + << p10_S + << p11_S + << p12_S + << p13_S + << p14_S + << p15_S + << p16_S + << p17_S + << p18_S + << p19_S + << p20_S + << p21_S + << p22_S + << p23_S + << p24_S + << p25_S + << p26_S + << p27_S + << p28_S + << p29_S + << p30_S + << p31_S + << p32_S + << p33_S + << p34_S + << p35_S + << p36_S + << p37_S + << p38_S + << p39_S + << p40_S + << p41_S + << p42_S + << p43_S + << p44_S + << p45_S + << p46_S + << p47_S + << p48_S + << p49_S + << p50_S + << p51_S + << p52_S + << p53_S + << p54_S + << p998_S; + + return list; +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index e2b030f69..66bca2317 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -519,6 +519,7 @@ extern const QString p53_S; extern const QString p54_S; extern const QString p998_S; +QStringList ListPMSystems(); void InitPMSystems(QComboBox *systemCombo); // functions diff --git a/src/test/ValentinaTest/tst_vmeasurements.cpp b/src/test/ValentinaTest/tst_vmeasurements.cpp index f6fc00b62..bb986c8a3 100644 --- a/src/test/ValentinaTest/tst_vmeasurements.cpp +++ b/src/test/ValentinaTest/tst_vmeasurements.cpp @@ -114,3 +114,101 @@ void TST_VMeasurements::CreateEmptyIndividualFile() QFAIL(e.ErrorMessage().toUtf8().constData()); } } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ValidPMCodesStandardFile helps to check that all current pattern making systems match pattern inside XSD + * scheme. + */ +void TST_VMeasurements::ValidPMCodesStandardFile() +{ + Unit mUnit = Unit::Cm; + const int height = 176; + const int size = 50; + + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + data->SetHeight(height); + data->SetSize(size); + + QSharedPointer m = + QSharedPointer(new VMeasurements(mUnit, size, height, data.data())); + + const QStringList listSystems = ListPMSystems(); + for (int i = 0; i < listSystems.size(); ++i) + { + QString code = listSystems.at(i); + code.remove(0, 1); // remove 'p' + m->SetPMSystem(code); + + QTemporaryFile file; + if (file.open()) + { + QString error; + const bool result = m->SaveDocument(file.fileName(), error); + + const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i)); + QVERIFY2(result, qUtf8Printable(message)); + } + else + { + QFAIL("Can't open temporary file."); + } + + try + { + VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, file.fileName()); + } + catch (VException &e) + { + const QString message = QString("Error: %1 for code=%2").arg(e.ErrorMessage()).arg(listSystems.at(i)); + QFAIL(qUtf8Printable(message)); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ValidPMCodesIndividualFile helps to check that all current pattern making systems match pattern inside XSD + * scheme. + */ +void TST_VMeasurements::ValidPMCodesIndividualFile() +{ + Unit mUnit = Unit::Cm; + + QSharedPointer data = QSharedPointer(new VContainer(nullptr, &mUnit)); + + QSharedPointer m = + QSharedPointer(new VMeasurements(mUnit, data.data())); + + const QStringList listSystems = ListPMSystems(); + for (int i = 0; i < listSystems.size(); ++i) + { + QString code = listSystems.at(i); + code.remove(0, 1); // remove 'p' + m->SetPMSystem(code); + + QTemporaryFile file; + if (file.open()) + { + QString error; + const bool result = m->SaveDocument(file.fileName(), error); + + const QString message = QString("Error: %1 for code=%2").arg(error).arg(listSystems.at(i)); + QVERIFY2(result, qUtf8Printable(message)); + } + else + { + QFAIL("Can't open temporary file."); + } + + try + { + VDomDocument::ValidateXML(VVITConverter::CurrentSchema, file.fileName()); + } + catch (VException &e) + { + const QString message = QString("Error: %1 for code=%2").arg(e.ErrorMessage()).arg(listSystems.at(i)); + QFAIL(qUtf8Printable(message)); + } + } +} diff --git a/src/test/ValentinaTest/tst_vmeasurements.h b/src/test/ValentinaTest/tst_vmeasurements.h index bbf482fe9..a12432d70 100644 --- a/src/test/ValentinaTest/tst_vmeasurements.h +++ b/src/test/ValentinaTest/tst_vmeasurements.h @@ -41,6 +41,8 @@ private slots: void CreateEmptyStandardFile(); void CreateEmptyIndividualFile(); + void ValidPMCodesStandardFile(); + void ValidPMCodesIndividualFile(); }; #endif // TST_VMEASUREMENTS_H