mCRL2
Loading...
Searching...
No Matches
test_utilities.h
Go to the documentation of this file.
1// Author(s): Frank Stappers
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_UTILITIES_TEST_UTILITIES_H
13#define MCRL2_UTILITIES_TEST_UTILITIES_H
14
15#include <algorithm>
16#include <cctype>
17#include <fstream>
18#include <sstream>
19#include <string>
20#include <vector>
21
22namespace mcrl2
23{
24
25namespace utilities
26{
27
29inline
31{
32 char c;
33 do
34 {
35 c = static_cast<char>(std::rand());
36 } while(!std::isalnum(static_cast<unsigned char>(c)));
37 // The cast to unsigned char, above here, is to ensure that the value passed
38 // to isalnum is between 0 and 255, which is required by std::isalnum.
39 // MSVC checks for these bounds in debug mode.
40 return c;
41
42}
43
45inline
46std::string rand_alnum_str(const std::string::size_type n)
47{
48 std::string s;
49 s.reserve(n);
50 std::generate_n(std::back_inserter(s), n, rand_alnum);
51 return s;
52}
53
54inline
55bool file_exists(const char *filename)
56{
57 std::ifstream ifile(filename);
58 return ifile.good();
59}
60
63inline
64std::string temporary_filename(std::string const& prefix = "")
65{
66 std::string basename(prefix + "_" + rand_alnum_str(8));
67 std::string result = basename ;
68 int suffix = 0;
69 while (file_exists(result.c_str()))
70 {
71 std::stringstream suffix_s;
72 suffix_s << suffix;
73 result = basename + suffix_s.str();
74 ++suffix;
75 }
76 return result;
77}
78
79} // namespace utilities
80
81} // namespace mcrl2
82
83#endif // MCRL2_UTILITIES_TEST_UTILITIES_H
char rand_alnum()
Generate a random alphanumeric character.
bool file_exists(const std::string &filename)
std::string rand_alnum_str(const std::string::size_type n)
Generate a random string of length n.
std::string temporary_filename(std::string const &prefix="")
Get filename with random suffix.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72