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-2019 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <memory>
38 : #include <sstream>
39 :
40 : #include <limits.h>
41 :
42 :
43 : #if defined(__sun) || defined(__sun__) || defined(__SunOS) || defined(__CYGWIN__)
44 : namespace std
45 : {
46 :
47 : // somehow they have g++ 4.8.2 but to_string() is missing
48 : template<typename T>
49 : std::string to_string(T v)
50 : {
51 : std::ostringstream ss;
52 : ss << v;
53 : return ss.str();
54 : }
55 :
56 : }
57 : #endif
58 :
59 :
60 : namespace zipios_test
61 : {
62 :
63 :
64 : /** \brief Create a random number representing a size_t object.
65 : *
66 : * This function is used to accommodate 32 and 64 bit tests. It creates
67 : * a random number in a size_t variable. The result is expected to fill
68 : * all the bits in a random manner.
69 : *
70 : * \todo
71 : * Look into whether we want to define all the bits. Right now, it is
72 : * likely that bit 31 and 63 never get set.
73 : *
74 : * \return A random size_t variable.
75 : */
76 49 : inline size_t rand_size_t()
77 : {
78 49 : return static_cast<size_t>(rand())
79 : #if !defined(_ILP32) && ((UINT_MAX) != 0xFFFFFFFFU)
80 : | (static_cast<size_t>(rand()) << 32)
81 : #endif
82 : ;
83 : }
84 :
85 :
86 : class auto_unlink_t
87 : {
88 : public:
89 : auto_unlink_t(std::string const& filename);
90 : ~auto_unlink_t();
91 :
92 : private:
93 : std::string const m_filename;
94 : };
95 :
96 :
97 : class file_t
98 : {
99 : public:
100 : typedef std::shared_ptr<file_t> pointer_t;
101 : typedef std::vector<pointer_t> vector_t;
102 : typedef std::vector<std::string> filenames_t;
103 :
104 : enum class type_t
105 : {
106 : UNKNOWN,
107 : REGULAR,
108 : DIRECTORY
109 : };
110 :
111 : file_t(type_t t, int children_count, std::string const& new_filename = "");
112 : ~file_t();
113 : type_t type() const;
114 : std::string const& filename() const;
115 : vector_t const& children() const;
116 : size_t size();
117 : type_t find(std::string const& name);
118 : filenames_t get_all_filenames() const;
119 :
120 : private:
121 : void get_filenames(filenames_t& names, std::string const& parent) const;
122 :
123 : std::string m_filename;
124 : vector_t m_children;
125 : type_t m_type;
126 : };
127 :
128 :
129 : } // zipios_test namespace
130 :
131 : // Local Variables:
132 : // mode: cpp
133 : // indent-tabs-mode: nil
134 : // c-basic-offset: 4
135 : // tab-width: 4
136 : // End:
137 :
138 : // vim: ts=4 sw=4 et
139 : #endif
|