monotone

monotone Mtn Source Tree

Root/string_queue.cc

1// unit tests for string_queue
2
3#include <string>
4
5#include "string_queue.hh"
6
7using namespace std;
8
9#ifdef BUILD_UNIT_TESTS
10
11#include <iostream>
12#include "unit_tests.hh"
13
14void
15test_string_queue()
16{
17 string_queue sq1;
18
19 BOOST_CHECKPOINT( "append" );
20
21 sq1.append("123");
22 sq1.append("45z", 2); // 'z' shall be ignored
23 sq1.append('6');
24
25 BOOST_CHECK( sq1.size() == 6 );
26
27 BOOST_CHECKPOINT( "retrieve" );
28
29 BOOST_CHECK( sq1.substr(0, 6) == "123456" );
30 BOOST_CHECK( sq1.substr(3, 2) == "45" );
31
32 BOOST_CHECK( sq1[5] == '6' );
33 BOOST_CHECK( sq1[0] == '1' );
34
35 BOOST_CHECK( *(sq1.front_pointer(6)) == '1');
36
37 BOOST_CHECK( sq1.size() == 6);
38
39 BOOST_CHECKPOINT( "failures" );
40
41 // check a few things will fail
42 BOOST_CHECK_THROW( sq1.substr(3, 4), logic_error );
43 BOOST_CHECK_THROW( sq1.front_pointer(7), logic_error );
44
45 // modification
46 BOOST_CHECKPOINT( "modification" );
47
48 sq1[5] = 'r';
49 BOOST_CHECK_THROW( sq1[6], logic_error );
50
51 BOOST_CHECK( sq1[5] == 'r' );
52 BOOST_CHECK( sq1.substr(3, 3) == "45r" );
53
54 // empty it out
55 BOOST_CHECKPOINT( "emptying" );
56
57 BOOST_CHECK_THROW( sq1.pop_front( 7 ), logic_error );
58 sq1.pop_front(1);
59 BOOST_CHECK( sq1.size() == 5 );
60 BOOST_CHECK(sq1[0] == '2');
61
62 BOOST_CHECK(sq1[4] == 'r');
63 BOOST_CHECK_THROW( sq1[5], logic_error );
64 BOOST_CHECK_THROW( sq1.pop_front( 6 ), logic_error );
65 sq1.pop_front(5);
66 BOOST_CHECK_THROW( sq1.pop_front( 1 ), logic_error );
67
68 // it's empty again
69 BOOST_CHECK( sq1.size() == 0 );
70}
71
72void
73add_string_queue_tests(test_suite * suite)
74{
75 suite->add(BOOST_TEST_CASE(&test_string_queue));
76}
77
78#endif // BUILD_UNIT_TESTS

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status