Line data Source code
1 : #pragma once
2 : #ifndef CATCH_TESTS_HPP
3 : #define CATCH_TESTS_HPP
4 :
5 : /*
6 : Zipios++ - a small C++ library that provides easy access to .zip files.
7 :
8 : Copyright (C) 2000-2007 Thomas Sondergaard
9 : Copyright (C) 2015 Made to Order Software Corporation
10 :
11 : This library is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU Lesser General Public
13 : License as published by the Free Software Foundation; either
14 : version 2 of the License, or (at your option) any later version.
15 :
16 : This library is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 : Lesser General Public License for more details.
20 :
21 : You should have received a copy of the GNU Lesser General Public
22 : License along with this library; if not, write to the Free Software
23 : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 : */
25 :
26 : /** \file
27 : * \brief Common header for all our catch tests.
28 : *
29 : * Zipios++ comes with a unit test suite. This header defines things
30 : * that all the tests access, such as the catch.hpp header file.
31 : */
32 :
33 : #include "zipios++/zipios-config.hpp"
34 :
35 : #include <catch.hpp>
36 :
37 : #include <sstream>
38 :
39 : #include <limits.h>
40 :
41 :
42 : #if defined(__sun) || defined(__sun__) || defined(__SunOS) || defined(__CYGWIN__)
43 : namespace std
44 : {
45 :
46 : // somehow they have g++ 4.8.2 but to_string() is missing
47 : template<typename T>
48 : std::string to_string(T v)
49 : {
50 : std::ostringstream ss;
51 : ss << v;
52 : return ss.str();
53 : }
54 :
55 : }
56 : #endif
57 :
58 :
59 : namespace zipios_test
60 : {
61 :
62 :
63 : /** \brief Create a random number representing a size_t object.
64 : *
65 : * This function is used to accomodate 32 and 64 bit tests. It creates
66 : * a random number in a size_t variable. The result is expected to fill
67 : * all the bits in a random manner.
68 : *
69 : * \todo
70 : * Look into whether we want to define all the bits. Right now, it is
71 : * likely that bit 31 and 63 never get set.
72 : *
73 : * \return A random size_t variable.
74 : */
75 98 : inline size_t rand_size_t()
76 : {
77 98 : return static_cast<size_t>(rand())
78 : #if !defined(_ILP32) && ((UINT_MAX) != 0xFFFFFFFFU)
79 : | (static_cast<size_t>(rand()) << 32)
80 : #endif
81 : ;
82 : }
83 :
84 :
85 : class auto_unlink_t
86 : {
87 : public:
88 : auto_unlink_t(std::string const& filename);
89 : ~auto_unlink_t();
90 :
91 : private:
92 : std::string const m_filename;
93 : };
94 :
95 :
96 : class file_t
97 : {
98 : public:
99 : typedef std::shared_ptr<file_t> pointer_t;
100 : typedef std::vector<pointer_t> vector_t;
101 : typedef std::vector<std::string> filenames_t;
102 :
103 : enum class type_t
104 : {
105 : UNKNOWN,
106 : REGULAR,
107 : DIRECTORY
108 : };
109 :
110 : file_t(type_t t, int children_count, std::string const& new_filename = "");
111 : ~file_t();
112 : type_t type() const;
113 : std::string const& filename() const;
114 : vector_t const& children() const;
115 : size_t size();
116 : type_t find(std::string const& name);
117 : filenames_t get_all_filenames() const;
118 :
119 : private:
120 : void get_filenames(filenames_t& names, std::string const& parent) const;
121 :
122 : std::string m_filename;
123 : vector_t m_children;
124 : type_t m_type;
125 : };
126 :
127 :
128 : } // zipios_test namespace
129 :
130 : // vim: ts=4 sw=4 et
131 :
132 : // Local Variables:
133 : // mode: cpp
134 : // indent-tabs-mode: nil
135 : // c-basic-offset: 4
136 : // tab-width: 4
137 : // End:
138 :
139 : #endif
|