1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_TEST_FILES_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_TEST_FILES_HPP_INCLUDED
11 #include <cctype> // toupper, tolower
12 #include <cstdio> // tmpname, TMP_MAX, remove
13 #include <cstdlib> // rand, toupper, tolower (VC6)
16 #include <boost/filesystem/operations.hpp>
17 #include "./constants.hpp"
19 #ifdef BOOST_NO_STDC_NAMESPACE
25 using ::toupper; using ::tolower; using ::remove; using ::rand;
29 namespace boost { namespace iostreams { namespace test {
31 // Represents a temp file, deleted upon destruction.
35 // Constructs a temp file which does not initially exist.
36 temp_file() { set_name(); }
37 ~temp_file() { (void)std::remove(name_.c_str()); }
38 const ::std::string name() const { return name_; }
39 operator const ::std::string() const { return name_; }
42 name_ = boost::filesystem::unique_path().string();
48 struct test_file : public temp_file {
51 BOOST_IOS::openmode mode =
52 BOOST_IOS::out | BOOST_IOS::binary;
53 ::std::ofstream f(name().c_str(), mode);
54 const ::std::string n(name());
55 const char* buf = narrow_data();
56 for (int z = 0; z < data_reps; ++z)
57 f.write(buf, data_length());
62 struct uppercase_file : public temp_file {
65 BOOST_IOS::openmode mode =
66 BOOST_IOS::out | BOOST_IOS::binary;
67 ::std::ofstream f(name().c_str(), mode);
68 const char* buf = narrow_data();
69 for (int z = 0; z < data_reps; ++z)
70 for (int w = 0; w < data_length(); ++w)
71 f.put((char) std::toupper(buf[w]));
75 struct lowercase_file : public temp_file {
78 BOOST_IOS::openmode mode =
79 BOOST_IOS::out | BOOST_IOS::binary;
80 ::std::ofstream f(name().c_str(), mode);
81 const char* buf = narrow_data();
82 for (int z = 0; z < data_reps; ++z)
83 for (int w = 0; w < data_length(); ++w)
84 f.put((char) std::tolower(buf[w]));
88 //----------------------------------------------------------------------------//
90 } } } // End namespaces test, iostreams, boost.
92 #endif // #ifndef BOOST_IOSTREAMS_TEST_FILES_HPP_INCLUDED