// ********************************************************************** // // This file tries to test the TupleNameTag and HBookNameTag classes. // It prints ERROR: error msg // to cout in case of unexpected result. // ********************************************************************** // #include #include #include bool errorHappened = false; void error (string msg) { cout << "ERROR: " << msg << endl; errorHappened = true; } void ColumnTagTest(string name,bool index,bool good = true); void ColumnTagTestEngine(TupleNameTag tag, string name,bool index, bool good) { if ( !good ) { if (tag.isValid() ) { string msg = "TupleNameTag found :"; msg += tag.block(); msg += "&"; msg += tag.column(); msg += " instead of error"; error(msg); } return; } if ( ! tag.isValid() ) { // good implied string msg = "Unexpected error in "; msg += name; error(msg); return; } if ( tag.block().length() != 0 ) { string msg = "TupleNameTag found block in '"; msg += name; msg += "'"; error(msg); } if ( index ) { int ppos = name.find('('); string index = name.substr(ppos); name = name.substr(0,ppos); } if ( tag.column() != name ) { string msg = "TupleNameTag found "; msg += tag.column(); msg += " instead of "; msg += name; error(msg); } } void ColumnTagTest(string name,bool index, bool good) { TupleNameTag tag(name,index); ColumnTagTestEngine(tag,name,index,good); } void BlockTagTestEngine(TupleNameTag tag, string bk, string col, string d,bool index, bool good) { string name = bk+d+col; if ( !good ) { if (tag.isValid() ) { string msg = "TupleNameTag found :"; msg += tag.block(); msg += "&"; msg += tag.column(); msg += " instead of error"; error(msg); } return; } if ( ! tag.isValid() ) { // good implied string msg = "Unexpected error in "; msg += name; error(msg); return; } if ( tag.block().length() == 0 ) { string msg = "TupleNameTag not found in '"; msg += name; msg += "'"; error(msg); } else if ( tag.block() != bk ) { string msg = "TupleNameTag found "; msg += tag.block(); msg += " instead of "; msg += bk; error(msg); } if ( index ) { int ppos = col.find('('); string index = col.substr(ppos); col = col.substr(0,ppos); } if ( tag.column().length() == 0 ) { string msg = "TupleNameTag not found in '"; msg += name; msg += "'"; error(msg); } else if ( tag.column() != col ) { string msg = "TupleNameTag found "; msg += tag.column(); msg += " instead of "; msg += col; error(msg); } } void BlockTagTest(string b, string c, string d, bool index,bool good =true); void BlockTagTest(string bk, string col, string d,bool index, bool good) { string name = bk+d+col; TupleNameTag tag(name,index); BlockTagTestEngine(tag,bk,col,d,index,good); } void HBookColumnTagTest(string name,bool index,bool good = true); void HBookColumnTagTest(string name,bool index,bool good) { HBookNameTag tag(name,index); ColumnTagTestEngine(tag, name,index,good); } void HBookBlockTagTest(string b, string c, string d, bool index,bool good =true); void HBookBlockTagTest(string bk, string col, string d, bool index,bool good) { string name = bk+d+col; HBookNameTag tag(name,index); BlockTagTestEngine(tag,bk,col,d,index,good); } void NameTagTest () { cout << "Start simple Column NameTag test\n"; ColumnTagTest("ACOLUMNBYITSELF",false); ColumnTagTest("12734jhgsadfjhgds",false); ColumnTagTest("ACOLUMNBYI(8,2,3)",true); ColumnTagTest("ACOLUMNBYI(8,2,3)",false,false); ColumnTagTest("ACOLUMN(8,3,4,4)BYITSELF",true,false); ColumnTagTest("ACOLUMNBYITSELF(8,,2)",true,false); ColumnTagTest(" sadlhjf",false,false); ColumnTagTest("sa dlhjf",false,false); ColumnTagTest(" sadlhjf ",false,false); cout << "Start simple Block NameTag test\n"; BlockTagTest("blockName","colName","::",false); BlockTagTest("blockName","colName(2,3,4)","::",true); BlockTagTest("blockName23123","12312colName","::",false); BlockTagTest("blo1231ckName","1231colName","::",false); BlockTagTest("123123blockName","123colName","::",false); BlockTagTest("b&^#lockName","col*&#Name","::",false,false); BlockTagTest("blockName","colName(2,3,4)","::",false,false); BlockTagTest("","colName","::",false,false); BlockTagTest("asd sad","col Name","::",false,false); } void HBookNameTagTest () { cout << "Start simple HBook Column NameTag test\n"; HBookColumnTagTest("ACOLUMN",false); HBookColumnTagTest("ACOLUMN(1,2,3)",true); HBookColumnTagTest("ACOLUMN(1)",true); HBookColumnTagTest("ACOLUMNBYITSELF",false,false); HBookColumnTagTest("12734jhgsadfjhgds",false,false); HBookColumnTagTest("ACOLUMNBYI(8,2,3)",true,false); HBookColumnTagTest("ACOLUMN(8,3,4,4)BYITSELF",false,false); HBookColumnTagTest("ACOLUMNBYITSELF(8,,2)",true,false); HBookColumnTagTest(" sadlhjf",false,false); HBookColumnTagTest("sa dlhjf",false,false); HBookColumnTagTest(" sadlhjf ",false,false); cout << "Start simple HBook Block NameTag test\n"; HBookBlockTagTest("bkName","colName","::",false); HBookBlockTagTest("bkName","colName(1,2,3)","::",true); HBookBlockTagTest("bkName","colName(1)","::",true); HBookBlockTagTest("bkName","colName(1,)","::",false,false); HBookBlockTagTest("blockName","colName","::",false,false); HBookBlockTagTest("blockName","colName(2,3,4)","::",false,false); HBookBlockTagTest("blockName23123","12312colName","::",false,false); HBookBlockTagTest("blo1231ckName","1231colName","::",false,false); HBookBlockTagTest("123123blockName","123colName","::",false,false); HBookBlockTagTest("b&^#lockName","col*&#Name","::",false,false); HBookBlockTagTest("","colName","::",false,false); HBookBlockTagTest("asd sad","col Name","::",false,false); } void main () { NameTagTest(); HBookNameTagTest(); }