1 #ifndef _T_CIRCULAR_BUFFER_H_
2 #define _T_CIRCULAR_BUFFER_H_
5 #include <mimetic/circular_buffer.h>
11 class TEST_CLASS( test_circular_buffer)
16 char* push_back_items;
19 static const test_item tb[];
20 static const unsigned int test_count;
25 test_circular_buffer()
29 void TEST_FUNCTION( testOverflow )
31 circular_buffer<char> cb(3);
32 for(unsigned i = 0; i < 1000; i++)
35 void TEST_FUNCTION( testCount )
37 unsigned int maxsize = 64;
38 circular_buffer<char> cb(maxsize);
39 for(unsigned int i = 0; i < 1000; i++)
41 if(cb.count() < maxsize)
43 TEST_ASSERT_EQUALS_P( i, cb.count());
45 TEST_ASSERT_EQUALS_P( maxsize, cb.count());
50 void TEST_FUNCTION( testCmpCh )
52 for(unsigned int i = 0 ; i < test_count; ++i)
55 putstr = ti.push_back_items;
57 circular_buffer<char> cb(ti.buf_sz);
59 while(0 != (c = *putstr++))
61 while(0 != (c = *result++))
63 TEST_ASSERT_EQUALS_P( cb.front(), c );
69 void TEST_FUNCTION( testInOut )
71 for(unsigned int i =0 ; i < test_count; ++i)
74 putstr = ti.push_back_items;
75 circular_buffer<char> cb(ti.buf_sz);
77 while(0 != (c = *putstr++))
80 TEST_ASSERT_EQUALS_P( cb.front(), c );
86 void TEST_FUNCTION( testFill )
88 for(unsigned int i =0 ; i < test_count; ++i)
91 putstr = ti.push_back_items;
92 circular_buffer<char> cb(ti.buf_sz);
94 const char * cmp = putstr;
95 while(0 != (c = *putstr++))
98 if(cb.count() < cb.max_size()) continue;
100 TEST_ASSERT_EQUALS_P( cb.front(), c );
105 void TEST_FUNCTION( testIdx )
107 for(unsigned int i =0 ; i < test_count; i++)
110 putstr = ti.push_back_items;
112 circular_buffer<char> cb(ti.buf_sz);
114 while(0 != (c = *putstr++))
116 for(unsigned int t = 0 ; t < cb.count(); ++t)
118 TEST_ASSERT_EQUALS_P( cb[t], result[t]);
122 void TEST_FUNCTION( testEq )
124 for(unsigned int i =0 ; i < test_count; i++)
127 putstr = ti.push_back_items;
129 circular_buffer<char> cb(ti.buf_sz);
131 while(0 != (c = *putstr++))
133 // test == and != operators
134 TEST_ASSERT( cb == result );
135 TEST_ASSERT( false == (cb != result) );
139 void TEST_FUNCTION( testCompare )
141 for(unsigned int i =0 ; i < test_count; i++)
144 putstr = ti.push_back_items;
145 //result = ti.result;
146 std::string res = ti.result;
147 circular_buffer<char> cb(ti.buf_sz);
149 while(0 != (c = *putstr++))
151 for(unsigned int c = 0; c < res.length(); c++)
153 std::string subs = res.substr(c);
154 TEST_ASSERT( cb.compare(c,subs.length(),subs) );
156 for(unsigned int c = 0; c < res.length(); c++)
158 std::string subs = res.substr(c, res.length()-c);
159 TEST_ASSERT( cb.compare(c,subs.length(),subs) );
161 for(unsigned int c = res.length(); c != 0; c--)
163 std::string subs = res.substr(0,c);
164 TEST_ASSERT( cb.compare(0,subs.length(),subs) );
166 for(unsigned int c = res.length(); c != 0; c--)
168 TEST_ASSERT( cb.compare(0,c,res) );
173 void TEST_FUNCTION( testToStr )
175 for(unsigned int i =0 ; i < test_count; ++i)
178 putstr = ti.push_back_items;
180 circular_buffer<char> cb(ti.buf_sz);
182 while(0 != (c = *putstr++))
184 TEST_ASSERT_EQUALS_P( cb.str(), result );