OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_misc_unix.cpp
Go to the documentation of this file.
1#include "test_common.hpp"
2
4
5using namespace openvpn;
6
7std::string content1 = "It was a bright cold day in April, and the clocks\n"
8 "were striking thirteen. Winston Smith, his chin nuzzled\n"
9 "into his breast in an effort to escape the vile wind,\n"
10 "slipped quickly through the glass doors of Victory\n"
11 "Mansions, though not quickly enough to prevent a\n"
12 "swirl of gritty dust from entering along with him.\n";
13
14std::string content2 = "To be or not to be, that is the question?\n";
15
16TEST(misc, tempfile)
17{
18 TempFile tf(getTempDirPath("tempfile-XXXXXX"), true);
19
20 tf.write(content1);
21 tf.reset();
22 const std::string s1 = tf.read();
23 ASSERT_EQ(s1, content1);
24
25 tf.truncate();
26 tf.write(content2);
27 tf.reset();
28 const std::string s2 = tf.read();
29 ASSERT_EQ(s2, content2);
30}
31
32TEST(misc, tempfile_name)
33{
34 TempFile tf(getTempDirPath("tempfile-XXXXXX"), true);
35 auto fn = tf.filename();
36 ASSERT_NE(std::string::npos, fn.find("tempfile-"));
37 ASSERT_EQ(std::string::npos, fn.find("XXXXXX"));
38}
39
40TEST(misc, tempfile_name_6Xs)
41{
42 TempFile tf(getTempDirPath("tempXXXXXXfile"), true);
43 auto fn = tf.filename();
44 ASSERT_NE(std::string::npos, fn.find("temp"));
45 ASSERT_NE(std::string::npos, fn.find("file"));
46 ASSERT_EQ(std::string::npos, fn.find("XXXXXX"));
47}
48
49TEST(misc, tempfile_name_7Xs)
50{
51 TempFile tf(getTempDirPath("tempXXXXXXXfile"), true);
52 auto fn = tf.filename();
53 ASSERT_NE(std::string::npos, fn.find("temp"));
54 ASSERT_NE(std::string::npos, fn.find("file"));
55 ASSERT_EQ(std::string::npos, fn.find("XXXXXX"));
56}
57
58TEST(misc, tempfile_name_6X6X)
59{
60 TempFile tf(getTempDirPath("tempXXXXXXfile-XXXXXX"), true);
61 auto fn = tf.filename();
62 ASSERT_NE(std::string::npos, fn.find("temp"));
63 ASSERT_NE(std::string::npos, fn.find("file"));
64 ASSERT_EQ(fn.rfind("XXXXXX"), fn.find("XXXXXX"));
65}
std::string read()
Definition tempfile.hpp:115
std::string filename() const
Definition tempfile.hpp:121
void write(const std::string &content)
Definition tempfile.hpp:101
std::string getTempDirPath(const std::string &fn)
std::string content1
std::string content2
TEST(misc, tempfile)