summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/unit/hash.cpp40
-rw-r--r--src/unit/taf.cpp48
2 files changed, 88 insertions, 0 deletions
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 @@
1#include "bu/fstring.h"
2#include "bu/hash.h"
3#include "unitsuite.h"
4
5#include <stdio.h>
6
7class Unit : public Bu::UnitSuite
8{
9private:
10 typedef Bu::Hash<Bu::FString, int> StrIntHash;
11public:
12 Unit()
13 {
14 setName("Hash");
15 addTest( Unit::test_probe );
16 }
17
18 virtual ~Unit()
19 {
20 }
21
22 void test_probe()
23 {
24 StrIntHash h;
25 char buf[20];
26 for(int i=0;i<10000;i++)
27 {
28 sprintf(buf,"%d",i);
29 Bu::FString sTmp(buf);
30 h[sTmp] = i;
31 unitTest( h.has(sTmp) );
32 }
33 }
34};
35
36int main( int argc, char *argv[] )
37{
38 return Unit().run( argc, argv );
39}
40
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 @@
1#include "unitsuite.h"
2#include "file.h"
3#include "tafreader.h"
4
5#include <string.h>
6#include <unistd.h>
7
8class Unit : public Bu::UnitSuite
9{
10public:
11 Unit()
12 {
13 setName("taf");
14 addTest( Unit::read1 );
15 }
16
17 virtual ~Unit()
18 {
19 }
20
21 void read1()
22 {
23#define FN_TMP ("/tmp/tmpXXXXXXXX")
24 Bu::FString sFnTmp(FN_TMP);
25 Bu::File fOut = Bu::File::tempFile( sFnTmp, "wb" );
26 const char *data =
27"{test: name=\"Bob\"}"
28;
29 fOut.write(data,strlen(data));
30 fOut.close();
31
32 Bu::File fIn(sFnTmp.c_str(), "rb");
33 Bu::TafReader tr(fIn);
34
35 Bu::TafNode *tn = tr.getNode();
36 unitTest( !strcmp("Bob", tn->getProperty("name").c_str()) );
37 delete tn;
38
39 unlink(sFnTmp.c_str());
40#undef FN_TMP
41 }
42};
43
44int main( int argc, char *argv[] )
45{
46 return Unit().run( argc, argv );
47}
48