Skip to content

Commit

Permalink
Tests were not returning errors when an exception was caught. This wa…
Browse files Browse the repository at this point in the history
…s discovered in support of #30
  • Loading branch information
WardF committed Mar 28, 2016
1 parent 0c32c52 commit 077f763
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 113 deletions.
21 changes: 11 additions & 10 deletions cxx4/test_att.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ int main()
{
cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
NcFile ncFile("firstFile.cdf",NcFile::replace);

cout<<left<<setw(55)<<"Testing addGroup(\"groupName\")";
NcGroup groupA(ncFile.addGroup("groupA"));
NcGroup groupA0(ncFile.addGroup("groupA0"));
NcGroup groupB(groupA.addGroup("groupB"));
NcGroup groupC(groupA.addGroup("groupC"));
cout <<" ----------- passed\n";

cout <<left<<setw(55)<<"Testing putAtt(\"attName\",\"typeName\",len,dataValues)";
vector<string> b1(10);
vector<unsigned char *> b2(10);
Expand Down Expand Up @@ -402,7 +402,7 @@ int main()
iter=groupMap.find("att_C1"); if( iter != groupMap.end()) throw NcException("Error in test 8.116",__FILE__,__LINE__);


// now for groupB
// now for groupB
groupMap = groupB.getAtts();
if(groupMap.size() != 4) throw NcException("Error in test 8.117",__FILE__,__LINE__);
iter=groupMap.find("att1_7"); if( iter != groupMap.end()) throw NcException("Error in test 8.118",__FILE__,__LINE__);
Expand Down Expand Up @@ -456,7 +456,7 @@ int main()

cout <<" ----------- passed\n";
}

cout <<left<<setw(55)<<"Testing getAtt(\"name\",[netCDF::Location])";
if(ncFile.getAtt("att1_7") != attA1_7) throw NcException("Error in test 9.1",__FILE__,__LINE__);
if(ncFile.getAtt("att1_7",NcGroup::Current) != attA1_7) throw NcException("Error in test 9.2",__FILE__,__LINE__);
Expand Down Expand Up @@ -498,31 +498,31 @@ int main()
if(ncFile.getAtt("att_C1",NcGroup::All) != att_C1) throw NcException("Error in test 9.35",__FILE__,__LINE__);

// now for next group

if(!groupA0.getAtt("att1_7").isNull()) throw NcException("Error in test 9.36",__FILE__,__LINE__);
if(!groupA0.getAtt("att1_7",NcGroup::Current).isNull()) throw NcException("Error in test 9.37",__FILE__,__LINE__);
if(groupA0.getAtt("att1_7",NcGroup::Parents) != attA1_7) throw NcException("Error in test 9.38",__FILE__,__LINE__);
if(!groupA0.getAtt("att1_7",NcGroup::Children).isNull()) throw NcException("Error in test 9.39",__FILE__,__LINE__);
if(groupA0.getAtt("att1_7",NcGroup::ParentsAndCurrent) != attA1_7) throw NcException("Error in test 9.40",__FILE__,__LINE__);
if(!groupA0.getAtt("att1_7",NcGroup::ChildrenAndCurrent).isNull()) throw NcException("Error in test 9.41",__FILE__,__LINE__);
if(groupA0.getAtt("att1_7",NcGroup::All) != attA1_7) throw NcException("Error in test 9.42",__FILE__,__LINE__);

