ResInsight/ApplicationLibCode/UnitTests/ListKeywordsForObjectsAndFields-Test.cpp
Magne Sjaastad 0c90f67dcc
Change API for PdmObjectHandle and PdmFieldHandle
* Refactor interface to PdmObjectHandle and PdmFieldHandle
Return objects instead of passing in structures as parameters

* Add nodiscard to several functions
* Remove redundant this->
* Rename to ptrReferencedObjectsByType
2023-05-12 21:41:34 +02:00

109 lines
3.0 KiB
C++

#include "gtest/gtest.h"
#include "RiaVersionInfo.h"
#include "cafClassTypeName.h"
#include "cafPdmDefaultObjectFactory.h"
#include "cafPdmObjectHandle.h"
#include <QDateTime>
#include <QFile>
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void writeTextToFile( const QString& filePath, const QString& text )
{
QFile exportFile( filePath );
if ( exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
QTextStream stream( &exportFile );
stream << text;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString versionHeaderText()
{
QString text;
text += QString( "// ResInsight version string : %1\n" ).arg( STRPRODUCTVER );
text += QString( "// Report generated : %1\n" ).arg( QDateTime::currentDateTime().toString() );
text += "//\n";
text += "//\n";
text += "\n";
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( ListKeywords, ListAllObjectKeywords )
{
auto instance = caf::PdmDefaultObjectFactory::instance();
QString textString;
QTextStream stream( &textString );
textString = versionHeaderText();
std::vector<QString> classKeywords = instance->classKeywords();
for ( auto keyword : classKeywords )
{
stream << keyword << "\n";
}
QString filePath = "c:/temp/ri-objectKeywords.txt";
// writeTextToFile(filePath, textString);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( ListKeywords, ListAllObjectKeywordsAndFieldKeywords )
{
auto instance = caf::PdmDefaultObjectFactory::instance();
QString textString;
QTextStream stream( &textString );
bool includeClassName = true;
textString = versionHeaderText();
std::vector<QString> classKeywords = instance->classKeywords();
for ( auto keyword : classKeywords )
{
caf::PdmObjectHandle* myClass = instance->create( keyword );
stream << keyword;
if ( includeClassName )
{
QString className = qStringTypeName( *myClass );
stream << " - " << className;
}
stream << "\n";
std::vector<caf::PdmFieldHandle*> fields = myClass->fields();
for ( auto f : fields )
{
stream << " " << f->keyword() << "\n";
}
stream << "\n";
delete myClass;
}
QString filePath = "c:/temp/ri-fieldKeywords.txt";
// writeTextToFile(filePath, textString);
}