From 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 15 May 2010 07:44:10 +0000 Subject: mkunit.sh was a little dumb, it didn't handle a number of things correctly. I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad. --- src/unit/taf.unit | 180 +++++++++++++++++++++++++++--------------------------- 1 file changed, 90 insertions(+), 90 deletions(-) (limited to 'src/unit/taf.unit') diff --git a/src/unit/taf.unit b/src/unit/taf.unit index a4f4f86..eb9475e 100644 --- a/src/unit/taf.unit +++ b/src/unit/taf.unit @@ -13,109 +13,109 @@ #include #include -{=Init} - -{%read1} +suite Taf { + test read1 + { #define FN_TMP ("/tmp/tmpXXXXXXXX") - Bu::FString sFnTmp(FN_TMP); - Bu::File fOut = Bu::File::tempFile( sFnTmp ); - const char *data = -"{test: name=\"Bob\"}" -; - fOut.write(data,strlen(data)); - fOut.close(); + Bu::FString sFnTmp(FN_TMP); + Bu::File fOut = Bu::File::tempFile( sFnTmp ); + const char *data = + "{test: name=\"Bob\"}" + ; + fOut.write(data,strlen(data)); + fOut.close(); - Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); - Bu::TafReader tr(fIn); - - Bu::TafGroup *tn = tr.readGroup(); - unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); - delete tn; + Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); + Bu::TafReader tr(fIn); + + Bu::TafGroup *tn = tr.readGroup(); + unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); + delete tn; - unlink(sFnTmp.getStr()); + unlink(sFnTmp.getStr()); #undef FN_TMP -} + } -{%encode1} -{ - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); - - Bu::TafGroup g("Test data"); - Bu::FString sData( 256 ); - for( int j = 0; j < 256; j++ ) - sData[j] = (unsigned char)j; - g.addChild( new Bu::TafProperty("Encoded", sData) ); - tw.writeGroup( &g ); + test encode1 + { + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); + + Bu::TafGroup g("Test data"); + Bu::FString sData( 256 ); + for( int j = 0; j < 256; j++ ) + sData[j] = (unsigned char)j; + g.addChild( new Bu::TafProperty("Encoded", sData) ); + tw.writeGroup( &g ); - static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" - "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" - "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" - "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" - "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" - " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" - "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" - "jklmnopqrstuvwxyz{|}~\\x7F" - "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" - "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" - "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" - "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" - "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" - "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" - "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" - "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" - "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" - "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" - "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" - "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" - "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" - "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" - "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" - "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; - unitTest( mb.getString() == cmpdata ); - mb.setPos( 0 ); - Bu::TafReader tr( mb ); - Bu::TafGroup *rg = tr.readGroup(); - unitTest( rg->getProperty("Encoded") == sData ); - delete rg; -} + static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" + "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" + "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" + "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" + " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" + "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" + "jklmnopqrstuvwxyz{|}~\\x7F" + "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" + "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" + "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" + "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" + "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" + "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" + "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" + "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" + "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" + "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" + "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" + "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" + "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" + "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" + "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" + "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; + unitTest( mb.getString() == cmpdata ); + mb.setPos( 0 ); + Bu::TafReader tr( mb ); + Bu::TafGroup *rg = tr.readGroup(); + unitTest( rg->getProperty("Encoded") == sData ); + delete rg; + } -{%emptyStr1} -{ - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); + test emptyStr1 + { + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); - Bu::TafGroup g("Test Group"); - Bu::FString sVal; - g.addChild( new Bu::TafProperty("Lame", sVal) ); - tw.writeGroup( &g ); + Bu::TafGroup g("Test Group"); + Bu::FString sVal; + g.addChild( new Bu::TafProperty("Lame", sVal) ); + tw.writeGroup( &g ); - unitTest( - mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); -} + unitTest( + mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); + } -{%incomplete1} -{ - try + test incomplete1 { - Bu::MemBuf mb("{Lame: \"Hello=\""); - Bu::TafReader tr( mb ); - delete tr.readGroup(); - unitFailed("Should have thrown an exception, didn't."); + try + { + Bu::MemBuf mb("{Lame: \"Hello=\""); + Bu::TafReader tr( mb ); + delete tr.readGroup(); + unitFailed("Should have thrown an exception, didn't."); + } + catch( Bu::TafException &e ) + { + // Woot + } } - catch( Bu::TafException &e ) + + test bypath1 { - // Woot + Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }"); + Bu::TafReader tr( mb ); + const Bu::TafGroup *g = tr.readGroup(); + unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" ); + unitTest( g->getByPath("inner/final/test") == "hi" ); } } - -{%bypath1} -{ - Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }"); - Bu::TafReader tr( mb ); - const Bu::TafGroup *g = tr.readGroup(); - unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" ); - unitTest( g->getByPath("inner/final/test") == "hi" ); -} - -- cgit v1.2.3