Skip to content

Commit

Permalink
Test the model instance json (#9660)
Browse files Browse the repository at this point in the history
Create a static lib of Util instead of compiling it for each test
  • Loading branch information
adeas31 committed Nov 4, 2022
1 parent 4d44447 commit 64229a6
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 31 deletions.
7 changes: 3 additions & 4 deletions OMEdit/Testsuite/BrowseMSL/BrowseMSL.pro
Expand Up @@ -29,11 +29,10 @@
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = BrowseMSL

SOURCES += ../Common/Util.cpp \
BrowseMSL.cpp
SOURCES += BrowseMSL.cpp

HEADERS += ../Common/Util.h \
BrowseMSL.h
HEADERS += BrowseMSL.h
16 changes: 8 additions & 8 deletions OMEdit/Testsuite/Common/Testsuite.pri
Expand Up @@ -35,20 +35,20 @@ greaterThan(QT_MAJOR_VERSION, 4) {
CONFIG += qtestlib
}

LIBS += -L../../bin -lOMEdit

OMEDIT_ROOT = ../../

LIBS += -L$$OMEDIT_ROOT/bin -lOMEdit

# Windows libraries and includes
win32 {
include(../../OMEditGUI/OMEditGUI.win.config.pri)
include($$OMEDIT_ROOT/OMEditGUI/OMEditGUI.win.config.pri)
} else { # Unix libraries and includes
include(../../OMEditGUI/OMEditGUI.unix.config.pri)
include($$OMEDIT_ROOT/OMEditGUI/OMEditGUI.unix.config.pri)
}

INCLUDEPATH += ../../ \
../../OMEditLIB \
../Common \
INCLUDEPATH += $$OMEDIT_ROOT \
$$OMEDIT_ROOT/OMEditLIB \
../Util \
$$OPENMODELICAHOME/include \
$$OPENMODELICAHOME/include/omplot \
$$OPENMODELICAHOME/include/omplot/qwt \
Expand All @@ -61,7 +61,7 @@ for(path, INCLUDEPATH) {
QMAKE_CXXFLAGS += -isystem $${path}
}

DESTDIR = ../../bin/tests
DESTDIR = $$OMEDIT_ROOT/bin/tests

MOC_DIR = generatedfiles/moc

31 changes: 31 additions & 0 deletions OMEdit/Testsuite/Common/Util.pri
@@ -0,0 +1,31 @@
#
# This file is part of OpenModelica.
#
# Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
# c/o Linköpings universitet, Department of Computer and Information Science,
# SE-58183 Linköping, Sweden.
#
# All rights reserved.
#
# THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
# THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
# ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
# OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
#
# The OpenModelica software and the Open Source Modelica
# Consortium (OSMC) Public License (OSMC-PL) are obtained
# from OSMC, either from the above address,
# from the URLs: http://www.ida.liu.se/projects/OpenModelica or
# http://www.openmodelica.org, and in the OpenModelica distribution.
# GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
#
# This program is distributed WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
# IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
#
# See the full OSMC Public License conditions for more details.
#
#/

LIBS += -L../../bin/tests -lUtil
7 changes: 3 additions & 4 deletions OMEdit/Testsuite/Diagram/Diagram.pro
Expand Up @@ -29,11 +29,10 @@
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = Diagram

SOURCES += ../Common/Util.cpp \
Diagram.cpp
SOURCES += Diagram.cpp

HEADERS += ../Common/Util.h \
Diagram.h
HEADERS += Diagram.h
7 changes: 3 additions & 4 deletions OMEdit/Testsuite/Expression/Expression.pro
Expand Up @@ -29,11 +29,10 @@
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = Expression

SOURCES += ../Common/Util.cpp \
ExpressionTest.cpp
SOURCES += ExpressionTest.cpp

HEADERS += ../Common/Util.h \
ExpressionTest.h
HEADERS += ExpressionTest.h
7 changes: 3 additions & 4 deletions OMEdit/Testsuite/Homotopy/Homotopy.pro
Expand Up @@ -29,11 +29,10 @@
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = Homotopy

SOURCES += ../Common/Util.cpp \
HomotopyTest.cpp
SOURCES += HomotopyTest.cpp

HEADERS += ../Common/Util.h \
HomotopyTest.h
HEADERS += HomotopyTest.h
38 changes: 38 additions & 0 deletions OMEdit/Testsuite/ModelInstance/ModelInstance.pro
@@ -0,0 +1,38 @@
#
# This file is part of OpenModelica.
#
# Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
# c/o Linköpings universitet, Department of Computer and Information Science,
# SE-58183 Linköping, Sweden.
#
# All rights reserved.
#
# THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
# THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
# ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
# OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
#
# The OpenModelica software and the Open Source Modelica
# Consortium (OSMC) Public License (OSMC-PL) are obtained
# from OSMC, either from the above address,
# from the URLs: http://www.ida.liu.se/projects/OpenModelica or
# http://www.openmodelica.org, and in the OpenModelica distribution.
# GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
#
# This program is distributed WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
# IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
#
# See the full OSMC Public License conditions for more details.
#
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = ModelInstance

SOURCES += ModelInstanceTest.cpp

HEADERS += ModelInstanceTest.h
96 changes: 96 additions & 0 deletions OMEdit/Testsuite/ModelInstance/ModelInstanceTest.cpp
@@ -0,0 +1,96 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#include "ModelInstanceTest.h"
#include "Util.h"
#include "OMEditApplication.h"
#include "MainWindow.h"
#include "Modeling/LibraryTreeWidget.h"

#define GC_THREADS
extern "C" {
#include "meta/meta_modelica.h"
}

OMEDITTEST_MAIN(ModelInstanceTest)

void ModelInstanceTest::initTestCase()
{
MainWindow::instance()->getLibraryWidget()->openFile(QFINDTESTDATA(mFileName));
if (!MainWindow::instance()->getOMCProxy()->existClass(mPackageName)) {
QFAIL(QString("Failed to load file %1").arg(mFileName).toStdString().c_str());
}

mpModelInstance = new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(mModelName));
}

