From 077f76345e9f207e07d666eea3f4a276e726675b Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Mon, 28 Mar 2016 10:58:03 -0600 Subject: [PATCH] Tests were not returning errors when an exception was caught. This was discovered in support of https://github.com/Unidata/netcdf-cxx4/issues/30 --- cxx4/test_att.cpp | 21 ++++++------ cxx4/test_classic.cpp | 2 +- cxx4/test_dim.cpp | 11 ++++--- cxx4/test_group.cpp | 45 ++++++++++++------------- cxx4/test_open_close.cpp | 1 + cxx4/test_type.cpp | 71 ++++++++++++++++++++-------------------- cxx4/test_type2.cpp | 11 ++++--- cxx4/test_type3.cpp | 25 +++++++------- cxx4/test_type4.cpp | 19 ++++++----- cxx4/test_type5.cpp | 19 ++++++----- cxx4/test_var.cpp | 11 ++++--- cxx4/test_var2.cpp | 1 + 12 files changed, 124 insertions(+), 113 deletions(-) diff --git a/cxx4/test_att.cpp b/cxx4/test_att.cpp index 7993710..ecc4b8a 100644 --- a/cxx4/test_att.cpp +++ b/cxx4/test_att.cpp @@ -20,14 +20,14 @@ int main() { cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"< b1(10); vector b2(10); @@ -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__); @@ -456,7 +456,7 @@ int main() cout <<" ----------- passed\n"; } - + cout < dimMap; @@ -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 < b1(10); vector b2(10); vector b3(10); @@ -134,7 +134,7 @@ try if( ncString.getTypeClassName() != "nc_STRING") throw NcException("Error in test 5.12",__FILE__,__LINE__); cout <<" ----------- passed\n"; - + cout < memberShape; @@ -204,14 +204,14 @@ try if(memberShape[0] != 6) throw NcException("Error in test 11.4",__FILE__,__LINE__); if(memberShape[1] != 3) throw NcException("Error in test 11.5",__FILE__,__LINE__); cout <<" ----------- passed\n"; - + cout < vecSize(2); vecSize[0]=6,vecSize[1]=3; - + NcCompoundType compoundType3(ncFile.addCompoundType("compoundType_3",sizeof(struct3))); compoundType3.addMember("member1",ncInt,offsetof(struct3,mem1)); compoundType3.addMember("member2",ncDouble,offsetof(struct3,mem2)); @@ -394,52 +394,52 @@ try NcDim dim3 = ncFile.addDim("dim3",2); NcVar var_3 = ncFile.addVar("var_3", compoundType3,dim3); - + struct3 dummyStruct; dummyStruct.mem1=1; dummyStruct.mem2=-1.23456; dummyStruct.mem3[0]=1; dummyStruct.mem3[1]=-6; dummyStruct.mem3[2]=20; - + struct3 dummyFill ; dummyFill.mem1=94; dummyFill.mem2=95; dummyFill.mem3[0]=96; dummyFill.mem3[1]=97; dummyFill.mem3[2]=98; - + struct3 dummyStruct2[2]; dummyStruct2[0].mem1=1; dummyStruct2[0].mem2=-1.23456; dummyStruct2[0].mem3[0]=1; dummyStruct2[0].mem3[1]=-6; dummyStruct2[0].mem3[2]=20; - + var_3.setFill(true,dummyFill); vector index(1);index[0]=1; - //var_3.putVar(&dummyStruct2); - var_3.putVar(index,&dummyStruct); - + //var_3.putVar(&dummyStruct2); + var_3.putVar(index,&dummyStruct); + NcVar var_4(ncFile.getVar("var_3")); if(var_4.isNull()) throw NcException("Error in test 28.1",__FILE__,__LINE__); struct3 dummyStruct3[2]; var_4.getVar(dummyStruct3); - + if(dummyStruct3[1].mem1 != 1) throw NcException("Error in test 28.2",__FILE__,__LINE__); if(dummyStruct3[1].mem2 != -1.23456) throw NcException("Error in test 28.3",__FILE__,__LINE__); if(dummyStruct3[1].mem3[0] != 1) throw NcException("Error in test 28.4",__FILE__,__LINE__); if(dummyStruct3[1].mem3[1] != -6) throw NcException("Error in test 28.5",__FILE__,__LINE__); if(dummyStruct3[1].mem3[2] != 20) throw NcException("Error in test 28.6",__FILE__,__LINE__); - + if(dummyStruct3[0].mem1 != 94) throw NcException("Error in test 28.7",__FILE__,__LINE__); if(dummyStruct3[0].mem2 != 95) throw NcException("Error in test 28.8",__FILE__,__LINE__); if(dummyStruct3[0].mem3[0] != 96) throw NcException("Error in test 28.9",__FILE__,__LINE__); if(dummyStruct3[0].mem3[1] != 97) throw NcException("Error in test 28.10",__FILE__,__LINE__); if(dummyStruct3[0].mem3[2] != 98) throw NcException("Error in test 28.11",__FILE__,__LINE__); - + } cout <<" ----------- passed\n"; @@ -472,7 +472,7 @@ try dummyData[1].p = vlenPointer; dummyData[1].len = 2; - var_7.putVar(dummyData); + var_7.putVar(dummyData); nc_free_vlen(&dummyData[0]); nc_free_vlen(&dummyData[1]); @@ -521,7 +521,7 @@ try // finally define a variable containing this new compound type NcDim dim13 = ncFile.addDim("dim13",2); NcVar var_13 = ncFile.addVar("var_13", compoundType4,dim13); - + // here we populate a single entry. struct10 dummyData2; short int* vlenPointer; @@ -539,12 +539,12 @@ try vlenPointer[1] = 64; dummyData2.mem1[1].p=vlenPointer; dummyData2.mem1[1].len=2; - + dummyData2.mem2=20.1234; // ...and put the data into the netCDF file vector index(1);index[0]=1; - var_13.putVar(index,&dummyData2); + var_13.putVar(index,&dummyData2); nc_free_vlen(&dummyData2.mem1[0]); nc_free_vlen(&dummyData2.mem1[1]); @@ -552,13 +552,14 @@ try } cout <<" ----------- passed\n"; - - + + } catch (NcException& e) { cout << "unknown error"< vecSize(2); vecSize[0]=6,vecSize[1]=3; - + NcCompoundType compoundType3(ncFile.addCompoundType("compoundType_3",sizeof(struct3))); compoundType3.addMember("member1",ncInt,offsetof(struct3,mem1)); compoundType3.addMember("member2",ncDouble,offsetof(struct3,mem2)); @@ -36,17 +36,17 @@ try NcDim dim3 = ncFile.addDim("dim3",1); NcVar var_3 = ncFile.addVar("var_3", compoundType3,dim3); - + struct3 dummyStruct; dummyStruct.mem1=1; dummyStruct.mem2=-1.23456; dummyStruct.mem3[0]=1; dummyStruct.mem3[1]=-6; dummyStruct.mem3[2]=20; - + vector index(1);index[0]=0; - var_3.putVar(index,&dummyStruct); - + var_3.putVar(index,&dummyStruct); + //NcVar var_4(ncFile.getVar("var_3")); exit(1); @@ -55,5 +55,6 @@ catch (NcException& e) { cout << "unknown error"< vecSize(2); vecSize[0]=6,vecSize[1]=3; - + NcVlenType vlenType(ncFile.addVlenType("vlenType_1",ncDouble)); - - + + NcCompoundType compoundType3(ncFile.addCompoundType("compoundType_3",sizeof(struct3))); compoundType3.addMember("member1",ncInt,offsetof(struct3,mem1)); compoundType3.addMember("member2",ncDouble,offsetof(struct3,mem2)); vector mem3Shape(1);mem3Shape[0]=mem3Size; compoundType3.addMember("member3",ncDouble,offsetof(struct3,mem3),mem3Shape); compoundType3.addMember("member4",vlenType,offsetof(struct3,mem4)); - + NcDim dim3 = ncFile.addDim("dim3"); NcVar var_3 = ncFile.addVar("var_3", compoundType3,dim3); // set the fill value - + struct3 fillValue; fillValue.mem1=0; fillValue.mem2=0.0; for(int j=0;j index(1); - + for (int i=0; i< 100;i++) { index[0]=i; - var_3.putVar(index,&dummyStruct); - } - + var_3.putVar(index,&dummyStruct); + } + nc_free_vlen(&dummyStruct.mem4); exit(1); - + } catch (NcException& e) { cout << "unknown error"< mem2Shape(1);mem2Shape[0]=mem2Size; vector mem3Shape(1);mem3Shape[0]=mem3Size; @@ -38,10 +38,10 @@ try NcDim dim3 = ncFile.addDim("dim3"); NcVar var_3 = ncFile.addVar("var_3", compoundType3,dim3); // set the fill value - + struct3 fillValue; for(int j=0;j index(1); - + for (int i=0; i< 1000;i++) { index[0]=i; - var_3.putVar(index,&dummyStruct); - } - - + var_3.putVar(index,&dummyStruct); + } + + } catch (NcException& e) { cout << "unknown error"< mem3Shape(1);mem3Shape[0]=mem3Size; compoundType3.addMember("member3",ncDouble,offsetof(struct3,mem3),mem3Shape); @@ -39,7 +39,7 @@ try // set the fill value struct3 fillValue; for(int j=0;j index(2); - + for (int i=0; i< 100;i++) { index[1]=i; index[0]=0; - var_3.putVar(index,&dummyStruct); + var_3.putVar(index,&dummyStruct); index[0]=1; - var_3.putVar(index,&dummyStruct2); - } - - + var_3.putVar(index,&dummyStruct2); + } + + } catch (NcException& e) { cout << "unknown error"<