Skip to content

Commit

Permalink
Fixed parsing the cpacs version
Browse files Browse the repository at this point in the history
Fixes #830
  • Loading branch information
rainman110 committed Nov 2, 2021
1 parent 95ead49 commit 8cbafe1
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/api/tigl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "CTiglAttachedRotorBlade.h"
#include "CGlobalExporterConfigs.h"
#include "Debugging.h"
#include "Version.h"

#include "CTiglPoint.h"

Expand Down Expand Up @@ -155,15 +156,17 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglOpenCPACSConfiguration(TixiDocumentHandle
}

/* check TIXI Version */
if ( atof(tixiGetVersion()) < 2.2 ) {
if ( Version(tixiGetVersion()) < Version("2.2") ) {
LOG(ERROR) << "Incompatible TIXI Version in use with this TIGL" << std::endl;
return TIGL_WRONG_TIXI_VERSION;
}


/* check CPACS Version */
{
double dcpacsVersion = 1.0;
ReturnCode tixiRet = tixiGetDoubleElement(tixiHandle, "/cpacs/header/cpacsVersion", &dcpacsVersion);
char* cpacsVersionStr = NULL;
ReturnCode tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/cpacsVersion", &cpacsVersionStr);

if (tixiRet != SUCCESS) {
// NO CPACS Version Information in Header
if (tixiRet == ELEMENT_PATH_NOT_UNIQUE) {
Expand All @@ -177,15 +180,23 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglOpenCPACSConfiguration(TixiDocumentHandle
}
return TIGL_WRONG_CPACS_VERSION;
}
else {
if (dcpacsVersion < (double) TIGL_MAJOR_VERSION) {

try {
const auto cpacsVersion = Version(cpacsVersionStr);

if (cpacsVersion.vMajor() < TIGL_MAJOR_VERSION) {
LOG(ERROR) << "Too old CPACS dataset. CPACS version has to be at least " << (double) TIGL_MAJOR_VERSION << "!";
return TIGL_WRONG_CPACS_VERSION;
}
else if (dcpacsVersion > atof(tiglGetVersion())) {
else if (cpacsVersion > Version(tiglGetVersion())) {
LOG(WARNING) << "CPACS dataset version is higher than TIGL library version!";
}
}
catch (const std::invalid_argument& err) {
LOG(ERROR) << "Cannot read CPACS Version: " << err.what();
return TIGL_WRONG_CPACS_VERSION;
}

}

/* check if there is only one configuration in the data set. Then we open this */
Expand Down
17 changes: 17 additions & 0 deletions tests/unittests/TestData/testversion_good.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<cpacs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://cpacs.googlecode.com/files/CPACS_21_Schema.xsd">
<header>
<name>Cpacs2Test</name>
<description>Test file to check versioning</description>
<creator>Martin Siggel</creator>
<timestamp>2021-11-02T15:12:00</timestamp>
<version>1.0.0</version>
<cpacsVersion>3.2.1</cpacsVersion>
</header>
<vehicles>
<aircraft>
<model uID="LoggingTestModel"/>
</aircraft>
</vehicles>

</cpacs>
16 changes: 16 additions & 0 deletions tests/unittests/TestData/testversion_no_cpacs_version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<cpacs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://cpacs.googlecode.com/files/CPACS_21_Schema.xsd">
<header>
<name>Cpacs2Test</name>
<description>Test file to check versioning</description>
<creator>Martin Siggel</creator>
<timestamp>2021-11-02T15:12:00</timestamp>
<version>1.0.0</version>
</header>
<vehicles>
<aircraft>
<model uID="LoggingTestModel"/>
</aircraft>
</vehicles>

</cpacs>
17 changes: 17 additions & 0 deletions tests/unittests/TestData/testversion_too_old.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<cpacs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://cpacs.googlecode.com/files/CPACS_21_Schema.xsd">
<header>
<name>Cpacs2Test</name>
<description>Test file to check versioning</description>
<creator>Martin Siggel</creator>
<timestamp>2021-11-02T15:12:00</timestamp>
<version>1.0.0</version>
<cpacsVersion>2.1.3</cpacsVersion>
</header>
<vehicles>
<aircraft>
<model uID="LoggingTestModel"/>
</aircraft>
</vehicles>

</cpacs>
62 changes: 62 additions & 0 deletions tests/unittests/testCpacsVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2021 German Aerospace Center (DLR/SC)
*
* Created: 2021-11-02 Martin Siggel <Martin.Siggel@dlr.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "test.h"

#include "tigl.h"


TEST(CPACSVersion, success1)
{
TixiHandleWrapper tixihandle("TestData/testversion_good.xml");

TiglCPACSConfigurationHandle tiglHandle = -1;
EXPECT_EQ(TIGL_SUCCESS, tiglOpenCPACSConfiguration(tixihandle, "", &tiglHandle));

tiglCloseCPACSConfiguration(tiglHandle);
}

TEST(CPACSVersion, success2)
{
TixiHandleWrapper tixihandle("TestData/simpletest.cpacs.xml");

TiglCPACSConfigurationHandle tiglHandle = -1;
EXPECT_EQ(TIGL_SUCCESS, tiglOpenCPACSConfiguration(tixihandle, "", &tiglHandle));

tiglCloseCPACSConfiguration(tiglHandle);
}

TEST(CPACSVersion, versionTooOld)
{
TixiHandleWrapper tixihandle("TestData/testversion_too_old.xml");

TiglCPACSConfigurationHandle tiglHandle = -1;
EXPECT_EQ(TIGL_WRONG_CPACS_VERSION, tiglOpenCPACSConfiguration(tixihandle, "", &tiglHandle));

tiglCloseCPACSConfiguration(tiglHandle);
}

TEST(CPACSVersion, noCPACSVersion)
{
TixiHandleWrapper tixihandle("TestData/testversion_no_cpacs_version.xml");

TiglCPACSConfigurationHandle tiglHandle = -1;
EXPECT_EQ(TIGL_WRONG_CPACS_VERSION, tiglOpenCPACSConfiguration(tixihandle, "", &tiglHandle));

tiglCloseCPACSConfiguration(tiglHandle);
}

0 comments on commit 8cbafe1

Please sign in to comment.