aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/blob.unit118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/unit/blob.unit b/src/unit/blob.unit
new file mode 100644
index 0000000..645052b
--- /dev/null
+++ b/src/unit/blob.unit
@@ -0,0 +1,118 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2019 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/blob.h"
10#include "bu/exceptionindexoutofbounds.h"
11#include "bu/sio.h"
12
13#include <string.h>
14
15suite Blob
16{
17 test set
18 {
19 Bu::Blob a("hello there");
20 unitTest( !strcmp( a.getData(), "hello there") );
21 Bu::Blob b( a );
22 a = "New string";
23 unitTest( !strcmp( a.getData(), "New string") );
24 unitTest( !strcmp( b.getData(), "hello there") );
25 b = a;
26 unitTest( !strcmp( b.getData(), "New string") );
27 }
28
29 test index
30 {
31 Bu::Blob a("hello there");
32 unitTest( a[5] == ' ' );
33 unitTest( a[6] == 't' );
34 unitTestCatch( a[-1], Bu::ExceptionIndexOutOfBounds );
35 unitTestCatch( a[-100], Bu::ExceptionIndexOutOfBounds );
36 unitTest( a[10] == 'e' );
37 unitTestCatch( a[11], Bu::ExceptionIndexOutOfBounds );
38 unitTestCatch( a[12], Bu::ExceptionIndexOutOfBounds );
39 }
40
41 test compare
42 {
43 Bu::Blob a("cat"), b("dog"), c("cattail"), d("dog");
44
45 unitTest( a != b );
46 unitTest( a != c );
47 unitTest( a != "catt" );
48 unitTest( a != "ca" );
49 unitTest( !(a == c) );
50 unitTest( !(a == d) );
51 unitTest( a == a );
52 unitTest( !(a != a) );
53 unitTest( !(b != d) );
54
55 unitTest( a < b );
56 unitTest( a <= b );
57 unitTest( a < c );
58 unitTest( a <= c );
59 unitTest( !(b < d) );
60 unitTest( b <= d );
61 unitTest( !(c < a) );
62
63 unitTest( a < "dog" );
64 unitTest( a <= "dog" );
65 unitTest( a < "cattail" );
66 unitTest( a <= "cattail" );
67 unitTest( !(b < "dog") );
68 unitTest( b <= "dog" );
69 unitTest( !(c < "cattail") );
70
71 unitTest( b > a );
72 unitTest( b >= a );
73 unitTest( c > a );
74 unitTest( c >= a );
75 unitTest( !(d > b) );
76 unitTest( d <= b );
77 unitTest( !(a > c) );
78
79 unitTest( b > "cat" );
80 unitTest( b >= "cat" );
81 unitTest( c > "cat" );
82 unitTest( c >= "cat" );
83 unitTest( !(d > "dog") );
84 unitTest( d <= "dog" );
85 unitTest( !(a > "cattail") );
86 }
87
88 test iterator
89 {
90 }
91
92 test const_iterator
93 {
94 }
95
96 test sort
97 {
98 Bu::List<Bu::Blob> lList;
99 lList.append("Moose");
100 lList.append("Cattail");
101 lList.append("Cat");
102 lList.append("Cattxil");
103 lList.append("Moo");
104 lList.append("Cattails");
105 lList.append("Dog");
106
107 lList.sort();
108
109 Bu::List<Bu::Blob>::iterator i = lList.begin();
110 unitTest( *i == "Cat" && i++ );
111 unitTest( *i == "Cattail" && i++ );
112 unitTest( *i == "Cattails" && i++ );
113 unitTest( *i == "Cattxil" && i++ );
114 unitTest( *i == "Dog" && i++ );
115 unitTest( *i == "Moo" && i++ );
116 unitTest( *i == "Moose" && !(i++) );
117 }
118}