From fc7d5c05945c58a14e6bba8d6038e33d27cf87c5 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Thu, 5 Nov 2026 09:09:58 +0100 Subject: [PATCH] #15008 Test that the added folder matches subCollectionClassKeyword() The Python generator declares the add_folder() return type from subCollectionClassKeyword(), while the folder is created by createSubCollection(). Nothing tied the two together, so overriding only one of them would give wrong type hints without any failing test. ResInsight-tests: the folder added to a polygon collection, a surface collection and an ensemble surface has the class named by subCollectionClassKeyword(), and a polygon file declares and creates no folder. --- .../RimcNestedCollectionBase-Test.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ApplicationLibCode/UnitTests/RimcNestedCollectionBase-Test.cpp b/ApplicationLibCode/UnitTests/RimcNestedCollectionBase-Test.cpp index 6e92627c10..4d3b4b5f92 100644 --- a/ApplicationLibCode/UnitTests/RimcNestedCollectionBase-Test.cpp +++ b/ApplicationLibCode/UnitTests/RimcNestedCollectionBase-Test.cpp @@ -20,6 +20,8 @@ #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" @@ -40,6 +42,17 @@ QString scriptCollectionName( caf::PdmNestedCollectionBase* collection ) 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 //-------------------------------------------------------------------------------------------------- @@ -71,6 +84,34 @@ TEST( RimcNestedCollectionBase, CollectionNameUsesPolygonFileFallback ) 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() ); +} + //-------------------------------------------------------------------------------------------------- /// //--------------------------------------------------------------------------------------------------