15 #ifndef Om_Source_IteratorSource_
23 #ifndef Om_Macro_Precompilation_
25 #include "boost/test/unit_test.hpp"
31 BOOST_AUTO_TEST_SUITE(IteratorSourceTest)
35 static void CopyWithIterators(
36 char const theCodeUnitIterator[],
37 std::string & theSinkString
43 IteratorSource theSource(theCodeUnitIterator);
44 IteratorSource
const theSourceEnd(
"");
46 Sink::ContainerBackSink<
49 > theSink(theSinkString);
63 Item(
char const theCodeUnit):
64 thisCodeUnit(theCodeUnit) {}
66 bool operator !()
const {
67 return !this->thisCodeUnit;
76 BOOST_AUTO_TEST_CASE(GeneralTest) {
77 typedef Item * Iterator;
83 Item theSourceArray[] = {
89 IteratorSource theSource(theSourceArray);
90 Item theSourceArrayEnd[] = {0};
91 IteratorSource
const theSourceEnd(theSourceArrayEnd);
93 BOOST_CHECK(theSourceEnd != theSource);
96 theSource->thisCodeUnit
100 BOOST_CHECK(theSourceEnd != theSource);
103 (*theSource).thisCodeUnit
106 IteratorSource theIterator = ++theSource;
107 BOOST_CHECK(theSourceEnd != theSource);
110 theIterator->thisCodeUnit
114 theSource->thisCodeUnit
117 theIterator->thisCodeUnit =
'3';
118 (*theSource).thisCodeUnit =
'4';
121 (*theIterator).thisCodeUnit
125 theSource->thisCodeUnit
129 theSourceArray[0].thisCodeUnit
133 theSourceArray[1].thisCodeUnit
137 theSourceArray[2].thisCodeUnit
141 theSourceArray[3].thisCodeUnit
145 BOOST_CHECK(theSourceEnd == theSource);
148 BOOST_AUTO_TEST_CASE(CopyMultipleItemsTest) {
149 char const theSourceNullTerminatedString[] =
"01";
150 std::string theSinkString;
152 theSourceNullTerminatedString,
157 theSourceNullTerminatedString,
162 BOOST_AUTO_TEST_CASE(CopySingleItemTest) {
163 char const theSourceNullTerminatedString[] =
"0";
164 std::string theSinkString;
166 theSourceNullTerminatedString,
171 theSourceNullTerminatedString,
176 BOOST_AUTO_TEST_CASE(CopyNoItemsTest) {
177 char const theSourceNullTerminatedString[] =
"";
178 std::string theSinkString;
180 theSourceNullTerminatedString,
185 theSourceNullTerminatedString,
190 BOOST_AUTO_TEST_SUITE_END()
203 typename ThisIterator \
207 Om::Source::IteratorSource< \
215 inline Type_::IteratorSource(ThisIterator
const theIterator):
216 thisIterator(theIterator) {}
219 inline Type_ & Type_::operator =(IteratorSource theIteratorSource) {
220 this->Swap(theIteratorSource);
225 inline bool Type_::operator !()
const {
226 return !*this->thisIterator;
230 inline ThisItem & Type_::operator *()
const {
231 assert(!!*this->thisIterator);
232 return *this->thisIterator;
236 inline bool Type_::Equals(IteratorSource
const & theIteratorSource)
const {
238 this->thisIterator == theIteratorSource.thisIterator ||
240 !*this->thisIterator &&
241 !*theIteratorSource.thisIterator
247 inline void Type_::Pop() {
248 assert(!!*this->thisIterator);
249 ++this->thisIterator;
253 inline void Type_::Swap(IteratorSource & theIteratorSource) {
256 theIteratorSource.thisIterator
268 typename TheIterator \
272 Om::Source::IteratorSource< \
279 Type_
const & theFirst,
280 Type_
const & theSecond
282 return theFirst.Equals(theSecond);
287 Type_
const & theFirst,
288 Type_
const & theSecond
290 return !theFirst.Equals(theSecond);
300 theFirst.Swap(theSecond);
A Source adapter for a sentinal-terminated input iterator.
bool operator==(CodePointSource< TheCodeUnitIterator > const &, CodePointSource< TheCodeUnitIterator > const &)
bool operator!=(CodePointSource< TheCodeUnitIterator > const &, CodePointSource< TheCodeUnitIterator > const &)
void swap(Om::Language::Expression &, Om::Language::Expression &)