diff --git a/unittests/testbase.cpp b/unittests/testbase.cpp index f2d764d29..9a67132f8 100644 --- a/unittests/testbase.cpp +++ b/unittests/testbase.cpp @@ -1,87 +1,88 @@ /* Copyright 2015 Ralf Habacker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "testbase.h" // app includes #include "codegenerationpolicy.h" #include "uml.h" // qt includes #include #if !defined(QT_GUI_LIB) #error umbrello unittests require QT_GUI_LIB to be present #endif #if QT_VERSION < 0x050000 #include #endif #if QT_VERSION >= 0x050000 #include #endif TestBase::TestBase(QObject *parent) : QObject(parent) { } void TestBase::initTestCase() { QWidget *w = new QWidget; - new UMLApp(w); + UMLApp *app = new UMLApp(w); + app->setActiveLanguage(Uml::ProgrammingLanguage::Cpp); } void TestBase::cleanupTestCase() { foreach(QObject *p, m_objectsToDelete) { delete p; } delete UMLApp::app(); } void TestBase::cleanupOnExit(QObject *p) { m_objectsToDelete.append(p); } void TestCodeGeneratorBase::initTestCase() { TestBase::initTestCase(); #if QT_VERSION >= 0x050000 static QTemporaryDir tmpDir; m_tempPath = tmpDir.path() + QLatin1String("/"); #else static KTempDir tmpDir; m_tempPath = tmpDir.name(); #endif UMLApp::app()->commonPolicy()->setOutputDirectory(m_tempPath); } /** * Return temporay path usable to generated code. * @return */ QString TestCodeGeneratorBase::temporaryPath() { return m_tempPath; } diff --git a/unittests/testclassifier.cpp b/unittests/testclassifier.cpp index b46ce30b6..e5a1728af 100644 --- a/unittests/testclassifier.cpp +++ b/unittests/testclassifier.cpp @@ -1,252 +1,318 @@ /* Copyright 2011 Andi Fischer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "testclassifier.h" // app include #include "uml.h" #include "classifier.h" +#include "datatype.h" +#include "operation.h" +#include "model_utils.h" #define IS_NOT_IMPL() QSKIP("not implemented yet", SkipSingle) //----------------------------------------------------------------------------- -//#define RUN_ALL #ifdef RUN_ALL #undef QCOMPARE #define QCOMPARE(actual, expected) \ QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__) +#undef QVERIFY +#define QVERIFY(statement) \ + QTest::qVerify((statement), #statement, "", __FILE__, __LINE__) #endif void TEST_classifier::test_equal() { UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None); UMLClassifier* b = a; UMLClassifier* c = new UMLClassifier("Test A", Uml::ID::None); UMLClassifier* d = new UMLClassifier("Test B", Uml::ID::None); QCOMPARE(*a == *b, true); QCOMPARE(*a == *c, true); QCOMPARE(*b == *c, true); QCOMPARE(*c == *d, false); } void TEST_classifier::test_copyInto() { UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None); UMLClassifier* b = new UMLClassifier("Test B", Uml::ID::None); b->copyInto(a); QCOMPARE(*a == *b, true); } void TEST_classifier::test_clone() { UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None); UMLClassifier* b = a->clone()->asUMLClassifier(); QCOMPARE(*a == *b, true); } void TEST_classifier::test_addAttributeWithType() { UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None); UMLAttribute* attrA = a->addAttribute("attributeA_", Uml::ID::None); /* UMLAttribute* attrB = */ a->addAttribute("attributeB_", Uml::ID::None); int num1 = a->getAttributeList().count(); QCOMPARE(num1, 2); int num2 = a->removeAttribute(attrA); QCOMPARE(num2, 1); // one deleted int num3 = a->getAttributeList().count(); QCOMPARE(num3, num1 - 1); } void TEST_classifier::test_addAttributeWithObject() { IS_NOT_IMPL(); } void TEST_classifier::test_addAttributeWithAttribute() { IS_NOT_IMPL(); } void TEST_classifier::test_removeAndCountAttribute() { UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None); int num0 = a->getAttributeList().count(); QCOMPARE(num0, 0); // no attributes present yet /*UMLAttribute* attrA = */ a->addAttribute("attributeA_", Uml::ID::None); UMLAttribute* attrB = a->addAttribute("attributeB_", Uml::ID::None); UMLAttribute* attrC = a->addAttribute("attributeC_", Uml::ID::None); /* UMLAttribute* attrD = */ a->addAttribute("attributeD_", Uml::ID::None); int num1 = a->getAttributeList().count(); QCOMPARE(num1, 4); int num2 = a->removeAttribute(attrB); QCOMPARE(num2, 3); // one deleted num2 = a->removeAttribute(attrC); QCOMPARE(num2, 2); // one deleted int num3 = a->getAttributeList().count(); QCOMPARE(num3, 2); } void TEST_classifier::test_getAttributeList() { IS_NOT_IMPL(); } void TEST_classifier::test_addOperationWithPosition() { IS_NOT_IMPL(); } void TEST_classifier::test_addOperationWithLog() { IS_NOT_IMPL(); } void TEST_classifier::test_checkOperationSignature() { IS_NOT_IMPL(); } void TEST_classifier::test_removeAndCountOperation() { IS_NOT_IMPL(); } void TEST_classifier::test_getOperationList() { IS_NOT_IMPL(); } void TEST_classifier::test_addTemplateWithType() { IS_NOT_IMPL(); } void TEST_classifier::test_addTemplateWithLog() { IS_NOT_IMPL(); } void TEST_classifier::test_addTemplateWithPosition() { IS_NOT_IMPL(); } void TEST_classifier::test_removeAndCountTemplate() { IS_NOT_IMPL(); } void TEST_classifier::test_findTemplate() { IS_NOT_IMPL(); } void TEST_classifier::test_getTemplateList() { IS_NOT_IMPL(); } void TEST_classifier::test_takeItem() { IS_NOT_IMPL(); } void TEST_classifier::test_getFilteredList() { IS_NOT_IMPL(); } void TEST_classifier::test_resolveRef() { qDebug() << "already tested by testumlobject"; } void TEST_classifier::test_findOperations() { - IS_NOT_IMPL(); + UMLClassifier c("Test A", Uml::ID::None); + UMLOperation o1(nullptr, "testop1"); + c.addOperation(&o1); + int num1 = c.getOpList().count(); + QCOMPARE(num1, 1); + UMLOperation o2(nullptr, "testop2"); + c.addOperation(&o2); + int num2 = c.getOpList().count(); + QCOMPARE(num2, 2); + QCOMPARE(c.findOperations("testop1").count(), 1); + QCOMPARE(c.findOperations("testop2").count(), 1); + QCOMPARE(c.findOperations("testOp1").count(), 0); + QCOMPARE(c.findOperations("testOp2").count(), 0); + // case insensitive language + Uml::ProgrammingLanguage::Enum lang = UMLApp::app()->activeLanguage(); + UMLApp::app()->setActiveLanguage(Uml::ProgrammingLanguage::PostgreSQL); + QCOMPARE(c.findOperations("testOp1").count(), 1); + QCOMPARE(c.findOperations("testOp2").count(), 1); + UMLApp::app()->setActiveLanguage(lang); } void TEST_classifier::test_findChildObjectById() { IS_NOT_IMPL(); } void TEST_classifier::test_findOperation() { - IS_NOT_IMPL(); + UMLClassifier c("Test A", Uml::ID::None); + UMLOperation o1(nullptr, "testop1"); + UMLAttribute a1(nullptr, "aParam"); + a1.setTypeName("int"); + o1.addParm(&a1); + c.addOperation(&o1); + UMLOperation o2(nullptr, "testop1"); + UMLAttribute a2(nullptr, "aParam"); + a2.setTypeName("double"); + o2.addParm(&a2); + c.addOperation(&o2); + Model_Utils::NameAndType_List searchTypes; + // first function + searchTypes << Model_Utils::NameAndType("aParam", a1.getType()); + UMLOperation *o = c.findOperation("testop1", searchTypes); + QVERIFY(o); + // second function + searchTypes.clear(); + searchTypes << Model_Utils::NameAndType("aParam", a2.getType()); + o = c.findOperation("testop1", searchTypes); + QVERIFY(o); + + // unknown type + UMLDatatype d1("someType"); + searchTypes.clear(); + searchTypes << Model_Utils::NameAndType("aParam", &d1); + o = c.findOperation("testop1", searchTypes); + QVERIFY(!o); + +#if 0 + // different param name + searchTypes.clear(); + searchTypes << Model_Utils::NameAndType("otherParam", a1.getType()); + o = c.findOperation("testop1", searchTypes); + QVERIFY(!o); + + // different param name + searchTypes.clear(); + searchTypes << Model_Utils::NameAndType("otherParam", a2.getType()); + o = c.findOperation("testop1", searchTypes); + QVERIFY(!o); +#else + qDebug() <<"finding param names is not supported"; +#endif } void TEST_classifier::test_findSuperClassConcepts() { IS_NOT_IMPL(); } void TEST_classifier::test_findSubClassConcepts() { IS_NOT_IMPL(); } void TEST_classifier::test_setGetClassAssoc() { IS_NOT_IMPL(); } void TEST_classifier::test_setBaseType() { qDebug() << "already tested by testumlobject"; } void TEST_classifier::test_isInterface() { IS_NOT_IMPL(); } void TEST_classifier::test_isDatatype() { IS_NOT_IMPL(); } void TEST_classifier::test_setGetOriginType() { IS_NOT_IMPL(); } void TEST_classifier::test_setGetIsReference() { IS_NOT_IMPL(); } void TEST_classifier::test_hasAbstractOps() { IS_NOT_IMPL(); } void TEST_classifier::test_makeChildObject() { IS_NOT_IMPL(); } void TEST_classifier::test_getUniAssociationToBeImplemented() { IS_NOT_IMPL(); } QTEST_MAIN(TEST_classifier)