diff options
Diffstat (limited to '')
| -rw-r--r-- | src/unit/archive.cpp | 145 | ||||
| -rw-r--r-- | src/unit/archive.unit | 130 | ||||
| -rw-r--r-- | src/unit/array.cpp | 101 | ||||
| -rw-r--r-- | src/unit/array.unit | 80 | ||||
| -rw-r--r-- | src/unit/file.cpp | 117 | ||||
| -rw-r--r-- | src/unit/file.unit | 95 | ||||
| -rw-r--r-- | src/unit/fstring.cpp | 170 | ||||
| -rw-r--r-- | src/unit/fstring.unit | 140 | ||||
| -rw-r--r-- | src/unit/hash.cpp | 109 | ||||
| -rw-r--r-- | src/unit/hash.unit | 86 | ||||
| -rw-r--r-- | src/unit/membuf.cpp | 60 | ||||
| -rw-r--r-- | src/unit/membuf.unit | 45 | ||||
| -rw-r--r-- | src/unit/taf.cpp | 133 | ||||
| -rw-r--r-- | src/unit/taf.unit | 112 | ||||
| -rw-r--r-- | src/unit/xml.cpp | 39 | ||||
| -rw-r--r-- | src/unit/xml.unit | 20 | ||||
| -rw-r--r-- | src/unitsuite.cpp | 2 | ||||
| -rw-r--r-- | src/unitsuite.h | 8 |
18 files changed, 716 insertions, 876 deletions
diff --git a/src/unit/archive.cpp b/src/unit/archive.cpp deleted file mode 100644 index 8e71f4b..0000000 --- a/src/unit/archive.cpp +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/unitsuite.h" | ||
| 9 | #include "bu/membuf.h" | ||
| 10 | |||
| 11 | class Unit : public Bu::UnitSuite | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | Unit() | ||
| 15 | { | ||
| 16 | setName("Archive"); | ||
| 17 | addTest( Unit::testPrimitives ); | ||
| 18 | addTest( Unit::testContainers ); | ||
| 19 | } | ||
| 20 | |||
| 21 | virtual ~Unit() | ||
| 22 | { | ||
| 23 | } | ||
| 24 | |||
| 25 | void testPrimitives() | ||
| 26 | { | ||
| 27 | Bu::MemBuf mb; | ||
| 28 | { | ||
| 29 | Bu::Archive ar( mb, Bu::Archive::save ); | ||
| 30 | ar << (int8_t)1; | ||
| 31 | ar << (uint8_t)2; | ||
| 32 | ar << (int16_t)3; | ||
| 33 | ar << (uint16_t)4; | ||
| 34 | ar << (int32_t)5; | ||
| 35 | ar << (uint32_t)6; | ||
| 36 | ar << (int64_t)7; | ||
| 37 | ar << (uint64_t)8; | ||
| 38 | ar << (char)9; | ||
| 39 | ar << (unsigned char)10; | ||
| 40 | ar << (short)11; | ||
| 41 | ar << (unsigned short)12; | ||
| 42 | ar << (int)13; | ||
| 43 | ar << (unsigned int)14; | ||
| 44 | ar << (long)15; | ||
| 45 | ar << (unsigned long)16; | ||
| 46 | ar << (long long)17; | ||
| 47 | ar << (unsigned long long)18; | ||
| 48 | ar.close(); | ||
| 49 | } | ||
| 50 | mb.setPos( 0 ); | ||
| 51 | { | ||
| 52 | Bu::Archive ar( mb, Bu::Archive::load ); | ||
| 53 | int8_t p1; | ||
| 54 | uint8_t p2; | ||
| 55 | int16_t p3; | ||
| 56 | uint16_t p4; | ||
| 57 | int32_t p5; | ||
| 58 | uint32_t p6; | ||
| 59 | int64_t p7; | ||
| 60 | uint64_t p8; | ||
| 61 | char p9; | ||
| 62 | unsigned char p10; | ||
| 63 | short p11; | ||
| 64 | unsigned short p12; | ||
| 65 | int p13; | ||
| 66 | unsigned int p14; | ||
| 67 | long p15; | ||
| 68 | unsigned long p16; | ||
| 69 | long long p17; | ||
| 70 | unsigned long long p18; | ||
| 71 | ar >> p1; | ||
| 72 | ar >> p2; | ||
| 73 | ar >> p3; | ||
| 74 | ar >> p4; | ||
| 75 | ar >> p5; | ||
| 76 | ar >> p6; | ||
| 77 | ar >> p7; | ||
| 78 | ar >> p8; | ||
| 79 | ar >> p9; | ||
| 80 | ar >> p10; | ||
| 81 | ar >> p11; | ||
| 82 | ar >> p12; | ||
| 83 | ar >> p13; | ||
| 84 | ar >> p14; | ||
| 85 | ar >> p15; | ||
| 86 | ar >> p16; | ||
| 87 | ar >> p17; | ||
| 88 | ar >> p18; | ||
| 89 | unitTest( p1 == 1 ); | ||
| 90 | unitTest( p2 == 2 ); | ||
| 91 | unitTest( p3 == 3 ); | ||
| 92 | unitTest( p4 == 4 ); | ||
| 93 | unitTest( p5 == 5 ); | ||
| 94 | unitTest( p6 == 6 ); | ||
| 95 | unitTest( p7 == 7 ); | ||
| 96 | unitTest( p8 == 8 ); | ||
| 97 | unitTest( p9 == 9 ); | ||
| 98 | unitTest( p10 == 10 ); | ||
| 99 | unitTest( p11 == 11 ); | ||
| 100 | unitTest( p12 == 12 ); | ||
| 101 | unitTest( p13 == 13 ); | ||
| 102 | unitTest( p14 == 14 ); | ||
| 103 | unitTest( p15 == 15 ); | ||
| 104 | unitTest( p16 == 16 ); | ||
| 105 | unitTest( p17 == 17 ); | ||
| 106 | unitTest( p18 == 18 ); | ||
| 107 | ar.close(); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | void testContainers() | ||
| 112 | { | ||
| 113 | Bu::MemBuf mb; | ||
| 114 | { | ||
| 115 | Bu::Archive ar( mb, Bu::Archive::save ); | ||
| 116 | Bu::FString sStr("This is a test string."); | ||
| 117 | Bu::List<int> lList; | ||
| 118 | lList.append( 10 ); | ||
| 119 | lList.append( 20 ); | ||
| 120 | lList.append( 30 ); | ||
| 121 | lList.append( 40 ); | ||
| 122 | ar << sStr; | ||
| 123 | ar << lList; | ||
| 124 | ar.close(); | ||
| 125 | } | ||
| 126 | mb.setPos( 0 ); | ||
| 127 | { | ||
| 128 | Bu::Archive ar( mb, Bu::Archive::load ); | ||
| 129 | Bu::FString sStr; | ||
| 130 | Bu::List<int> lList; | ||
| 131 | ar >> sStr; | ||
| 132 | ar >> lList; | ||
| 133 | unitTest( sStr == "This is a test string." ); | ||
| 134 | unitTest( lList.getSize() == 4 ); | ||
| 135 | Bu::List<int>::iterator i = lList.begin(); | ||
| 136 | unitTest( *i == 10 ); i++; | ||
| 137 | unitTest( *i == 20 ); i++; | ||
| 138 | unitTest( *i == 30 ); i++; | ||
| 139 | unitTest( *i == 40 ); | ||
| 140 | ar.close(); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | }; | ||
| 144 | |||
| 145 | int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } | ||
diff --git a/src/unit/archive.unit b/src/unit/archive.unit new file mode 100644 index 0000000..ecc589b --- /dev/null +++ b/src/unit/archive.unit | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/membuf.h" | ||
| 10 | |||
| 11 | {=Init} | ||
| 12 | |||
| 13 | {%testPrimitives} | ||
| 14 | { | ||
| 15 | Bu::MemBuf mb; | ||
| 16 | { | ||
| 17 | Bu::Archive ar( mb, Bu::Archive::save ); | ||
| 18 | ar << (int8_t)1; | ||
| 19 | ar << (uint8_t)2; | ||
| 20 | ar << (int16_t)3; | ||
| 21 | ar << (uint16_t)4; | ||
| 22 | ar << (int32_t)5; | ||
| 23 | ar << (uint32_t)6; | ||
| 24 | ar << (int64_t)7; | ||
| 25 | ar << (uint64_t)8; | ||
| 26 | ar << (char)9; | ||
| 27 | ar << (unsigned char)10; | ||
| 28 | ar << (short)11; | ||
| 29 | ar << (unsigned short)12; | ||
| 30 | ar << (int)13; | ||
| 31 | ar << (unsigned int)14; | ||
| 32 | ar << (long)15; | ||
| 33 | ar << (unsigned long)16; | ||
| 34 | ar << (long long)17; | ||
| 35 | ar << (unsigned long long)18; | ||
| 36 | ar.close(); | ||
| 37 | } | ||
| 38 | mb.setPos( 0 ); | ||
| 39 | { | ||
| 40 | Bu::Archive ar( mb, Bu::Archive::load ); | ||
| 41 | int8_t p1; | ||
| 42 | uint8_t p2; | ||
| 43 | int16_t p3; | ||
| 44 | uint16_t p4; | ||
| 45 | int32_t p5; | ||
| 46 | uint32_t p6; | ||
| 47 | int64_t p7; | ||
| 48 | uint64_t p8; | ||
| 49 | char p9; | ||
| 50 | unsigned char p10; | ||
| 51 | short p11; | ||
| 52 | unsigned short p12; | ||
| 53 | int p13; | ||
| 54 | unsigned int p14; | ||
| 55 | long p15; | ||
| 56 | unsigned long p16; | ||
| 57 | long long p17; | ||
| 58 | unsigned long long p18; | ||
| 59 | ar >> p1; | ||
| 60 | ar >> p2; | ||
| 61 | ar >> p3; | ||
| 62 | ar >> p4; | ||
| 63 | ar >> p5; | ||
| 64 | ar >> p6; | ||
| 65 | ar >> p7; | ||
| 66 | ar >> p8; | ||
| 67 | ar >> p9; | ||
| 68 | ar >> p10; | ||
| 69 | ar >> p11; | ||
| 70 | ar >> p12; | ||
| 71 | ar >> p13; | ||
| 72 | ar >> p14; | ||
| 73 | ar >> p15; | ||
| 74 | ar >> p16; | ||
| 75 | ar >> p17; | ||
| 76 | ar >> p18; | ||
| 77 | unitTest( p1 == 1 ); | ||
| 78 | unitTest( p2 == 2 ); | ||
| 79 | unitTest( p3 == 3 ); | ||
| 80 | unitTest( p4 == 4 ); | ||
| 81 | unitTest( p5 == 5 ); | ||
| 82 | unitTest( p6 == 6 ); | ||
| 83 | unitTest( p7 == 7 ); | ||
| 84 | unitTest( p8 == 8 ); | ||
| 85 | unitTest( p9 == 9 ); | ||
| 86 | unitTest( p10 == 10 ); | ||
| 87 | unitTest( p11 == 11 ); | ||
| 88 | unitTest( p12 == 12 ); | ||
| 89 | unitTest( p13 == 13 ); | ||
| 90 | unitTest( p14 == 14 ); | ||
| 91 | unitTest( p15 == 15 ); | ||
| 92 | unitTest( p16 == 16 ); | ||
| 93 | unitTest( p17 == 17 ); | ||
| 94 | unitTest( p18 == 18 ); | ||
| 95 | ar.close(); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | {%testContainers} | ||
| 100 | { | ||
| 101 | Bu::MemBuf mb; | ||
| 102 | { | ||
| 103 | Bu::Archive ar( mb, Bu::Archive::save ); | ||
| 104 | Bu::FString sStr("This is a test string."); | ||
| 105 | Bu::List<int> lList; | ||
| 106 | lList.append( 10 ); | ||
| 107 | lList.append( 20 ); | ||
| 108 | lList.append( 30 ); | ||
| 109 | lList.append( 40 ); | ||
| 110 | ar << sStr; | ||
| 111 | ar << lList; | ||
| 112 | ar.close(); | ||
| 113 | } | ||
| 114 | mb.setPos( 0 ); | ||
| 115 | { | ||
| 116 | Bu::Archive ar( mb, Bu::Archive::load ); | ||
| 117 | Bu::FString sStr; | ||
| 118 | Bu::List<int> lList; | ||
| 119 | ar >> sStr; | ||
| 120 | ar >> lList; | ||
| 121 | unitTest( sStr == "This is a test string." ); | ||
| 122 | unitTest( lList.getSize() == 4 ); | ||
| 123 | Bu::List<int>::iterator i = lList.begin(); | ||
| 124 | unitTest( *i == 10 ); i++; | ||
| 125 | unitTest( *i == 20 ); i++; | ||
| 126 | unitTest( *i == 30 ); i++; | ||
| 127 | unitTest( *i == 40 ); | ||
| 128 | ar.close(); | ||
| 129 | } | ||
| 130 | } | ||
diff --git a/src/unit/array.cpp b/src/unit/array.cpp deleted file mode 100644 index f7dc0ae..0000000 --- a/src/unit/array.cpp +++ /dev/null | |||
| @@ -1,101 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/unitsuite.h" | ||
| 9 | #include "bu/hash.h" | ||
| 10 | #include "bu/array.h" | ||
| 11 | |||
| 12 | class Unit : public Bu::UnitSuite | ||
| 13 | { | ||
| 14 | public: | ||
| 15 | Unit() | ||
| 16 | { | ||
| 17 | setName("Array"); | ||
| 18 | addTest( Unit::general ); | ||
| 19 | addTest( Unit::iterate1 ); | ||
| 20 | addTest( Unit::iterate2 ); | ||
| 21 | addTest( Unit::copy ); | ||
| 22 | } | ||
| 23 | |||
| 24 | virtual ~Unit() | ||
| 25 | { | ||
| 26 | } | ||
| 27 | |||
| 28 | void general() | ||
| 29 | { | ||
| 30 | Bu::Array<int> ai; | ||
| 31 | |||
| 32 | ai.append( 5 ); | ||
| 33 | ai.append( 10 ); | ||
| 34 | unitTest( ai.getSize() == 2 ); | ||
| 35 | unitTest( ai.getCapacity() == 10 ); | ||
| 36 | unitTest( ai[0] == 5 ); | ||
| 37 | unitTest( ai[1] == 10 ); | ||
| 38 | } | ||
| 39 | |||
| 40 | void iterate1() | ||
| 41 | { | ||
| 42 | Bu::Array<int> ai; | ||
| 43 | for( int j = 0; j < 10; j++ ) | ||
| 44 | ai.append( j ); | ||
| 45 | |||
| 46 | int j = 0; | ||
| 47 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 48 | unitTest( (*i) == j++ ); | ||
| 49 | |||
| 50 | const Bu::Array<int> &ci = ai; | ||
| 51 | j = 0; | ||
| 52 | for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ ) | ||
| 53 | unitTest( (*i) == j++ ); | ||
| 54 | } | ||
| 55 | |||
| 56 | void iterate2() | ||
| 57 | { | ||
| 58 | Bu::Array<int> ai; | ||
| 59 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 60 | unitFailed("Empty lists shouldn't be iterated through."); | ||
| 61 | } | ||
| 62 | |||
| 63 | void copy() | ||
| 64 | { | ||
| 65 | typedef Bu::Hash<Bu::FString, Bu::FString> StrHash; | ||
| 66 | typedef Bu::Array<StrHash> StrHashArray; | ||
| 67 | |||
| 68 | StrHash h1; | ||
| 69 | h1["Hi"] = "Yo"; | ||
| 70 | h1["Bye"] = "Later"; | ||
| 71 | |||
| 72 | StrHash h2; | ||
| 73 | h2["Test"] = "Bloop"; | ||
| 74 | h2["Foo"] = "ooF"; | ||
| 75 | |||
| 76 | StrHashArray a1; | ||
| 77 | a1.append( h1 ); | ||
| 78 | a1.append( h2 ); | ||
| 79 | |||
| 80 | StrHashArray a2(a1); | ||
| 81 | |||
| 82 | unitTest( a2[0].get("Hi") == "Yo" ); | ||
| 83 | unitTest( a2[0].get("Bye") == "Later" ); | ||
| 84 | unitTest( a2[1].get("Test") == "Bloop" ); | ||
| 85 | unitTest( a2[1].get("Foo") == "ooF" ); | ||
| 86 | |||
| 87 | StrHashArray a3; | ||
| 88 | a3 = a1; | ||
| 89 | |||
| 90 | unitTest( a3[0].get("Hi") == "Yo" ); | ||
| 91 | unitTest( a3[0].get("Bye") == "Later" ); | ||
| 92 | unitTest( a3[1].get("Test") == "Bloop" ); | ||
| 93 | unitTest( a3[1].get("Foo") == "ooF" ); | ||
| 94 | } | ||
| 95 | }; | ||
| 96 | |||
| 97 | int main( int argc, char *argv[] ) | ||
| 98 | { | ||
| 99 | return Unit().run( argc, argv ); | ||
| 100 | } | ||
| 101 | |||
diff --git a/src/unit/array.unit b/src/unit/array.unit new file mode 100644 index 0000000..d5fc573 --- /dev/null +++ b/src/unit/array.unit | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/hash.h" | ||
| 10 | #include "bu/array.h" | ||
| 11 | |||
| 12 | {=Init} | ||
| 13 | |||
| 14 | {%general} | ||
| 15 | { | ||
| 16 | Bu::Array<int> ai; | ||
| 17 | |||
| 18 | ai.append( 5 ); | ||
| 19 | ai.append( 10 ); | ||
| 20 | unitTest( ai.getSize() == 2 ); | ||
| 21 | unitTest( ai.getCapacity() == 10 ); | ||
| 22 | unitTest( ai[0] == 5 ); | ||
| 23 | unitTest( ai[1] == 10 ); | ||
| 24 | } | ||
| 25 | |||
| 26 | {%iterate1} | ||
| 27 | { | ||
| 28 | Bu::Array<int> ai; | ||
| 29 | for( int j = 0; j < 10; j++ ) | ||
| 30 | ai.append( j ); | ||
| 31 | |||
| 32 | int j = 0; | ||
| 33 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 34 | unitTest( (*i) == j++ ); | ||
| 35 | |||
| 36 | const Bu::Array<int> &ci = ai; | ||
| 37 | j = 0; | ||
| 38 | for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ ) | ||
| 39 | unitTest( (*i) == j++ ); | ||
| 40 | } | ||
| 41 | |||
| 42 | {%iterate2} | ||
| 43 | { | ||
| 44 | Bu::Array<int> ai; | ||
| 45 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 46 | unitFailed("Empty lists shouldn't be iterated through."); | ||
| 47 | } | ||
| 48 | |||
| 49 | {%copy} | ||
| 50 | { | ||
| 51 | typedef Bu::Hash<Bu::FString, Bu::FString> StrHash; | ||
| 52 | typedef Bu::Array<StrHash> StrHashArray; | ||
| 53 | |||
| 54 | StrHash h1; | ||
| 55 | h1["Hi"] = "Yo"; | ||
| 56 | h1["Bye"] = "Later"; | ||
| 57 | |||
| 58 | StrHash h2; | ||
| 59 | h2["Test"] = "Bloop"; | ||
| 60 | h2["Foo"] = "ooF"; | ||
| 61 | |||
| 62 | StrHashArray a1; | ||
| 63 | a1.append( h1 ); | ||
| 64 | a1.append( h2 ); | ||
| 65 | |||
| 66 | StrHashArray a2(a1); | ||
| 67 | |||
| 68 | unitTest( a2[0].get("Hi") == "Yo" ); | ||
| 69 | unitTest( a2[0].get("Bye") == "Later" ); | ||
| 70 | unitTest( a2[1].get("Test") == "Bloop" ); | ||
| 71 | unitTest( a2[1].get("Foo") == "ooF" ); | ||
| 72 | |||
| 73 | StrHashArray a3; | ||
| 74 | a3 = a1; | ||
| 75 | |||
| 76 | unitTest( a3[0].get("Hi") == "Yo" ); | ||
| 77 | unitTest( a3[0].get("Bye") == "Later" ); | ||
| 78 | unitTest( a3[1].get("Test") == "Bloop" ); | ||
| 79 | unitTest( a3[1].get("Foo") == "ooF" ); | ||
| 80 | } | ||
diff --git a/src/unit/file.cpp b/src/unit/file.cpp deleted file mode 100644 index cc19fac..0000000 --- a/src/unit/file.cpp +++ /dev/null | |||
| @@ -1,117 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/unitsuite.h" | ||
| 9 | #include "bu/file.h" | ||
| 10 | |||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/stat.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | class Unit : public Bu::UnitSuite | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | Unit() | ||
| 19 | { | ||
| 20 | setName("File"); | ||
| 21 | addTest( Unit::writeFull ); | ||
| 22 | addTest( Unit::readBlocks ); | ||
| 23 | addTest( Unit::readError1 ); | ||
| 24 | addTest( Unit::readError2 ); | ||
| 25 | } | ||
| 26 | |||
| 27 | virtual ~Unit() { } | ||
| 28 | |||
| 29 | // | ||
| 30 | // Tests go here | ||
| 31 | // | ||
| 32 | void writeFull() | ||
| 33 | { | ||
| 34 | Bu::File sf("testfile1", Bu::File::Write ); | ||
| 35 | for( int c = 0; c < 256; c++ ) | ||
| 36 | { | ||
| 37 | unsigned char ch = (unsigned char)c; | ||
| 38 | sf.write( &ch, 1 ); | ||
| 39 | unitTest( sf.tell() == c+1 ); | ||
| 40 | } | ||
| 41 | //unitTest( sf.canRead() == false ); | ||
| 42 | //unitTest( sf.canWrite() == true ); | ||
| 43 | //unitTest( sf.canSeek() == true ); | ||
| 44 | sf.close(); | ||
| 45 | struct stat sdat; | ||
| 46 | stat("testfile1", &sdat ); | ||
| 47 | unitTest( sdat.st_size == 256 ); | ||
| 48 | } | ||
| 49 | |||
| 50 | void readBlocks() | ||
| 51 | { | ||
| 52 | Bu::File sf("testfile1", Bu::File::Read ); | ||
| 53 | unsigned char buf[50]; | ||
| 54 | size_t total = 0; | ||
| 55 | for(;;) | ||
| 56 | { | ||
| 57 | size_t s = sf.read( buf, 50 ); | ||
| 58 | for( size_t c = 0; c < s; c++ ) | ||
| 59 | { | ||
| 60 | unitTest( buf[c] == (unsigned char)(c+total) ); | ||
| 61 | } | ||
| 62 | total += s; | ||
| 63 | if( s < 50 ) | ||
| 64 | { | ||
| 65 | unitTest( total == 256 ); | ||
| 66 | unitTest( sf.isEOS() == true ); | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | sf.close(); | ||
| 71 | } | ||
| 72 | |||
| 73 | void readError1() | ||
| 74 | { | ||
| 75 | try | ||
| 76 | { | ||
| 77 | Bu::File sf("doesn'texist", Bu::File::Read ); | ||
| 78 | unitFailed("No exception thrown"); | ||
| 79 | } | ||
| 80 | catch( Bu::FileException &e ) | ||
| 81 | { | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | void readError2() | ||
| 87 | { | ||
| 88 | Bu::File sf("testfile1", Bu::File::Read ); | ||
| 89 | char buf[256]; | ||
| 90 | int r = sf.read( buf, 256 ); | ||
| 91 | unitTest( r == 256 ); | ||
| 92 | // You have to read past the end to set the EOS flag. | ||
| 93 | unitTest( sf.isEOS() == false ); | ||
| 94 | try | ||
| 95 | { | ||
| 96 | if( sf.read( buf, 5 ) > 0 ) | ||
| 97 | { | ||
| 98 | unitFailed("Non-zero read result"); | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | sf.close(); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | catch( Bu::FileException &e ) | ||
| 106 | { | ||
| 107 | sf.close(); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | }; | ||
| 112 | |||
| 113 | int main( int argc, char *argv[] ) | ||
| 114 | { | ||
| 115 | return Unit().run( argc, argv ); | ||
| 116 | } | ||
| 117 | |||
diff --git a/src/unit/file.unit b/src/unit/file.unit new file mode 100644 index 0000000..e6320ad --- /dev/null +++ b/src/unit/file.unit | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/file.h" | ||
| 10 | |||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/stat.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | {=Init} | ||
| 16 | |||
| 17 | {%writeFull} | ||
| 18 | { | ||
| 19 | Bu::File sf("testfile1", Bu::File::Write ); | ||
| 20 | for( int c = 0; c < 256; c++ ) | ||
| 21 | { | ||
| 22 | unsigned char ch = (unsigned char)c; | ||
| 23 | sf.write( &ch, 1 ); | ||
| 24 | unitTest( sf.tell() == c+1 ); | ||
| 25 | } | ||
| 26 | //unitTest( sf.canRead() == false ); | ||
| 27 | //unitTest( sf.canWrite() == true ); | ||
| 28 | //unitTest( sf.canSeek() == true ); | ||
| 29 | sf.close(); | ||
| 30 | struct stat sdat; | ||
| 31 | stat("testfile1", &sdat ); | ||
| 32 | unitTest( sdat.st_size == 256 ); | ||
| 33 | } | ||
| 34 | |||
| 35 | {%readBlocks} | ||
| 36 | { | ||
| 37 | Bu::File sf("testfile1", Bu::File::Read ); | ||
| 38 | unsigned char buf[50]; | ||
| 39 | size_t total = 0; | ||
| 40 | for(;;) | ||
| 41 | { | ||
| 42 | size_t s = sf.read( buf, 50 ); | ||
| 43 | for( size_t c = 0; c < s; c++ ) | ||
| 44 | { | ||
| 45 | unitTest( buf[c] == (unsigned char)(c+total) ); | ||
| 46 | } | ||
| 47 | total += s; | ||
| 48 | if( s < 50 ) | ||
| 49 | { | ||
| 50 | unitTest( total == 256 ); | ||
| 51 | unitTest( sf.isEOS() == true ); | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | sf.close(); | ||
| 56 | } | ||
| 57 | |||
| 58 | {%readError1} | ||
| 59 | { | ||
| 60 | try | ||
| 61 | { | ||
| 62 | Bu::File sf("doesn'texist", Bu::File::Read ); | ||
| 63 | unitFailed("No exception thrown"); | ||
| 64 | } | ||
| 65 | catch( Bu::FileException &e ) | ||
| 66 | { | ||
| 67 | return; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | {%readError2} | ||
| 72 | { | ||
| 73 | Bu::File sf("testfile1", Bu::File::Read ); | ||
| 74 | char buf[256]; | ||
| 75 | int r = sf.read( buf, 256 ); | ||
| 76 | unitTest( r == 256 ); | ||
| 77 | // You have to read past the end to set the EOS flag. | ||
| 78 | unitTest( sf.isEOS() == false ); | ||
| 79 | try | ||
| 80 | { | ||
| 81 | if( sf.read( buf, 5 ) > 0 ) | ||
| 82 | { | ||
| 83 | unitFailed("Non-zero read result"); | ||
| 84 | } | ||
| 85 | else | ||
| 86 | { | ||
| 87 | sf.close(); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | catch( Bu::FileException &e ) | ||
| 91 | { | ||
| 92 | sf.close(); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | } | ||
diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp deleted file mode 100644 index 9430a83..0000000 --- a/src/unit/fstring.cpp +++ /dev/null | |||
| @@ -1,170 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/fstring.h" | ||
| 9 | #include "bu/unitsuite.h" | ||
| 10 | |||
| 11 | #include <dirent.h> | ||
| 12 | |||
| 13 | class Unit : public Bu::UnitSuite | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | Unit() | ||
| 17 | { | ||
| 18 | setName("FString"); | ||
| 19 | addTest( Unit::compare1 ); | ||
| 20 | addTest( Unit::compare2 ); | ||
| 21 | addTest( Unit::appendSingle ); | ||
| 22 | addTest( Unit::shared1 ); | ||
| 23 | addTest( Unit::insert ); | ||
| 24 | addTest( Unit::remove ); | ||
| 25 | addTest( Unit::add1 ); | ||
| 26 | addTest( Unit::add2 ); | ||
| 27 | addTest( Unit::add3 ); | ||
| 28 | addTest( Unit::add4 ); | ||
| 29 | addTest( Unit::add5 ); | ||
| 30 | addTest( Unit::add6 ); | ||
| 31 | addTest( Unit::subStr1 ); | ||
| 32 | } | ||
| 33 | |||
| 34 | virtual ~Unit() | ||
| 35 | { | ||
| 36 | } | ||
| 37 | |||
| 38 | void compare1() | ||
| 39 | { | ||
| 40 | Bu::FString b("Bob"); | ||
| 41 | unitTest( !(b == "Bobo") ); | ||
| 42 | unitTest( b == "Bob" ); | ||
| 43 | } | ||
| 44 | |||
| 45 | void compare2() | ||
| 46 | { | ||
| 47 | Bu::FString b("Bobo"); | ||
| 48 | unitTest( !(b == "Bob") ); | ||
| 49 | unitTest( b == "Bobo" ); | ||
| 50 | } | ||
| 51 | |||
| 52 | void appendSingle() | ||
| 53 | { | ||
| 54 | Bu::FString b; | ||
| 55 | for( char l = 'a'; l < 'g'; l++ ) | ||
| 56 | b += l; | ||
| 57 | unitTest( b == "abcdef" ); | ||
| 58 | unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); | ||
| 59 | } | ||
| 60 | |||
| 61 | void shared1() | ||
| 62 | { | ||
| 63 | Bu::FString a("Hey there"); | ||
| 64 | Bu::FString b( a ); | ||
| 65 | unitTest( a.getStr() == b.getStr() ); | ||
| 66 | b += " guy"; | ||
| 67 | unitTest( a.getStr() != b.getStr() ); | ||
| 68 | a = b; | ||
| 69 | unitTest( a.getStr() == b.getStr() ); | ||
| 70 | } | ||
| 71 | |||
| 72 | void insert() | ||
| 73 | { | ||
| 74 | Bu::FString a("abcd"); | ||
| 75 | a.insert( 2, "-!-", 3 ); | ||
| 76 | unitTest( a == "ab-!-cd" ); | ||
| 77 | |||
| 78 | a.insert( 0, "!!", 2 ); | ||
| 79 | unitTest( a == "!!ab-!-cd" ); | ||
| 80 | |||
| 81 | a.insert( -10, "789", 3 ); | ||
| 82 | unitTest( a == "789!!ab-!-cd" ); | ||
| 83 | |||
| 84 | a.insert( 12, "89", 2 ); | ||
| 85 | unitTest( a == "789!!ab-!-cd89" ); | ||
| 86 | |||
| 87 | a.insert( 1203, "12", 2 ); | ||
| 88 | unitTest( a == "789!!ab-!-cd8912" ); | ||
| 89 | } | ||
| 90 | |||
| 91 | void remove() | ||
| 92 | { | ||
| 93 | Bu::FString a("abHEYcd"); | ||
| 94 | a.remove( 2, 3 ); | ||
| 95 | unitTest( a == "abcd" ); | ||
| 96 | a.remove( 2, 5 ); | ||
| 97 | unitTest( a == "ab" ); | ||
| 98 | a += "cdefghijklmnop"; | ||
| 99 | a.remove( 5, 1 ); | ||
| 100 | unitTest( a = "abcdeghijklmnop" ); | ||
| 101 | } | ||
| 102 | |||
| 103 | void add1() | ||
| 104 | { | ||
| 105 | Bu::FString a("hi there"); | ||
| 106 | Bu::FString b(", yeah!"); | ||
| 107 | Bu::FString c = a + b; | ||
| 108 | |||
| 109 | unitTest( c == "hi there, yeah!" ); | ||
| 110 | } | ||
| 111 | |||
| 112 | void add2() | ||
| 113 | { | ||
| 114 | Bu::FString a("hi there"); | ||
| 115 | Bu::FString c = a + ", yeah!"; | ||
| 116 | |||
| 117 | unitTest( c == "hi there, yeah!" ); | ||
| 118 | } | ||
| 119 | |||
| 120 | void add3() | ||
| 121 | { | ||
| 122 | Bu::FString a("hi there"); | ||
| 123 | Bu::FString b(", yeah!"); | ||
| 124 | Bu::FString c = a + ", Mr. Man" + b; | ||
| 125 | |||
| 126 | unitTest( c == "hi there, Mr. Man, yeah!" ); | ||
| 127 | } | ||
| 128 | |||
| 129 | void add4() | ||
| 130 | { | ||
| 131 | Bu::FString b(", yeah!"); | ||
| 132 | Bu::FString c = "hi there" + b; | ||
| 133 | |||
| 134 | unitTest( c == "hi there, yeah!" ); | ||
| 135 | } | ||
| 136 | |||
| 137 | void add5() | ||
| 138 | { | ||
| 139 | Bu::FString b; | ||
| 140 | Bu::FString c = "sup?"; | ||
| 141 | b += "hey, " + c; | ||
| 142 | |||
| 143 | unitTest( b == "hey, sup?" ); | ||
| 144 | } | ||
| 145 | |||
| 146 | void add6() | ||
| 147 | { | ||
| 148 | Bu::FString a("Hello"); | ||
| 149 | char b[256] = {"Dude"}; | ||
| 150 | Bu::FString c = a + "/" + b; | ||
| 151 | |||
| 152 | unitTest( c == "Hello/Dude" ); | ||
| 153 | } | ||
| 154 | |||
| 155 | void subStr1() | ||
| 156 | { | ||
| 157 | Bu::FString a("abcdefghijklmnop"); | ||
| 158 | unitTest( a.getSubStr( 5, 3 ) == "fgh" ); | ||
| 159 | unitTest( a.getSubStr( 10 ) == "klmnop" ); | ||
| 160 | unitTest( a.getSubStr( 40 ) == "" ); | ||
| 161 | unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); | ||
| 162 | unitTest( a.getSubStr( -15, 4 ) == "abcd" ); | ||
| 163 | } | ||
| 164 | }; | ||
| 165 | |||
| 166 | int main( int argc, char *argv[] ) | ||
| 167 | { | ||
| 168 | return Unit().run( argc, argv ); | ||
| 169 | } | ||
| 170 | |||
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit new file mode 100644 index 0000000..93065fe --- /dev/null +++ b/src/unit/fstring.unit | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/fstring.h" | ||
| 10 | |||
| 11 | #include <dirent.h> | ||
| 12 | |||
| 13 | {=Init} | ||
| 14 | |||
| 15 | {%compare1} | ||
| 16 | { | ||
| 17 | Bu::FString b("Bob"); | ||
| 18 | unitTest( !(b == "Bobo") ); | ||
| 19 | unitTest( b == "Bob" ); | ||
| 20 | } | ||
| 21 | |||
| 22 | {%compare2} | ||
| 23 | { | ||
| 24 | Bu::FString b("Bobo"); | ||
| 25 | unitTest( !(b == "Bob") ); | ||
| 26 | unitTest( b == "Bobo" ); | ||
| 27 | } | ||
| 28 | |||
| 29 | {%appendSingle} | ||
| 30 | { | ||
| 31 | Bu::FString b; | ||
| 32 | for( char l = 'a'; l < 'g'; l++ ) | ||
| 33 | b += l; | ||
| 34 | unitTest( b == "abcdef" ); | ||
| 35 | unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); | ||
| 36 | } | ||
| 37 | |||
| 38 | {%shared1} | ||
| 39 | { | ||
| 40 | Bu::FString a("Hey there"); | ||
| 41 | Bu::FString b( a ); | ||
| 42 | unitTest( a.getStr() == b.getStr() ); | ||
| 43 | b += " guy"; | ||
| 44 | unitTest( a.getStr() != b.getStr() ); | ||
| 45 | a = b; | ||
| 46 | unitTest( a.getStr() == b.getStr() ); | ||
| 47 | } | ||
| 48 | |||
| 49 | {%insert} | ||
| 50 | { | ||
| 51 | Bu::FString a("abcd"); | ||
| 52 | a.insert( 2, "-!-", 3 ); | ||
| 53 | unitTest( a == "ab-!-cd" ); | ||
| 54 | |||
| 55 | a.insert( 0, "!!", 2 ); | ||
| 56 | unitTest( a == "!!ab-!-cd" ); | ||
| 57 | |||
| 58 | a.insert( -10, "789", 3 ); | ||
| 59 | unitTest( a == "789!!ab-!-cd" ); | ||
| 60 | |||
| 61 | a.insert( 12, "89", 2 ); | ||
| 62 | unitTest( a == "789!!ab-!-cd89" ); | ||
| 63 | |||
| 64 | a.insert( 1203, "12", 2 ); | ||
| 65 | unitTest( a == "789!!ab-!-cd8912" ); | ||
| 66 | } | ||
| 67 | |||
| 68 | {%remove} | ||
| 69 | { | ||
| 70 | Bu::FString a("abHEYcd"); | ||
| 71 | a.remove( 2, 3 ); | ||
| 72 | unitTest( a == "abcd" ); | ||
| 73 | a.remove( 2, 5 ); | ||
| 74 | unitTest( a == "ab" ); | ||
| 75 | a += "cdefghijklmnop"; | ||
| 76 | a.remove( 5, 1 ); | ||
| 77 | unitTest( a = "abcdeghijklmnop" ); | ||
| 78 | } | ||
| 79 | |||
| 80 | {%add1} | ||
| 81 | { | ||
| 82 | Bu::FString a("hi there"); | ||
| 83 | Bu::FString b(", yeah!"); | ||
| 84 | Bu::FString c = a + b; | ||
| 85 | |||
| 86 | unitTest( c == "hi there, yeah!" ); | ||
| 87 | } | ||
| 88 | |||
| 89 | {%add2} | ||
| 90 | { | ||
| 91 | Bu::FString a("hi there"); | ||
| 92 | Bu::FString c = a + ", yeah!"; | ||
| 93 | |||
| 94 | unitTest( c == "hi there, yeah!" ); | ||
| 95 | } | ||
| 96 | |||
| 97 | {%add3} | ||
| 98 | { | ||
| 99 | Bu::FString a("hi there"); | ||
| 100 | Bu::FString b(", yeah!"); | ||
| 101 | Bu::FString c = a + ", Mr. Man" + b; | ||
| 102 | |||
| 103 | unitTest( c == "hi there, Mr. Man, yeah!" ); | ||
| 104 | } | ||
| 105 | |||
| 106 | {%add4} | ||
| 107 | { | ||
| 108 | Bu::FString b(", yeah!"); | ||
| 109 | Bu::FString c = "hi there" + b; | ||
| 110 | |||
| 111 | unitTest( c == "hi there, yeah!" ); | ||
| 112 | } | ||
| 113 | |||
| 114 | {%add5} | ||
| 115 | { | ||
| 116 | Bu::FString b; | ||
| 117 | Bu::FString c = "sup?"; | ||
| 118 | b += "hey, " + c; | ||
| 119 | |||
| 120 | unitTest( b == "hey, sup?" ); | ||
| 121 | } | ||
| 122 | |||
| 123 | {%add6} | ||
| 124 | { | ||
| 125 | Bu::FString a("Hello"); | ||
| 126 | char b[256] = {"Dude"}; | ||
| 127 | Bu::FString c = a + "/" + b; | ||
| 128 | |||
| 129 | unitTest( c == "Hello/Dude" ); | ||
| 130 | } | ||
| 131 | |||
| 132 | {%subStr1} | ||
| 133 | { | ||
| 134 | Bu::FString a("abcdefghijklmnop"); | ||
| 135 | unitTest( a.getSubStr( 5, 3 ) == "fgh" ); | ||
| 136 | unitTest( a.getSubStr( 10 ) == "klmnop" ); | ||
| 137 | unitTest( a.getSubStr( 40 ) == "" ); | ||
| 138 | unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); | ||
| 139 | unitTest( a.getSubStr( -15, 4 ) == "abcd" ); | ||
| 140 | } | ||
diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp deleted file mode 100644 index e04a656..0000000 --- a/src/unit/hash.cpp +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/fstring.h" | ||
| 9 | #include "bu/hash.h" | ||
| 10 | #include "bu/unitsuite.h" | ||
| 11 | |||
| 12 | #include <stdio.h> | ||
| 13 | |||
| 14 | class Unit : public Bu::UnitSuite | ||
| 15 | { | ||
| 16 | private: | ||
| 17 | typedef Bu::Hash<Bu::FString, int> StrIntHash; | ||
| 18 | typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; | ||
| 19 | typedef Bu::Hash<int, Bu::FString> IntStrHash; | ||
| 20 | |||
| 21 | public: | ||
| 22 | Unit() | ||
| 23 | { | ||
| 24 | setName("Hash"); | ||
| 25 | addTest( Unit::insert1 ); | ||
| 26 | addTest( Unit::insert2 ); | ||
| 27 | addTest( Unit::insert3 ); | ||
| 28 | addTest( Unit::probe1 ); | ||
| 29 | addTest( Unit::erase1 ); | ||
| 30 | } | ||
| 31 | |||
| 32 | virtual ~Unit() | ||
| 33 | { | ||
| 34 | } | ||
| 35 | |||
| 36 | void probe1() | ||
| 37 | { | ||
| 38 | StrIntHash h; | ||
| 39 | char buf[20]; | ||
| 40 | for(int i=1;i<10000;i++) | ||
| 41 | { | ||
| 42 | sprintf(buf,"%d",i); | ||
| 43 | Bu::FString sTmp(buf); | ||
| 44 | h[sTmp] = i; | ||
| 45 | unitTest( h.has(sTmp) ); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | void insert1() | ||
| 50 | { | ||
| 51 | StrIntHash h; | ||
| 52 | h["Hi"] = 42; | ||
| 53 | unitTest( h["Hi"] == 42 ); | ||
| 54 | } | ||
| 55 | |||
| 56 | void insert2() | ||
| 57 | { | ||
| 58 | StrStrHash h; | ||
| 59 | h["Hi"] = "Yo"; | ||
| 60 | h["Bye"] = "Later"; | ||
| 61 | unitTest( h["Hi"].getValue() == "Yo" ); | ||
| 62 | |||
| 63 | StrStrHash h2(h); | ||
| 64 | unitTest( h2["Hi"].getValue() = "Yo" ); | ||
| 65 | unitTest( h2["Bye"].getValue() = "Later" ); | ||
| 66 | |||
| 67 | StrStrHash h3; | ||
| 68 | h3 = h; | ||
| 69 | unitTest( h3["Hi"].getValue() = "Yo" ); | ||
| 70 | unitTest( h3["Bye"].getValue() = "Later" ); | ||
| 71 | } | ||
| 72 | |||
| 73 | void insert3() | ||
| 74 | { | ||
| 75 | IntStrHash h; | ||
| 76 | |||
| 77 | for( unsigned int i=1; i<50; i++ ) | ||
| 78 | { | ||
| 79 | h[i] = "testing"; | ||
| 80 | unitTest( h.getSize() == i ); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | void erase1() | ||
| 85 | { | ||
| 86 | StrIntHash h; | ||
| 87 | h.insert("Number 1", 1 ); | ||
| 88 | h.insert("Number 2", 2 ); | ||
| 89 | h.insert("Number 3", 3 ); | ||
| 90 | h.erase("Number 2"); | ||
| 91 | h.get("Number 3"); | ||
| 92 | try { | ||
| 93 | h.get("Number 2"); | ||
| 94 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); | ||
| 95 | } catch( Bu::HashException &e ) { } | ||
| 96 | |||
| 97 | /* printf("\n"); | ||
| 98 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) | ||
| 99 | { | ||
| 100 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | ||
| 101 | } */ | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | |||
| 105 | int main( int argc, char *argv[] ) | ||
| 106 | { | ||
| 107 | return Unit().run( argc, argv ); | ||
| 108 | } | ||
| 109 | |||
diff --git a/src/unit/hash.unit b/src/unit/hash.unit new file mode 100644 index 0000000..bd7da61 --- /dev/null +++ b/src/unit/hash.unit | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/fstring.h" | ||
| 10 | #include "bu/hash.h" | ||
| 11 | |||
| 12 | #include <stdio.h> | ||
| 13 | |||
| 14 | typedef Bu::Hash<Bu::FString, int> StrIntHash; | ||
| 15 | typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; | ||
| 16 | typedef Bu::Hash<int, Bu::FString> IntStrHash; | ||
| 17 | |||
| 18 | {=Init} | ||
| 19 | |||
| 20 | {%probe1} | ||
| 21 | { | ||
| 22 | StrIntHash h; | ||
| 23 | char buf[20]; | ||
| 24 | for(int i=1;i<10000;i++) | ||
| 25 | { | ||
| 26 | sprintf(buf,"%d",i); | ||
| 27 | Bu::FString sTmp(buf); | ||
| 28 | h[sTmp] = i; | ||
| 29 | unitTest( h.has(sTmp) ); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | {%insert1} | ||
| 34 | { | ||
| 35 | StrIntHash h; | ||
| 36 | h["Hi"] = 42; | ||
| 37 | unitTest( h["Hi"] == 42 ); | ||
| 38 | } | ||
| 39 | |||
| 40 | {%insert2} | ||
| 41 | { | ||
| 42 | StrStrHash h; | ||
| 43 | h["Hi"] = "Yo"; | ||
| 44 | h["Bye"] = "Later"; | ||
| 45 | unitTest( h["Hi"].getValue() == "Yo" ); | ||
| 46 | |||
| 47 | StrStrHash h2(h); | ||
| 48 | unitTest( h2["Hi"].getValue() = "Yo" ); | ||
| 49 | unitTest( h2["Bye"].getValue() = "Later" ); | ||
| 50 | |||
| 51 | StrStrHash h3; | ||
| 52 | h3 = h; | ||
| 53 | unitTest( h3["Hi"].getValue() = "Yo" ); | ||
| 54 | unitTest( h3["Bye"].getValue() = "Later" ); | ||
| 55 | } | ||
| 56 | |||
| 57 | {%insert3} | ||
| 58 | { | ||
| 59 | IntStrHash h; | ||
| 60 | |||
| 61 | for( unsigned int i=1; i<50; i++ ) | ||
| 62 | { | ||
| 63 | h[i] = "testing"; | ||
| 64 | unitTest( h.getSize() == i ); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | {%erase1} | ||
| 69 | { | ||
| 70 | StrIntHash h; | ||
| 71 | h.insert("Number 1", 1 ); | ||
| 72 | h.insert("Number 2", 2 ); | ||
| 73 | h.insert("Number 3", 3 ); | ||
| 74 | h.erase("Number 2"); | ||
| 75 | h.get("Number 3"); | ||
| 76 | try { | ||
| 77 | h.get("Number 2"); | ||
| 78 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); | ||
| 79 | } catch( Bu::HashException &e ) { } | ||
| 80 | |||
| 81 | /* printf("\n"); | ||
| 82 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) | ||
| 83 | { | ||
| 84 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | ||
| 85 | } */ | ||
| 86 | } | ||
diff --git a/src/unit/membuf.cpp b/src/unit/membuf.cpp deleted file mode 100644 index dc02aa3..0000000 --- a/src/unit/membuf.cpp +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/unitsuite.h" | ||
| 9 | #include "bu/membuf.h" | ||
| 10 | |||
| 11 | class Unit : public Bu::UnitSuite | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | Unit() | ||
| 15 | { | ||
| 16 | setName("MemBuf"); | ||
| 17 | addTest( Unit::testWriteRead01 ); | ||
| 18 | addTest( Unit::testOverwrite1 ); | ||
| 19 | } | ||
| 20 | |||
| 21 | virtual ~Unit() | ||
| 22 | { | ||
| 23 | } | ||
| 24 | |||
| 25 | void testWriteRead01() | ||
| 26 | { | ||
| 27 | Bu::MemBuf mb; | ||
| 28 | unitTest( mb.write("ab", 2 ) == 2 ); | ||
| 29 | unitTest( mb.write("cde", 3 ) == 3 ); | ||
| 30 | unitTest( mb.write("FG", 2 ) == 2 ); | ||
| 31 | |||
| 32 | mb.setPos( 0 ); | ||
| 33 | |||
| 34 | char buf[8]; | ||
| 35 | buf[7] = '\0'; | ||
| 36 | unitTest( mb.read( buf, 7 ) == 7 ); | ||
| 37 | unitTest( !strncmp( buf, "abcdeFG", 7 ) ); | ||
| 38 | unitTest( mb.read( buf, 7 ) == 0 ); | ||
| 39 | mb.seek( -3 ); | ||
| 40 | unitTest( mb.read( buf, 7 ) == 3 ); | ||
| 41 | unitTest( !strncmp( buf, "eFG", 3 ) ); | ||
| 42 | } | ||
| 43 | |||
| 44 | void testOverwrite1() | ||
| 45 | { | ||
| 46 | Bu::MemBuf mb; | ||
| 47 | unitTest( mb.write("0123456789") == 10 ); | ||
| 48 | mb.setPos( 4 ); | ||
| 49 | unitTest( mb.write("-5-") == 3 ); | ||
| 50 | mb.setPos( 9 ); | ||
| 51 | mb.write("Hey!!!"); | ||
| 52 | unitTest( mb.tell() == 15 ); | ||
| 53 | char buf[50]; | ||
| 54 | mb.setPos( 0 ); | ||
| 55 | buf[mb.read( buf, 50 )] = '\0'; | ||
| 56 | unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); | ||
| 57 | } | ||
| 58 | }; | ||
| 59 | |||
| 60 | int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } | ||
diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit new file mode 100644 index 0000000..aebf36c --- /dev/null +++ b/src/unit/membuf.unit | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/membuf.h" | ||
| 10 | |||
| 11 | {=Init} | ||
| 12 | |||
| 13 | {%testWriteRead01} | ||
| 14 | { | ||
| 15 | Bu::MemBuf mb; | ||
| 16 | unitTest( mb.write("ab", 2 ) == 2 ); | ||
| 17 | unitTest( mb.write("cde", 3 ) == 3 ); | ||
| 18 | unitTest( mb.write("FG", 2 ) == 2 ); | ||
| 19 | |||
| 20 | mb.setPos( 0 ); | ||
| 21 | |||
| 22 | char buf[8]; | ||
| 23 | buf[7] = '\0'; | ||
| 24 | unitTest( mb.read( buf, 7 ) == 7 ); | ||
| 25 | unitTest( !strncmp( buf, "abcdeFG", 7 ) ); | ||
| 26 | unitTest( mb.read( buf, 7 ) == 0 ); | ||
| 27 | mb.seek( -3 ); | ||
| 28 | unitTest( mb.read( buf, 7 ) == 3 ); | ||
| 29 | unitTest( !strncmp( buf, "eFG", 3 ) ); | ||
| 30 | } | ||
| 31 | |||
| 32 | {%testOverwrite1} | ||
| 33 | { | ||
| 34 | Bu::MemBuf mb; | ||
| 35 | unitTest( mb.write("0123456789") == 10 ); | ||
| 36 | mb.setPos( 4 ); | ||
| 37 | unitTest( mb.write("-5-") == 3 ); | ||
| 38 | mb.setPos( 9 ); | ||
| 39 | mb.write("Hey!!!"); | ||
| 40 | unitTest( mb.tell() == 15 ); | ||
| 41 | char buf[50]; | ||
| 42 | mb.setPos( 0 ); | ||
| 43 | buf[mb.read( buf, 50 )] = '\0'; | ||
| 44 | unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); | ||
| 45 | } | ||
diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp deleted file mode 100644 index e4b3ccc..0000000 --- a/src/unit/taf.cpp +++ /dev/null | |||
| @@ -1,133 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/unitsuite.h" | ||
| 9 | #include "bu/file.h" | ||
| 10 | #include "bu/tafreader.h" | ||
| 11 | #include "bu/tafwriter.h" | ||
| 12 | #include "bu/membuf.h" | ||
| 13 | |||
| 14 | #include <string.h> | ||
| 15 | #include <unistd.h> | ||
| 16 | |||
| 17 | class Unit : public Bu::UnitSuite | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | Unit() | ||
| 21 | { | ||
| 22 | setName("taf"); | ||
| 23 | addTest( Unit::read1 ); | ||
| 24 | addTest( Unit::encode1 ); | ||
| 25 | addTest( Unit::emptyStr1 ); | ||
| 26 | addTest( Unit::incomplete1 ); | ||
| 27 | } | ||
| 28 | |||
| 29 | virtual ~Unit() | ||
| 30 | { | ||
| 31 | } | ||
| 32 | |||
| 33 | void read1() | ||
| 34 | { | ||
| 35 | #define FN_TMP ("/tmp/tmpXXXXXXXX") | ||
| 36 | Bu::FString sFnTmp(FN_TMP); | ||
| 37 | Bu::File fOut = Bu::File::tempFile( sFnTmp ); | ||
| 38 | const char *data = | ||
| 39 | "{test: name=\"Bob\"}" | ||
| 40 | ; | ||
| 41 | fOut.write(data,strlen(data)); | ||
| 42 | fOut.close(); | ||
| 43 | |||
| 44 | Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); | ||
| 45 | Bu::TafReader tr(fIn); | ||
| 46 | |||
| 47 | Bu::TafGroup *tn = tr.readGroup(); | ||
| 48 | unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); | ||
| 49 | delete tn; | ||
| 50 | |||
| 51 | unlink(sFnTmp.getStr()); | ||
| 52 | #undef FN_TMP | ||
| 53 | } | ||
| 54 | |||
| 55 | void encode1() | ||
| 56 | { | ||
| 57 | Bu::MemBuf mb; | ||
| 58 | Bu::TafWriter tw( mb ); | ||
| 59 | |||
| 60 | Bu::TafGroup g("Test data"); | ||
| 61 | Bu::FString sData( 256 ); | ||
| 62 | for( int j = 0; j < 256; j++ ) | ||
| 63 | sData[j] = (unsigned char)j; | ||
| 64 | g.addChild( new Bu::TafProperty("Encoded", sData) ); | ||
| 65 | tw.writeGroup( &g ); | ||
| 66 | |||
| 67 | static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" | ||
| 68 | "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" | ||
| 69 | "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" | ||
| 70 | "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" | ||
| 71 | "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" | ||
| 72 | " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" | ||
| 73 | "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" | ||
| 74 | "jklmnopqrstuvwxyz{|}~\\x7F" | ||
| 75 | "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" | ||
| 76 | "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" | ||
| 77 | "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" | ||
| 78 | "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" | ||
| 79 | "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" | ||
| 80 | "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" | ||
| 81 | "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" | ||
| 82 | "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" | ||
| 83 | "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" | ||
| 84 | "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" | ||
| 85 | "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" | ||
| 86 | "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" | ||
| 87 | "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" | ||
| 88 | "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" | ||
| 89 | "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" | ||
| 90 | "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; | ||
| 91 | unitTest( mb.getString() == cmpdata ); | ||
| 92 | mb.setPos( 0 ); | ||
| 93 | Bu::TafReader tr( mb ); | ||
| 94 | Bu::TafGroup *rg = tr.readGroup(); | ||
| 95 | unitTest( rg->getProperty("Encoded") == sData ); | ||
| 96 | delete rg; | ||
| 97 | } | ||
| 98 | |||
| 99 | void emptyStr1() | ||
| 100 | { | ||
| 101 | Bu::MemBuf mb; | ||
| 102 | Bu::TafWriter tw( mb ); | ||
| 103 | |||
| 104 | Bu::TafGroup g("Test Group"); | ||
| 105 | Bu::FString sVal; | ||
| 106 | g.addChild( new Bu::TafProperty("Lame", sVal) ); | ||
| 107 | tw.writeGroup( &g ); | ||
| 108 | |||
| 109 | unitTest( | ||
| 110 | mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); | ||
| 111 | } | ||
| 112 | |||
| 113 | void incomplete1() | ||
| 114 | { | ||
| 115 | try | ||
| 116 | { | ||
| 117 | Bu::MemBuf mb("{Lame: \"Hello=\""); | ||
| 118 | Bu::TafReader tr( mb ); | ||
| 119 | delete tr.readGroup(); | ||
| 120 | unitFailed("Should have thrown an exception, didn't."); | ||
| 121 | } | ||
| 122 | catch( Bu::TafException &e ) | ||
| 123 | { | ||
| 124 | // Woot | ||
| 125 | } | ||
| 126 | } | ||
| 127 | }; | ||
| 128 | |||
| 129 | int main( int argc, char *argv[] ) | ||
| 130 | { | ||
| 131 | return Unit().run( argc, argv ); | ||
| 132 | } | ||
| 133 | |||
diff --git a/src/unit/taf.unit b/src/unit/taf.unit new file mode 100644 index 0000000..5588c85 --- /dev/null +++ b/src/unit/taf.unit | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/file.h" | ||
| 10 | #include "bu/tafreader.h" | ||
| 11 | #include "bu/tafwriter.h" | ||
| 12 | #include "bu/membuf.h" | ||
| 13 | |||
| 14 | #include <string.h> | ||
| 15 | #include <unistd.h> | ||
| 16 | |||
| 17 | {=Init} | ||
| 18 | |||
| 19 | {%read1} | ||
| 20 | { | ||
| 21 | #define FN_TMP ("/tmp/tmpXXXXXXXX") | ||
| 22 | Bu::FString sFnTmp(FN_TMP); | ||
| 23 | Bu::File fOut = Bu::File::tempFile( sFnTmp ); | ||
| 24 | const char *data = | ||
| 25 | "{test: name=\"Bob\"}" | ||
| 26 | ; | ||
| 27 | fOut.write(data,strlen(data)); | ||
| 28 | fOut.close(); | ||
| 29 | |||
| 30 | Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); | ||
| 31 | Bu::TafReader tr(fIn); | ||
| 32 | |||
| 33 | Bu::TafGroup *tn = tr.readGroup(); | ||
| 34 | unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); | ||
| 35 | delete tn; | ||
| 36 | |||
| 37 | unlink(sFnTmp.getStr()); | ||
| 38 | #undef FN_TMP | ||
| 39 | } | ||
| 40 | |||
| 41 | {%encode1} | ||
| 42 | { | ||
| 43 | Bu::MemBuf mb; | ||
| 44 | Bu::TafWriter tw( mb ); | ||
| 45 | |||
| 46 | Bu::TafGroup g("Test data"); | ||
| 47 | Bu::FString sData( 256 ); | ||
| 48 | for( int j = 0; j < 256; j++ ) | ||
| 49 | sData[j] = (unsigned char)j; | ||
| 50 | g.addChild( new Bu::TafProperty("Encoded", sData) ); | ||
| 51 | tw.writeGroup( &g ); | ||
| 52 | |||
| 53 | static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" | ||
| 54 | "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" | ||
| 55 | "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" | ||
| 56 | "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" | ||
| 57 | "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" | ||
| 58 | " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" | ||
| 59 | "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" | ||
| 60 | "jklmnopqrstuvwxyz{|}~\\x7F" | ||
| 61 | "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" | ||
| 62 | "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" | ||
| 63 | "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" | ||
| 64 | "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" | ||
| 65 | "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" | ||
| 66 | "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" | ||
| 67 | "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" | ||
| 68 | "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" | ||
| 69 | "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" | ||
| 70 | "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" | ||
| 71 | "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" | ||
| 72 | "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" | ||
| 73 | "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" | ||
| 74 | "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" | ||
| 75 | "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" | ||
| 76 | "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; | ||
| 77 | unitTest( mb.getString() == cmpdata ); | ||
| 78 | mb.setPos( 0 ); | ||
| 79 | Bu::TafReader tr( mb ); | ||
| 80 | Bu::TafGroup *rg = tr.readGroup(); | ||
| 81 | unitTest( rg->getProperty("Encoded") == sData ); | ||
| 82 | delete rg; | ||
| 83 | } | ||
| 84 | |||
| 85 | {%emptyStr1} | ||
| 86 | { | ||
| 87 | Bu::MemBuf mb; | ||
| 88 | Bu::TafWriter tw( mb ); | ||
| 89 | |||
| 90 | Bu::TafGroup g("Test Group"); | ||
| 91 | Bu::FString sVal; | ||
| 92 | g.addChild( new Bu::TafProperty("Lame", sVal) ); | ||
| 93 | tw.writeGroup( &g ); | ||
| 94 | |||
| 95 | unitTest( | ||
| 96 | mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); | ||
| 97 | } | ||
| 98 | |||
| 99 | {%incomplete1} | ||
| 100 | { | ||
| 101 | try | ||
| 102 | { | ||
| 103 | Bu::MemBuf mb("{Lame: \"Hello=\""); | ||
| 104 | Bu::TafReader tr( mb ); | ||
| 105 | delete tr.readGroup(); | ||
| 106 | unitFailed("Should have thrown an exception, didn't."); | ||
| 107 | } | ||
| 108 | catch( Bu::TafException &e ) | ||
| 109 | { | ||
| 110 | // Woot | ||
| 111 | } | ||
| 112 | } | ||
diff --git a/src/unit/xml.cpp b/src/unit/xml.cpp deleted file mode 100644 index e845cc1..0000000 --- a/src/unit/xml.cpp +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/fstring.h" | ||
| 9 | #include "bu/unitsuite.h" | ||
| 10 | #include "bu/xmlreader.h" | ||
| 11 | #include "bu/membuf.h" | ||
| 12 | |||
| 13 | class Unit : public Bu::UnitSuite | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | Unit() | ||
| 17 | { | ||
| 18 | setName("Xml"); | ||
| 19 | addTest( Unit::declaration ); | ||
| 20 | } | ||
| 21 | |||
| 22 | virtual ~Unit() | ||
| 23 | { | ||
| 24 | } | ||
| 25 | |||
| 26 | void declaration() | ||
| 27 | { | ||
| 28 | Bu::FString sXml("<?xml ?> <hi />"); | ||
| 29 | Bu::MemBuf buf( sXml ); | ||
| 30 | Bu::XmlReader xr( buf ); | ||
| 31 | } | ||
| 32 | |||
| 33 | }; | ||
| 34 | |||
| 35 | int main( int argc, char *argv[] ) | ||
| 36 | { | ||
| 37 | return Unit().run( argc, argv ); | ||
| 38 | } | ||
| 39 | |||
diff --git a/src/unit/xml.unit b/src/unit/xml.unit new file mode 100644 index 0000000..738ad66 --- /dev/null +++ b/src/unit/xml.unit | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/fstring.h" | ||
| 10 | #include "bu/xmlreader.h" | ||
| 11 | #include "bu/membuf.h" | ||
| 12 | |||
| 13 | {=Init} | ||
| 14 | |||
| 15 | {%declaration} | ||
| 16 | { | ||
| 17 | Bu::FString sXml("<?xml ?> <hi />"); | ||
| 18 | Bu::MemBuf buf( sXml ); | ||
| 19 | Bu::XmlReader xr( buf ); | ||
| 20 | } | ||
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp index 0008721..b61baa5 100644 --- a/src/unitsuite.cpp +++ b/src/unitsuite.cpp | |||
| @@ -72,7 +72,7 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) | |||
| 72 | return 0; | 72 | return 0; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void Bu::UnitSuite::add( Test fTest, Bu::FString sName ) | 75 | void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e ) |
| 76 | { | 76 | { |
| 77 | TestInfo ti; | 77 | TestInfo ti; |
| 78 | ti.sName = sName; | 78 | ti.sName = sName; |
diff --git a/src/unitsuite.h b/src/unitsuite.h index d27e322..d75211a 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h | |||
| @@ -81,9 +81,15 @@ namespace Bu | |||
| 81 | { | 81 | { |
| 82 | optStopOnError = 0x000001 | 82 | optStopOnError = 0x000001 |
| 83 | }; | 83 | }; |
| 84 | |||
| 85 | enum Expect | ||
| 86 | { | ||
| 87 | expectPass, | ||
| 88 | expectFail | ||
| 89 | }; | ||
| 84 | 90 | ||
| 85 | protected: | 91 | protected: |
| 86 | void add( Test fTest, Bu::FString sName ); | 92 | void add( Test fTest, const Bu::FString &sName, Expect e=expectPass ); |
| 87 | void setName( const FString &sName ); | 93 | void setName( const FString &sName ); |
| 88 | 94 | ||
| 89 | private: | 95 | private: |