if(!groupA0.getAtt("att_A01").isNull()) throw NcException("Error in test 9.43",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::Current).isNull()) throw NcException("Error in test 9.44",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::Parents).isNull()) throw NcException("Error in test 9.45",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::Children).isNull()) throw NcException("Error in test 9.46",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::ParentsAndCurrent).isNull()) throw NcException("Error in test 9.47",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::ChildrenAndCurrent).isNull())throw NcException("Error in test 9.48",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A01",NcGroup::All).isNull()) throw NcException("Error in test 9.49",__FILE__,__LINE__);

if(groupA0.getAtt("att_A1") != att_A1) throw NcException("Error in test 9.50",__FILE__,__LINE__);
if(groupA0.getAtt("att_A1",NcGroup::Current) != att_A1) throw NcException("Error in test 9.51",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A1",NcGroup::Parents).isNull()) throw NcException("Error in test 9.52",__FILE__,__LINE__);
if(!groupA0.getAtt("att_A1",NcGroup::Children).isNull()) throw NcException("Error in test 9.53",__FILE__,__LINE__);
if(groupA0.getAtt("att_A1",NcGroup::ParentsAndCurrent) != att_A1)throw NcException("Error in test 9.54",__FILE__,__LINE__);
if(groupA0.getAtt("att_A1",NcGroup::ChildrenAndCurrent)!= att_A1) throw NcException("Error in test 9.55",__FILE__,__LINE__);
if(groupA0.getAtt("att_A1",NcGroup::All) != att_A1) throw NcException("Error in test 9.56",__FILE__,__LINE__);

if(!groupA0.getAtt("att_B3").isNull()) throw NcException("Error in test 9.57",__FILE__,__LINE__);
if(!groupA0.getAtt("att_B3",NcGroup::Current).isNull()) throw NcException("Error in test 9.58",__FILE__,__LINE__);
if(!groupA0.getAtt("att_B3",NcGroup::Parents).isNull()) throw NcException("Error in test 9.59",__FILE__,__LINE__);
Expand Down Expand Up @@ -605,7 +605,7 @@ int main()
if(!groupB.getAtt("att_A1",NcGroup::ParentsAndCurrent).isNull()) throw NcException("Error in test 9.124",__FILE__,__LINE__);
if(!groupB.getAtt("att_A1",NcGroup::ChildrenAndCurrent).isNull())throw NcException("Error in test 9.125",__FILE__,__LINE__);
if(!groupB.getAtt("att_A1",NcGroup::All).isNull()) throw NcException("Error in test 9.126",__FILE__,__LINE__);

if(groupB.getAtt("att_B3") != att_B3) throw NcException("Error in test 9.127",__FILE__,__LINE__);
if(groupB.getAtt("att_B3",NcGroup::Current) != att_B3) throw NcException("Error in test 9.128",__FILE__,__LINE__);
if(!groupB.getAtt("att_B3",NcGroup::Parents).isNull()) throw NcException("Error in test 9.129",__FILE__,__LINE__);
Expand Down Expand Up @@ -817,7 +817,7 @@ int main()

return 0;
}




Expand All @@ -830,5 +830,6 @@ int main()
{
cout << "unknown error"<<endl;
e.what();
return e.errorCode();
}
}
2 changes: 1 addition & 1 deletion cxx4/test_classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ int main()
catch(NcException& e)
{
cout << "Error!\n";
return 99;
return e.errorCode();
}
}
11 changes: 6 additions & 5 deletions cxx4/test_dim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ int main()
{
cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
NcFile ncFile("firstFile.cdf", NcFile::replace);

cout<<left<<setw(55)<<"Testing addGroup(\"groupName\")";
NcGroup groupA(ncFile.addGroup("groupA"));
NcGroup groupA0(ncFile.addGroup("groupA0"));
NcGroup groupB(groupA.addGroup("groupB"));
NcGroup groupC(groupA.addGroup("groupC"));
cout <<" ----------- passed\n";

cout <<left<<setw(55)<<"Testing addDim(\"dimensionName\")";
NcDim dim1 = ncFile.addDim("dim1",11);
NcDim dim2 = ncFile.addDim("dim2");
Expand Down Expand Up @@ -105,7 +105,7 @@ int main()
cout <<" ----------- passed\n";



cout <<left<<setw(55)<<"Testing NcGroup::getDims([netCDF::Location])";
{
multimap<string,NcDim> dimMap;
Expand Down Expand Up @@ -162,12 +162,12 @@ int main()
if( iter == dimMap.end()) throw NcException("Error in test 7.21",__FILE__,__LINE__);
iter=dimMap.find("dim7");
if( iter == dimMap.end()) throw NcException("Error in test 7.22",__FILE__,__LINE__);

}
cout <<" ----------- passed\n";



cout <<left<<setw(55)<<"Testing NcGroup::getDims(\"name\",[netCDF::Location])";
{

Expand Down Expand Up @@ -328,5 +328,6 @@ int main()
{
cout <<"\n";
e.what();
return e.errorCode();
}
}
45 changes: 23 additions & 22 deletions cxx4/test_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ try
{
cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
NcFile ncFile("firstFile.cdf",NcFile::replace);

cout<<left<<setw(50)<<"Testing addGroup(\"groupName\")";
NcGroup groupA(ncFile.addGroup("groupA"));
NcGroup groupA0(ncFile.addGroup("groupA0"));
NcGroup groupB(groupA.addGroup("groupB"));
NcGroup groupC(groupA.addGroup("groupC"));
cout <<" ----------- passed\n";

cout <<left<<setw(50)<<"Testing getGroupCount([netCDF::Location])";
if( ncFile.getGroupCount()!= 2) throw NcException("Error in test 1.1",__FILE__,__LINE__);
if( groupA.getGroupCount()!= 2) throw NcException("Error in test 1.2",__FILE__,__LINE__);
Expand Down Expand Up @@ -53,14 +53,14 @@ try
if( iter == groupMap.end()) throw NcException("Error in test 2.2",__FILE__,__LINE__);
iter=groupMap.find("groupA0");
if( iter == groupMap.end()) throw NcException("Error in test 2.3",__FILE__,__LINE__);

groupMap =ncFile.getGroups(NcGroup::ChildrenGrps);
if( groupMap.size() != 2) throw NcException("Error in test 2.4",__FILE__,__LINE__);
iter=groupMap.find("groupA");
if( iter == groupMap.end()) throw NcException("Error in test 2.5",__FILE__,__LINE__);
iter=groupMap.find("groupA0");
if( iter == groupMap.end()) throw NcException("Error in test 2.6",__FILE__,__LINE__);

groupMap = ncFile.getGroups(NcGroup::ParentsGrps);
if( groupMap.size() != 0) throw NcException("Error in test 2.7",__FILE__,__LINE__);

Expand All @@ -81,7 +81,7 @@ try
if( iter == groupMap.end()) throw NcException("Error in test 2.14",__FILE__,__LINE__);
iter=groupMap.find("groupC");
if( iter == groupMap.end()) throw NcException("Error in test 2.15",__FILE__,__LINE__);

groupMap = ncFile.getGroups(NcGroup::ParentsAndCurrentGrps);
if( groupMap.size() != 1) throw NcException("Error in test 2.16",__FILE__,__LINE__);
iter=groupMap.find("/");
Expand Down Expand Up @@ -109,15 +109,15 @@ try
if( iter == groupMap.end()) throw NcException("Error in test 2.25",__FILE__,__LINE__);
iter=groupMap.find("groupC");
if( iter == groupMap.end()) throw NcException("Error in test 2.26",__FILE__,__LINE__);


groupMap =groupA.getGroups(NcGroup::ChildrenGrps);
if( groupMap.size() != 2) throw NcException("Error in test 2.27",__FILE__,__LINE__);
iter=groupMap.find("groupB");
if( iter == groupMap.end()) throw NcException("Error in test 2.28",__FILE__,__LINE__);
iter=groupMap.find("groupC");
if( iter == groupMap.end()) throw NcException("Error in test 2.29",__FILE__,__LINE__);

groupMap = groupA.getGroups(NcGroup::ParentsGrps);
if( groupMap.size() != 1) throw NcException("Error in test 2.30",__FILE__,__LINE__);
iter=groupMap.find("/");
Expand All @@ -132,7 +132,7 @@ try
if( iter == groupMap.end()) throw NcException("Error in test 2.34",__FILE__,__LINE__);
iter=groupMap.find("groupC");
if( iter == groupMap.end()) throw NcException("Error in test 2.35",__FILE__,__LINE__);

groupMap = groupA.getGroups(NcGroup::ParentsAndCurrentGrps);
if( groupMap.size() != 2) throw NcException("Error in test 2.36",__FILE__,__LINE__);
iter=groupMap.find("/");
Expand All @@ -158,7 +158,7 @@ try

groupMap =groupB.getGroups(NcGroup::ChildrenGrps);
if( groupMap.size() != 0) throw NcException("Error in test 2.45",__FILE__,__LINE__);

groupMap = groupB.getGroups(NcGroup::ParentsGrps);
if( groupMap.size() != 2) throw NcException("Error in test 2.46",__FILE__,__LINE__);
iter=groupMap.find("/");
Expand All @@ -171,7 +171,7 @@ try

groupMap = groupB.getGroups(NcGroup::AllChildrenGrps);
if( groupMap.size() != 0) throw NcException("Error in test 2.50",__FILE__,__LINE__);

groupMap = groupB.getGroups(NcGroup::ParentsAndCurrentGrps);
if( groupMap.size() != 3) throw NcException("Error in test 2.51",__FILE__,__LINE__);
iter=groupMap.find("/");
Expand Down Expand Up @@ -226,7 +226,7 @@ try

groupSet = ncFile.getGroups("groupA",NcGroup::AllGrps);
if( groupSet.size() != 1) throw NcException("Error in test 3.9",__FILE__,__LINE__);


// operations on ncFile:groupB

Expand All @@ -250,7 +250,7 @@ try

groupSet = ncFile.getGroups("groupB",NcGroup::AllGrps);
if( groupSet.size() != 1) throw NcException("Error in test 3.16",__FILE__,__LINE__);


// operations on groupA:groupA

Expand All @@ -274,7 +274,7 @@ try

groupSet = groupA.getGroups("groupA",NcGroup::AllGrps);
if( groupSet.size() != 1) throw NcException("Error in test 3.23",__FILE__,__LINE__);



// operations on groupA:ncFile
Expand All @@ -299,7 +299,7 @@ try

groupSet = groupA.getGroups("/",NcGroup::AllGrps);
if( groupSet.size() != 1) throw NcException("Error in test 3.30",__FILE__,__LINE__);



// operations on groupA:groupB
Expand All @@ -324,7 +324,7 @@ try

groupSet = groupA.getGroups("groupB",NcGroup::AllGrps);
if( groupSet.size() != 1) throw NcException("Error in test 3.37",__FILE__,__LINE__);


// operations on groupA:groupA0

Expand All @@ -348,13 +348,13 @@ try

groupSet = groupA.getGroups("groupA0",NcGroup::AllGrps);
if( groupSet.size() != 0) throw NcException("Error in test 3.44",__FILE__,__LINE__);

}

cout <<" ----------- passed\n";





cout <<left<<setw(50)<<"Testing getGroup(\"name\",[netCDF::Location])";
Expand All @@ -364,11 +364,11 @@ try

if( ncFile.getGroup("groupA").getName() != "groupA") throw NcException("Error in test 4.1",__FILE__,__LINE__);
if( !ncFile.getGroup("groupB").isNull()) throw NcException("Error in test 4.2",__FILE__,__LINE__);

}

cout <<" ----------- passed\n";




Expand All @@ -379,7 +379,7 @@ try
if( groupA0.getParentGroup().getName() != "/") throw NcException("Error in test 5.3",__FILE__,__LINE__);
if( groupB.getParentGroup().getName() != "groupA")throw NcException("Error in test 5.4",__FILE__,__LINE__);
if( groupC.getParentGroup().getName() != "groupA")throw NcException("Error in test 5.5",__FILE__,__LINE__);

cout <<" ----------- passed\n";


Expand All @@ -388,5 +388,6 @@ try
{
cout << "unknown error"<<endl;
e.what();
return e.errorCode();
}
}
1 change: 1 addition & 0 deletions cxx4/test_open_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int main() {
return -1;
} catch(NcException &e) {
cout << "Caught Expected Exception." << endl;
return e.errorCode();
}

// Test opening a file that exists.
Expand Down
Loading

0 comments on commit 077f763

Please sign in to comment.