diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp index b4f00c813b..c61ba6b9e7 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -3364,8 +3364,12 @@ void RigCaseCellResultsData::copyResultsMetaDataFromMainCase( RigEclipseCaseData RiaDefines::PorosityModelType poroModel, std::vector destinationCases ) { - std::vector resAddresses = mainCaseResultsData->results( poroModel )->existingResults(); - std::vector timeStepInfos = mainCaseResultsData->results( poroModel )->timeStepInfos( resAddresses[0] ); + std::vector resAddresses = mainCaseResultsData->results( poroModel )->existingResults(); + std::vector timeStepInfos; + if ( !resAddresses.empty() ) + { + timeStepInfos = mainCaseResultsData->results( poroModel )->timeStepInfos( resAddresses[0] ); + } const std::vector resultInfos = mainCaseResultsData->results( poroModel )->infoForEachResultIndex(); diff --git a/ApplicationLibCode/UnitTests/CMakeLists.txt b/ApplicationLibCode/UnitTests/CMakeLists.txt index 25dd04e2f6..d705e2bad9 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists.txt +++ b/ApplicationLibCode/UnitTests/CMakeLists.txt @@ -22,6 +22,7 @@ set(SOURCE_UNITTEST_FILES ${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommon-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RifReaderEclipseSummary-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RigActiveCellInfo-Test.cpp + ${CMAKE_CURRENT_LIST_DIR}/RigCaseCellResultsData-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RigEclipseCaseDataTools-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RigEclipseCrossPlotDataExtractor-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultTools-Test.cpp diff --git a/ApplicationLibCode/UnitTests/RigCaseCellResultsData-Test.cpp b/ApplicationLibCode/UnitTests/RigCaseCellResultsData-Test.cpp new file mode 100644 index 0000000000..50290106e1 --- /dev/null +++ b/ApplicationLibCode/UnitTests/RigCaseCellResultsData-Test.cpp @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026 Equinor 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "gtest/gtest.h" + +#include "RimEclipseResultCase.h" + +#include "RigCaseCellResultsData.h" +#include "RigEclipseCaseData.h" +#include "RigEclipseResultAddress.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// A main case without any results must not be indexed for its first result. +//-------------------------------------------------------------------------------------------------- +TEST( RigCaseCellResultsData, CopyResultsMetaDataFromMainCaseWithoutResults ) +{ + std::unique_ptr resultCase( new RimEclipseResultCase ); + cvf::ref eclipseCase = new RigEclipseCaseData( resultCase.get() ); + + const auto poroModel = RiaDefines::PorosityModelType::MATRIX_MODEL; + ASSERT_TRUE( eclipseCase->results( poroModel )->existingResults().empty() ); + + RigCaseCellResultsData::copyResultsMetaDataFromMainCase( eclipseCase.p(), poroModel, {} ); +}