mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-01 03:37:15 -06:00
0c90f67dcc
* 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
109 lines
3.0 KiB
C++
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);
|
|
}
|