mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2310 Add helper files and unit test for project file version queries
This commit is contained in:
parent
24aca6edc3
commit
e7c8667b24
@ -23,6 +23,7 @@ ${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaStdStringTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaSummaryCurveAnalyzer.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaSimWellBranchTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaProjectFileVersionTools.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@ -43,6 +44,7 @@ ${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaStdStringTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaSummaryCurveAnalyzer.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaSimWellBranchTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaProjectFileVersionTools.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
100
ApplicationCode/Application/Tools/RiaProjectFileVersionTools.cpp
Normal file
100
ApplicationCode/Application/Tools/RiaProjectFileVersionTools.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaProjectFileVersionTools.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectFileVersionTools::isProjectFileVersionNewerThan(const QString& projectFileVersion,
|
||||
const RiaProjectFileVersionData& fileVersionData)
|
||||
{
|
||||
return isProjectFileVersionNewerThan(projectFileVersion, fileVersionData.m_majorVersion, fileVersionData.m_minorVersion,
|
||||
fileVersionData.m_patch, fileVersionData.m_developmentId);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaProjectFileVersionTools::isProjectFileVersionNewerThan(const QString& projectFileVersion, int majorVersion,
|
||||
int minorVersion, int patchNumber, int developmentId)
|
||||
{
|
||||
int projectMajorVersion = 0;
|
||||
int projectMinorVersion = 0;
|
||||
int projectPatchNumber = 0;
|
||||
int projectDevelopmentId = 0;
|
||||
|
||||
// Split string and interpret sub strings
|
||||
{
|
||||
QStringList subStrings = projectFileVersion.split(".");
|
||||
|
||||
if (subStrings.size() > 0)
|
||||
{
|
||||
projectMajorVersion = subStrings[0].toInt();
|
||||
}
|
||||
|
||||
if (subStrings.size() > 1)
|
||||
{
|
||||
projectMinorVersion = subStrings[1].toInt();
|
||||
}
|
||||
|
||||
if (subStrings.size() > 2)
|
||||
{
|
||||
projectPatchNumber = subStrings[2].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
if (projectMajorVersion != majorVersion)
|
||||
{
|
||||
return (projectMajorVersion > majorVersion);
|
||||
}
|
||||
|
||||
if (projectMinorVersion != minorVersion)
|
||||
{
|
||||
return (projectMinorVersion > minorVersion);
|
||||
}
|
||||
|
||||
if (projectPatchNumber != patchNumber)
|
||||
{
|
||||
return (projectPatchNumber > patchNumber);
|
||||
}
|
||||
|
||||
if (projectDevelopmentId != developmentId)
|
||||
{
|
||||
return (projectDevelopmentId > developmentId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaProjectFileVersionTools::knownProjectVersionStrings()
|
||||
{
|
||||
QStringList versionStrings;
|
||||
|
||||
versionStrings << "2017.05.2-dev.15";
|
||||
versionStrings << "2017.05.2-dev.14";
|
||||
versionStrings << "2017.05.2-dev.13";
|
||||
versionStrings << "2017.05.2-dev.12";
|
||||
|
||||
return versionStrings;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
struct RiaProjectFileVersionData
|
||||
{
|
||||
int m_majorVersion;
|
||||
int m_minorVersion;
|
||||
int m_patch;
|
||||
int m_developmentId;
|
||||
|
||||
RiaProjectFileVersionData() : m_majorVersion(0), m_minorVersion(0), m_patch(0), m_developmentId(0) {}
|
||||
|
||||
RiaProjectFileVersionData(int majorVersion, int minorVersion, int patch, int developmentId)
|
||||
: m_majorVersion(majorVersion), m_minorVersion(minorVersion), m_patch(patch), m_developmentId(developmentId)
|
||||
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaProjectFileVersionTools
|
||||
{
|
||||
public:
|
||||
static bool isProjectFileVersionNewerThan(const QString& projectFileVersion,
|
||||
const RiaProjectFileVersionData& fileVersionData);
|
||||
|
||||
private:
|
||||
static bool isProjectFileVersionNewerThan(const QString& projectFileVersion, int majorVersion, int minorVersion, int patch,
|
||||
int developmentId);
|
||||
|
||||
static QStringList knownProjectVersionStrings();
|
||||
};
|
@ -35,6 +35,7 @@ ${CEE_CURRENT_LIST_DIR}RiuSummaryVectorDescriptionMap-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}FixedWidthDataParser-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigTimeCurveHistoryMerger-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}ListKeywordsForObjectsAndFields-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaProjectFileVersionTools-Test.cpp
|
||||
)
|
||||
|
||||
if (RESINSIGHT_ENABLE_PROTOTYPE_FEATURE_FRACTURES)
|
||||
|
@ -0,0 +1,30 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaProjectFileVersionTools, BasicUsage)
|
||||
{
|
||||
/*
|
||||
std::vector<double> a(10);
|
||||
std::iota(a.begin(), a.end(), 10);
|
||||
|
||||
std::vector<double> b(10);
|
||||
std::iota(b.begin(), b.end(), 100);
|
||||
|
||||
std::vector<double> c(10);
|
||||
|
||||
ExpressionParser parser;
|
||||
parser.assignVector("a", a);
|
||||
parser.assignVector("b", b);
|
||||
parser.assignVector("c", c);
|
||||
|
||||
QString expr = "c := a + b";
|
||||
EXPECT_TRUE(parser.evaluate(expr));
|
||||
|
||||
EXPECT_DOUBLE_EQ(c[0], 110.0);
|
||||
EXPECT_DOUBLE_EQ(c[9], 128.0);
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user