///////////////////////////////////////////////////////////////////////////////// // // 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 "Polygons/Cloud/RimPolygonCloudAddress.h" #include "Polygons/RimPolygonCollection.h" #include "Polygons/RimPolygonFile.h" #include "RimEnsembleSurface.h" #include "RimSurfaceCollection.h" #include "RimcDataContainerString.h" #include "RimcNestedCollectionBase.h" #include namespace { QString scriptCollectionName( caf::PdmNestedCollectionBase* collection ) { RimcNestedCollectionBase_collectionName method( collection ); auto result = method.execute(); if ( !result.has_value() ) return ""; std::unique_ptr strings( dynamic_cast( result.value() ) ); if ( !strings || strings->m_stringValues().size() != 1 ) return ""; return strings->m_stringValues().front(); } // 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() ); } } // 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 ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST( RimcNestedCollectionBase, CollectionNameUsesCloudAddressFallback ) { RimPolygonCloudAddress address; EXPECT_EQ( "Sumo Polygon Address", scriptCollectionName( &address ) ); address.setCollectionName( "Outline" ); EXPECT_EQ( "Outline", scriptCollectionName( &address ) ); }