From 2b90449c30e4a420af4fff7e58588611d71f61fc Mon Sep 17 00:00:00 2001 From: David Date: Fri, 15 Jun 2007 18:54:59 +0000 Subject: david - wrote two silly unit tests... --- src/unit/hash.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/unit/taf.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/unit/hash.cpp create mode 100644 src/unit/taf.cpp (limited to 'src/unit') diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp new file mode 100644 index 0000000..588e687 --- /dev/null +++ b/src/unit/hash.cpp @@ -0,0 +1,40 @@ +#include "bu/fstring.h" +#include "bu/hash.h" +#include "unitsuite.h" + +#include + +class Unit : public Bu::UnitSuite +{ +private: + typedef Bu::Hash StrIntHash; +public: + Unit() + { + setName("Hash"); + addTest( Unit::test_probe ); + } + + virtual ~Unit() + { + } + + void test_probe() + { + StrIntHash h; + char buf[20]; + for(int i=0;i<10000;i++) + { + sprintf(buf,"%d",i); + Bu::FString sTmp(buf); + h[sTmp] = i; + unitTest( h.has(sTmp) ); + } + } +}; + +int main( int argc, char *argv[] ) +{ + return Unit().run( argc, argv ); +} + diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp new file mode 100644 index 0000000..ab485d0 --- /dev/null +++ b/src/unit/taf.cpp @@ -0,0 +1,48 @@ +#include "unitsuite.h" +#include "file.h" +#include "tafreader.h" + +#include +#include + +class Unit : public Bu::UnitSuite +{ +public: + Unit() + { + setName("taf"); + addTest( Unit::read1 ); + } + + virtual ~Unit() + { + } + + void read1() + { +#define FN_TMP ("/tmp/tmpXXXXXXXX") + Bu::FString sFnTmp(FN_TMP); + Bu::File fOut = Bu::File::tempFile( sFnTmp, "wb" ); + const char *data = +"{test: name=\"Bob\"}" +; + fOut.write(data,strlen(data)); + fOut.close(); + + Bu::File fIn(sFnTmp.c_str(), "rb"); + Bu::TafReader tr(fIn); + + Bu::TafNode *tn = tr.getNode(); + unitTest( !strcmp("Bob", tn->getProperty("name").c_str()) ); + delete tn; + + unlink(sFnTmp.c_str()); +#undef FN_TMP + } +}; + +int main( int argc, char *argv[] ) +{ + return Unit().run( argc, argv ); +} + -- cgit v1.2.3