2026-11-04 17:05:14 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include "Polygons/Cloud/RimPolygonCloudAddress.h"
|
|
|
|
|
#include "Polygons/RimPolygonCollection.h"
|
|
|
|
|
#include "Polygons/RimPolygonFile.h"
|
2026-11-05 09:09:58 +01:00
|
|
|
#include "RimEnsembleSurface.h"
|
|
|
|
|
#include "RimSurfaceCollection.h"
|
2026-11-04 17:05:14 +01:00
|
|
|
|
|
|
|
|
#include "RimcDataContainerString.h"
|
|
|
|
|
#include "RimcNestedCollectionBase.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
QString scriptCollectionName( caf::PdmNestedCollectionBase* collection )
|
|
|
|
|
{
|
|
|
|
|
RimcNestedCollectionBase_collectionName method( collection );
|
|
|
|
|
|
|
|
|
|
auto result = method.execute();
|
|
|
|
|
if ( !result.has_value() ) return "<error>";
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RimcDataContainerString> strings( dynamic_cast<RimcDataContainerString*>( result.value() ) );
|
|
|
|
|
if ( !strings || strings->m_stringValues().size() != 1 ) return "<error>";
|
|
|
|
|
|
|
|
|
|
return strings->m_stringValues().front();
|
|
|
|
|
}
|
2026-11-05 09:09:58 +01:00
|
|
|
|
|
|
|
|
// The Python generator declares the folder type from subCollectionClassKeyword(), while the folder is
|
|
|
|
|
// created by createSubCollection(). Both must name the same class.
|
|
|
|
|
void expectAddedFolderMatchesDeclaredKeyword( caf::PdmNestedCollectionBase& collection, const QString& expectedKeyword )
|
|
|
|
|
{
|
|
|
|
|
EXPECT_EQ( expectedKeyword, collection.subCollectionClassKeyword() );
|
|
|
|
|
|
|
|
|
|
caf::PdmNestedCollectionBase* added = collection.addNewSubCollection();
|
|
|
|
|
ASSERT_NE( nullptr, added );
|
|
|
|
|
EXPECT_EQ( collection.subCollectionClassKeyword(), added->classKeyword() );
|
|
|
|
|
}
|
2026-11-04 17:05:14 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( RimcNestedCollectionBase, CollectionNameReturnsStoredName )
|
|
|
|
|
{
|
|
|
|
|
RimPolygonCollection collection;
|
|
|
|
|
collection.setCollectionName( "Folder A" );
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ( "Folder A", scriptCollectionName( &collection ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// A polygon file falls back to the file name, or to a default, when no name is stored.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( RimcNestedCollectionBase, CollectionNameUsesPolygonFileFallback )
|
|
|
|
|
{
|
|
|
|
|
RimPolygonFile polygonFile;
|
|
|
|
|
EXPECT_TRUE( polygonFile.collectionName().isEmpty() );
|
|
|
|
|
EXPECT_EQ( "Polygon File", scriptCollectionName( &polygonFile ) );
|
|
|
|
|
|
|
|
|
|
// Setting the file stores the base name of the file as the folder name
|
|
|
|
|
polygonFile.setFileName( "/data/polygons/outline.pol" );
|
|
|
|
|
EXPECT_EQ( "outline", scriptCollectionName( &polygonFile ) );
|
|
|
|
|
|
|
|
|
|
polygonFile.setCollectionName( "" );
|
|
|
|
|
EXPECT_EQ( "outline.pol", scriptCollectionName( &polygonFile ) );
|
|
|
|
|
EXPECT_EQ( polygonFile.name(), scriptCollectionName( &polygonFile ) );
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 09:09:58 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( RimcNestedCollectionBase, AddedFolderMatchesSubCollectionClassKeyword )
|
|
|
|
|
{
|
|
|
|
|
RimPolygonCollection polygonCollection;
|
|
|
|
|
expectAddedFolderMatchesDeclaredKeyword( polygonCollection, RimPolygonCollection::classKeywordStatic() );
|
|
|
|
|
|
|
|
|
|
RimSurfaceCollection surfaceCollection;
|
|
|
|
|
expectAddedFolderMatchesDeclaredKeyword( surfaceCollection, RimSurfaceCollection::classKeywordStatic() );
|
|
|
|
|
|
|
|
|
|
// An ensemble surface creates plain surface folders, not ensemble surfaces
|
|
|
|
|
RimEnsembleSurface ensembleSurface;
|
|
|
|
|
expectAddedFolderMatchesDeclaredKeyword( ensembleSurface, RimSurfaceCollection::classKeywordStatic() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// A leaf folder declares no folder type and creates none.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( RimcNestedCollectionBase, LeafFolderHasNoSubCollectionClassKeyword )
|
|
|
|
|
{
|
|
|
|
|
RimPolygonFile polygonFile;
|
|
|
|
|
EXPECT_FALSE( polygonFile.canAddSubCollection() );
|
|
|
|
|
EXPECT_TRUE( polygonFile.subCollectionClassKeyword().isEmpty() );
|
|
|
|
|
EXPECT_EQ( nullptr, polygonFile.addNewSubCollection() );
|
|
|
|
|
EXPECT_TRUE( polygonFile.subCollections().empty() );
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 17:05:14 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( RimcNestedCollectionBase, CollectionNameUsesCloudAddressFallback )
|
|
|
|
|
{
|
|
|
|
|
RimPolygonCloudAddress address;
|
|
|
|
|
EXPECT_EQ( "Sumo Polygon Address", scriptCollectionName( &address ) );
|
|
|
|
|
|
|
|
|
|
address.setCollectionName( "Outline" );
|
|
|
|
|
EXPECT_EQ( "Outline", scriptCollectionName( &address ) );
|
|
|
|
|
}
|