1 /*=============================================================================
2 Copyright (c) 2003 Giovanni Bajo
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/concept_check.hpp>
13 #include <boost/spirit/include/classic_file_iterator.hpp>
15 // This checks for a namespace related problem in VC8
16 // The problem can be avoided by not using "using namespace std;" in the
18 namespace vc8_bug_1
{ struct plus
{}; }
19 namespace vc8_bug_2
{ using namespace vc8_bug_1
; struct test
: plus
{}; }
23 using namespace BOOST_SPIRIT_CLASSIC_NS
;
27 static const char* TMP_FILE
= "file_iter.tmp";
29 bool CreateTempFile(void)
31 FILE* f
= fopen(TMP_FILE
, "wb");
36 for (int i
=0;i
<256;i
++)
38 unsigned char ci
= (unsigned char)i
;
40 if (fwrite(&ci
,1,1,f
) == 0)
51 template <typename ITER
>
54 // Check constructor opening a file
58 // Assert dereference (twice: derefence
59 // must not move the iterator)
63 // Check random access
64 BOOST_TEST(a
[123] == 123);
66 // Check copy constructor and operator==
69 BOOST_TEST(!(c
!= a
));
71 // Check assignment operator
74 BOOST_TEST(!(d
!= a
));
80 BOOST_TEST(a
+256 == b
);
81 BOOST_TEST(a
== b
-256);
83 // Check copy constructor on non-trivial position
84 BOOST_TEST(*ITER(a
+67) == 67);
96 // Check end iterator increment/decrement
98 BOOST_TEST(*b
== 254);
99 BOOST_TEST(a
+254 == b
);
101 BOOST_TEST(a
+256 == b
);
120 BOOST_TEST(!(a
>= b
));
122 // Check increment through end
131 ///////////////////////////////////////////////////////////////////////////////
134 typedef unsigned char character_t
;
135 typedef file_iterator
<character_t
,
136 fileiter_impl::std_file_iterator
<character_t
> > iter
;
137 BOOST_CLASS_REQUIRE(iter
, boost
, RandomAccessIteratorConcept
);
139 #ifdef BOOST_SPIRIT_FILEITERATOR_WINDOWS
140 typedef file_iterator
<character_t
,
141 fileiter_impl::mmap_file_iterator
<character_t
> > iterwin
;
142 BOOST_CLASS_REQUIRE(iterwin
, boost
, RandomAccessIteratorConcept
);
144 #ifdef BOOST_SPIRIT_FILEITERATOR_POSIX
145 typedef file_iterator
<character_t
,
146 fileiter_impl::mmap_file_iterator
<character_t
> > iterposix
;
147 BOOST_CLASS_REQUIRE(iterposix
, boost
, RandomAccessIteratorConcept
);
152 if (!CreateTempFile())
154 cerr
<< "ERROR: Cannot create temporary file file_iter.tmp" << endl
;
158 cerr
<< "Testing standard iterator" << endl
;
161 #ifdef BOOST_SPIRIT_FILEITERATOR_WINDOWS
162 cerr
<< "Testing Windows iterator" << endl
;
166 #ifdef BOOST_SPIRIT_FILEITERATOR_POSIX
167 cerr
<< "Testing POSIX iterator" << endl
;
168 RunTest
<iterposix
>();
171 // Check if the file handles were closed correctly
172 BOOST_TEST(remove(TMP_FILE
) == 0);
174 return boost::report_errors();
177 #ifdef BOOST_NO_EXCEPTIONS
180 void throw_exception(std::exception
const& e
)
182 BOOST_EROR("throw_exception");