Test of class NcString.
#include <iostream>
using std::cout;
using std::endl;
#include <memory>
#include <sstream>
#include "netcdf4"
using namespace netcdf;
#include "AssertEx.h"
char const *
const ncFileName =
"Test_NcString.nc";
char const *
const varNames[] = {
"strings",
"oneString",
"emptyString" };
std::vector< std::string > & strVec,
short const numStrings)
{
if ( numStrings > 0 )
{
strVec.resize( numStrings );
for ( short i = 0; i < numStrings; ++i )
{
std::ostringstream os;
os << "string " << i << ":";
for ( short n = 0; n <= i; ++n )
os << " " << n;
strVec[i] = os.str();
}
}
}
{
std::auto_ptr<NcFile> pNcFile (
NcDim strDim = pNcFile->AddDim (
"count" );
Assert(!strVar.IsNull());
Assert(!varScalarStr.IsNull());
Assert(!varScalarStr.IsNull());
pNcFile->ToDataMode();
return pNcFile;
}
std::vector< std::string > const & strVec,
std::string const & oneStr)
{
std::string emptyStr;
}
std::vector< std::string > & strVec,
std::string & oneStr)
{
std::string emptyStr;
}
std::vector< std::string > const & strVec)
{
std::string str;
bool ok = ( str == strVec[1] );
return ok;
}
std::string
const &
Test (
bool const result )
{
static std::string const strs[] = { "passed", "failed" };
return ( result ? strs[0] : strs[1] );
}
{
cout << "Test of class NcString I/O." << endl;
try
{
cout << "Making string array..." << endl;
std::size_t const numStrings = 5;
std::vector< std::string > strVec;
cout << "Add data to file..." << endl;
std::string const oneStr = "Do wah ditty";
AddData( *pNcFile, strVec, oneStr );
cout << "Read data from file..." << endl;
std::vector< std::string > strVecIn;
std::string oneStrIn;
ReadData( *pNcFile, strVecIn, oneStrIn );
bool areEqual = strVec.size() == strVecIn.size();
if ( areEqual )
areEqual = std::equal( strVec.begin(), strVec.end(), strVecIn.begin() );
cout << "variable vector<string>: original == input ? "
<< ( areEqual ? "yes" : "no" )
<< endl;
cout << "variable scalar string: original == input ? "
<< ( (oneStr == oneStrIn) ? "yes" : "no" )
<< endl;
}
catch (std::exception const & e)
{
cout << "Exception: " << e.what() << endl;
}
catch (...)
{
cout << "Error: unknown error." << endl;
}
cout << "\n all done!" << endl;
return 0;
}