diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 31819d11f..d4e773601 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -1,172 +1,179 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) set(SRC_PATH ../umbrello) include_directories( ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} ${CMAKE_SOURCE_DIR} ${SRC_PATH} ${SRC_PATH}/debug/ ${SRC_PATH}/dialogs/ ${SRC_PATH}/dialogs/pages ${SRC_PATH}/dialogs/widgets ${SRC_PATH}/clipboard ${SRC_PATH}/cmds ${SRC_PATH}/codegenerators ${SRC_PATH}/codegenerators/ada/ ${SRC_PATH}/codegenerators/as/ ${SRC_PATH}/codegenerators/cpp/ ${SRC_PATH}/codegenerators/csharp/ ${SRC_PATH}/codegenerators/d/ ${SRC_PATH}/codegenerators/idl/ ${SRC_PATH}/codegenerators/java/ ${SRC_PATH}/codegenerators/js/ ${SRC_PATH}/codegenerators/pascal/ ${SRC_PATH}/codegenerators/perl/ ${SRC_PATH}/codegenerators/php/ ${SRC_PATH}/codegenerators/python/ ${SRC_PATH}/codegenerators/ruby/ ${SRC_PATH}/codegenerators/sql/ ${SRC_PATH}/codegenerators/tcl/ ${SRC_PATH}/codegenerators/vala/ ${SRC_PATH}/codegenerators/xml/ ${SRC_PATH}/codegenwizard ${SRC_PATH}/codeimport ${SRC_PATH}/debug ${SRC_PATH}/dialogs ${SRC_PATH}/docgenerators ${SRC_PATH}/menus/ ${SRC_PATH}/refactoring ${SRC_PATH}/uml1model/ ${SRC_PATH}/umlwidgets/ ${CMAKE_CURRENT_BINARY_DIR} ) if(NOT BUILD_KF5) set(LIBS Qt4::QtCore Qt4::QtGui Qt4::QtXml Qt4::QtTest Qt4::QtWebKit ${KDE4_KFILE_LIBS} ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} libumbrello ) else() set(LIBS Qt5::Xml Qt5::Test Qt5::Widgets Qt5::WebKitWidgets KF5::I18n KF5::Crash ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} libumbrello ) endif() ecm_add_test( testbasictypes.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testbasictypes ) ecm_add_test( testumlobject.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testumlobject ) ecm_add_test( testassociation.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testassociation ) ecm_add_test( testclassifier.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testclassifier ) ecm_add_test( testcppwriter.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testcppwriter ) ecm_add_test( testpythonwriter.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testpythonwriter ) ecm_add_test( testoptionstate.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testoptionstate ) +ecm_add_test( + testumlcanvasobject.cpp + testbase.cpp + LINK_LIBRARIES ${LIBS} + TEST_NAME testumlcanvasobject +) + set(testumlroledialog_SRCS testumlroledialog.cpp ) add_executable(testumlroledialog ${testumlroledialog_SRCS}) target_link_libraries(testumlroledialog ${LIBS}) add_executable(testcrashhandler testcrashhandler.cpp) target_link_libraries(testcrashhandler ${LIBS}) add_executable(testlistpopupmenu testlistpopupmenu.cpp testbase.cpp) target_link_libraries(testlistpopupmenu ${LIBS}) find_package(LLVM CONFIG) find_package(Clang CONFIG) if(NOT Clang_FOUND) find_package(CLANG QUIET) endif() if(LLVM_FOUND AND (Clang_FOUND OR CLANG_FOUND) AND LLVM_VERSION VERSION_LESS "8.0.0") message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") message(STATUS "Found CLANG ${CLANG_PACKAGE_VERSION}") include_directories(${LLVM_INCLUDE_DIRS}) add_definitions(${LLVM_DEFINITIONS}) include_directories(${CLANG_INCLUDE_DIRS}) add_definitions(${CLANG_DEFINITIONS}) # Now build our tools add_executable(testllvm testllvm.cpp) # Find the libraries that correspond to the LLVM components # that we wish to use if(LLVM_VERSION_MAJOR STREQUAL "7") set(llvm_libs LLVM) else() llvm_map_components_to_libnames(llvm_libs support core irreader analysis) endif() # Link against LLVM libraries target_link_libraries(testllvm ${llvm_libs} clangFrontend clangTooling clangBasic) add_executable(testllvmparser testllvmparser.cpp) if(NOT LLVM_VERSION_MAJOR STREQUAL "7") llvm_map_components_to_libnames(llvm_libs support) endif() target_link_libraries(testllvmparser ${llvm_libs} clangFrontend clangTooling clangAST clangBasic ${LIBS}) ecm_mark_nongui_executable(testllvm testllvmparser) endif() add_custom_target(check COMMAND ${CMAKE_BUILD_TOOL} test) diff --git a/unittests/testumlcanvasobject.cpp b/unittests/testumlcanvasobject.cpp new file mode 100644 index 000000000..2aed48424 --- /dev/null +++ b/unittests/testumlcanvasobject.cpp @@ -0,0 +1,172 @@ +/* + Copyright 2019 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 "testumlcanvasobject.h" + +// app include +#include "association.h" +#include "classifier.h" +#include "umlcanvasobject.h" + +//----------------------------------------------------------------------------- +void TestUMLCanvasObject::test_addAssociationEnd() +{ + UMLCanvasObject c1("Test A"); + UMLCanvasObject c2("Test B"); + UMLAssociation a(Uml::AssociationType::Generalization, &c1, &c2); + c1.addAssociationEnd(&a); + c2.addAssociationEnd(&a); + QCOMPARE(c1.associations(), 1); + QCOMPARE(c2.associations(), 1); + c1.addAssociationEnd(&a); + c2.addAssociationEnd(&a); + QCOMPARE(c1.associations(), 1); + QCOMPARE(c2.associations(), 1); +} + +void TestUMLCanvasObject::test_getAssociations() +{ + UMLCanvasObject c1("Test A"); + UMLCanvasObject c2("Test B"); + UMLAssociation a(Uml::AssociationType::Generalization, &c1, &c2); + c1.addAssociationEnd(&a); + c2.addAssociationEnd(&a); + QCOMPARE(c1.hasAssociation(&a), true); + QCOMPARE(c2.hasAssociation(&a), true); + c1.removeAssociationEnd(&a); + c2.removeAssociationEnd(&a); + QCOMPARE(c1.hasAssociation(&a), false); + QCOMPARE(c2.hasAssociation(&a), false); +} + +void TestUMLCanvasObject::test_removeAllAssociationEnds() +{ + UMLCanvasObject c1("Test A"); + UMLCanvasObject c2("Test B"); + UMLAssociation a(Uml::AssociationType::Generalization, &c1, &c2); + c1.addAssociationEnd(&a); + UMLAssociation b(Uml::AssociationType::Association, &c1, &c2); + c1.addAssociationEnd(&b); + QCOMPARE(c1.associations(), 2); + c1.removeAllAssociationEnds(); + QCOMPARE(c1.associations(), 0); +} + +void TestUMLCanvasObject::test_getSuperClasses() +{ + UMLCanvasObject o1("Test Sup o"); + UMLCanvasObject o2("Test Super o"); + UMLAssociation a1(Uml::AssociationType::Generalization, &o1, &o2); + o1.addAssociationEnd(&a1); + o2.addAssociationEnd(&a1); + QCOMPARE(o1.getSuperClasses(false).size(), 0); + QCOMPARE(o1.getSubClasses().size(), 0); + QCOMPARE(o2.getSuperClasses().size(), 0); + QCOMPARE(o2.getSubClasses().size(), 0); + + UMLClassifier c1("Test Sup c"); + UMLClassifier c2("Test Super c"); + UMLAssociation a2(Uml::AssociationType::Generalization, &c1, &c2); + c1.addAssociationEnd(&a2); + c2.addAssociationEnd(&a2); + QCOMPARE(c1.getSuperClasses(false).size(), 1); + QCOMPARE(c1.getSubClasses().size(), 0); + QCOMPARE(c2.getSuperClasses().size(), 0); + QCOMPARE(c2.getSubClasses().size(), 1); + + UMLAssociation a3(Uml::AssociationType::Realization, &c1, &c2); + c1.addAssociationEnd(&a3); + c2.addAssociationEnd(&a3); + QCOMPARE(c1.getSuperClasses(false).size(), 1); + QCOMPARE(c1.getSuperClasses(true).size(), 2); + QCOMPARE(c1.getSubClasses().size(), 0); + QCOMPARE(c2.getSuperClasses().size(), 0); + QCOMPARE(c2.getSubClasses().size(), 2); +} + +void TestUMLCanvasObject::test_getRealizations() +{ + UMLClassifier c1("Test A"); + UMLClassifier c2("Test B"); + UMLAssociation a1(Uml::AssociationType::Realization, &c1, &c2); + UMLAssociation a2(Uml::AssociationType::Association, &c1, &c2); + c1.addAssociationEnd(&a1); + c2.addAssociationEnd(&a1); + QCOMPARE(c1.getRealizations().size(), 1); + c1.addAssociationEnd(&a2); + c2.addAssociationEnd(&a2); + QCOMPARE(c1.getRealizations().size(), 1); + c1.removeAssociationEnd(&a2); + c2.removeAssociationEnd(&a2); + QCOMPARE(c1.getRealizations().size(), 1); +} + +void TestUMLCanvasObject::test_getAggregations() +{ + UMLClassifier c1("Test A"); + UMLClassifier c2("Test B"); + UMLAssociation a1(Uml::AssociationType::Aggregation, &c1, &c2); + c1.addAssociationEnd(&a1); + c2.addAssociationEnd(&a1); + QCOMPARE(c1.getAggregations().size(), 1); + UMLAssociation a2(Uml::AssociationType::Association, &c1, &c2); + c1.addAssociationEnd(&a2); + c2.addAssociationEnd(&a2); + QCOMPARE(c1.getAggregations().size(), 1); + c1.removeAssociationEnd(&a1); + c2.removeAssociationEnd(&a1); + QCOMPARE(c1.getAggregations().size(), 0); +} + +void TestUMLCanvasObject::test_getCompositions() +{ + UMLClassifier c1("Test A"); + UMLClassifier c2("Test B"); + UMLAssociation a1(Uml::AssociationType::Composition, &c1, &c2); + c1.addAssociationEnd(&a1); + c2.addAssociationEnd(&a1); + QCOMPARE(c1.getCompositions().size(), 1); + UMLAssociation a2(Uml::AssociationType::Association, &c1, &c2); + c1.addAssociationEnd(&a2); + c2.addAssociationEnd(&a2); + QCOMPARE(c1.getCompositions().size(), 1); + c1.removeAssociationEnd(&a1); + c2.removeAssociationEnd(&a1); + QCOMPARE(c1.getCompositions().size(), 0); +} + +void TestUMLCanvasObject::test_getRelationships() +{ + UMLClassifier c1("Test A"); + UMLClassifier c2("Test B"); + UMLAssociation a1(Uml::AssociationType::Relationship, &c1, &c2); + c1.addAssociationEnd(&a1); + c2.addAssociationEnd(&a1); + QCOMPARE(c1.getRelationships().size(), 1); + UMLAssociation a2(Uml::AssociationType::Association, &c1, &c2); + c1.addAssociationEnd(&a2); + c2.addAssociationEnd(&a2); + QCOMPARE(c1.getRelationships().size(), 1); + c1.removeAssociationEnd(&a1); + c2.removeAssociationEnd(&a1); + QCOMPARE(c1.getRelationships().size(), 0); +} + +QTEST_MAIN(TestUMLCanvasObject) diff --git a/unittests/testumlcanvasobject.h b/unittests/testumlcanvasobject.h new file mode 100644 index 000000000..c33a09778 --- /dev/null +++ b/unittests/testumlcanvasobject.h @@ -0,0 +1,43 @@ +/* + Copyright 2019 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 . +*/ + +#ifndef TEST_UMLCANVASOBJECT_H +#define TEST_UMLCANVASOBJECT_H + +#include "testbase.h" + +/** + * Unit test for class UMLCanvasObject + */ +class TestUMLCanvasObject: public TestBase +{ + Q_OBJECT +private slots: + void test_addAssociationEnd(); + void test_getAssociations(); + void test_removeAllAssociationEnds(); + void test_getSuperClasses(); + void test_getRealizations(); + void test_getAggregations(); + void test_getCompositions(); + void test_getRelationships(); +}; + +#endif // TEST_UMLCANVASOBJECT_H