NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test_NcFileUtils.cpp

Test of functions in netcdf::NcFileUtils.

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include "TestHandler.h"
#include <iostream>
using std::cout;
using std::endl;
#include <sstream>
#include "netcdf4"
using namespace::netcdf;
//---------------------------------------------------------------------------
// global test handler instance
TestHandler testHandler ( "Test of functions in netcdf::NcFileUtils.",
false, // writeLogTests
true, // writeLogSuccesses
true ); // writeLogFailures
//---------------------------------------------------------------------------
{
std::string fn = "ncfile.xxx";
std::string const fnWanted = "ncfile.nc";
std::ostringstream os;
os << "--- netcdf::SetExtension: " << fn << " -> " << fnWanted;
testHandler.LogMessage ( os.str() );
// test
testHandler.TEST ( fn == fnWanted );
}
//---------------------------------------------------------------------------
{
std::string const path = "./*.nc";
std::string const fnWanted = "example-gridded-data.nc";
std::ostringstream os;
os << "--- netcdf::GetNcFiles: " << "path = " << path << " : expect file " << fnWanted;
testHandler.LogMessage ( os.str() );
// test
std::vector< std::string > fileNames;
netcdf::GetNcFiles( path, fileNames );
bool const result =
( std::find( fileNames.begin(), fileNames.end(), fnWanted ) != fileNames.end() );
testHandler.TEST ( result );
}
//---------------------------------------------------------------------------
{
std::string const path = "./";
std::string const fnWanted = "example-gridded-data.nc";
std::ostringstream os;
os << "--- netcdf::GetNcFiles: " << "path = " << path << " : expect file " << fnWanted;
testHandler.LogMessage ( os.str() );
// test
std::vector< std::string > fileNames;
netcdf::GetNcFiles( path, fileNames );
bool const result =
( std::find( fileNames.begin(), fileNames.end(), fnWanted ) != fileNames.end() );
testHandler.TEST ( result );
}
//---------------------------------------------------------------------------
{
std::string const path = "*";
std::string const fnWanted = "example-gridded-data.nc";
std::ostringstream os;
os << "--- netcdf::GetNcFiles: " << "path = " << path << " : expect file " << fnWanted;
testHandler.LogMessage ( os.str() );
// test
std::vector< std::string > fileNames;
netcdf::GetNcFiles( path, fileNames );
bool const result =
( std::find( fileNames.begin(), fileNames.end(), fnWanted ) != fileNames.end() );
testHandler.TEST ( result );
}
//---------------------------------------------------------------------------
{
std::string const fnWanted = "./example-gridded-data.nc";
std::ostringstream os;
os << "--- netcdf::FileExists: " << "find: " << fnWanted;
testHandler.LogMessage ( os.str() );
// test
testHandler.TEST ( netcdf::FileExists(fnWanted) );
}
//-----------------------------------------------------------------------------
int main ()
{
try
{
Test_SetExtension(); // netcdf::SetExtension
Test_GetNcFiles1(); // netcdf::GetNcFiles
Test_GetNcFiles2(); // netcdf::GetNcFiles
Test_GetNcFiles3(); // netcdf::GetNcFiles
Test_FileExists(); // netcdf::FileExists
testHandler.WriteResults (std::cout);
}
catch (std::exception const & e)
{
cout << "Exception: " << e.what() << endl;
}
catch (...)
{
cout << "Error: unknown error." << endl;
}
cout << "\n all done!" << endl;
return 0;
}
//-----------------------------------------------------------------------------