void ModelInstanceTest::classAnnotations()
{
if (mpModelInstance->getIconAnnotation()->getGraphics().isEmpty()) {
QFAIL("Failed to read the class icon annotation.");
}

if (mpModelInstance->getDiagramAnnotation()->getGraphics().isEmpty()) {
QFAIL("Failed to read the class diagram annotation.");
}
}

void ModelInstanceTest::classComponents()
{
if (mpModelInstance->getElements().isEmpty()) {
QFAIL("Failed to read the class components.");
}
}

void ModelInstanceTest::classConnections()
{
if (mpModelInstance->getConnections().isEmpty()) {
QFAIL("Failed to read the class connections.");
}
}

void ModelInstanceTest::classExtends()
{
if (mpModelInstance->getExtends().isEmpty()) {
QFAIL("Failed to read the class extends.");
}
}

void ModelInstanceTest::cleanupTestCase()
{
if (mpModelInstance) {
delete mpModelInstance;
}
MainWindow::instance()->close();
}
75 changes: 75 additions & 0 deletions OMEdit/Testsuite/ModelInstance/ModelInstanceTest.h
@@ -0,0 +1,75 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#ifndef DIAGRAM_H
#define DIAGRAM_H

#include <QObject>

#include "Modeling/Model.h"

/*!
* \brief The ModelInstanceTest class
* Tests the Model class.
*/
class ModelInstanceTest: public QObject
{
Q_OBJECT
private:
const QString mFileName = "ModelInstanceTest.mo";
const QString mPackageName = "P";
const QString mModelName = "P.M";
ModelInstance::Model *mpModelInstance = 0;
private slots:
void initTestCase();
/*!
* \brief classAnnotations
* Tests the class annotations like icon, diagram etc.
*/
void classAnnotations();
/*!
* \brief classComponents
* Tests the class components.
*/
void classComponents();
/*!
* \brief classConnections
* Tests the class connections.
*/
void classConnections();
void classExtends();
void cleanupTestCase();
};

#endif // DIAGRAM_H
24 changes: 24 additions & 0 deletions OMEdit/Testsuite/ModelInstance/ModelInstanceTest.mo
@@ -0,0 +1,24 @@
package P
connector C
Real e;
flow Real f;
end C;

model A
C c1, c2;
equation
connect(c1, c2);
end A;

model M
extends A;

C c3;
equation
connect(c1, c3) annotation(Line(points = {{-25, 30}, {10, 30}, {10, -20}, {40, -20}}));

annotation (
Icon(graphics={Rectangle(extent={{-66,78},{70,-56}}, lineColor={28,108,200})}),
Diagram(graphics={Ellipse(extent={{-62,68},{56,-60}}, lineColor={28,108,200})}));
end M;
end P;
2 changes: 1 addition & 1 deletion OMEdit/Testsuite/RunOMEditTestsuite.sh
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

testcases=( "BrowseMSL" "Diagram" "Transformation" "Homotopy" "Expression" )
testcases=( "BrowseMSL" "Diagram" "Transformation" "Homotopy" "Expression" "ModelInstance" )
OMEditTestResults="$PWD/OMEditTestResult"

for i in "${testcases[@]}"
Expand Down
12 changes: 10 additions & 2 deletions OMEdit/Testsuite/Testsuite.pro
Expand Up @@ -30,9 +30,17 @@

TEMPLATE = subdirs

SUBDIRS = BrowseMSL \
SUBDIRS = Util \
BrowseMSL \
Diagram \
Transformation \
Homotopy \
Expression
Expression \
ModelInstance

BrowseMSL.depends = Util
Diagram.depends = Util
Transformation.depends = Util
Homotopy.depends = Util
Expression.depends = Util
ModelInstance.depends = Util

0 comments on commit 64229a6

Please sign in to comment.