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
3
#include <
openvpn/common/tempfile.hpp
>
4
5
using namespace
openvpn
;
6
7
std::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
14
std::string
content2
=
"To be or not to be, that is the question?\n"
;
15
16
TEST
(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
32
TEST
(Misc, TempfileName)
33
{
34
const
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
40
TEST
(Misc, TempfileName6Xs)
41
{
42
const
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
49
TEST
(Misc, TempfileName7Xs)
50
{
51
const
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
58
TEST
(Misc, TempfileName6X6X)
59
{
60
const
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
}
openvpn::TempFile
Definition
tempfile.hpp:41
openvpn::TempFile::truncate
void truncate()
Definition
tempfile.hpp:91
openvpn::TempFile::read
std::string read()
Definition
tempfile.hpp:115
openvpn::TempFile::reset
void reset()
Definition
tempfile.hpp:79
openvpn::TempFile::filename
std::string filename() const
Definition
tempfile.hpp:121
openvpn::TempFile::write
void write(const std::string &content)
Definition
tempfile.hpp:101
openvpn
Definition
ovpncli.cpp:97
tempfile.hpp
test_common.hpp
getTempDirPath
std::string getTempDirPath(const std::string &fn)
Definition
test_helper.hpp:193
content1
std::string content1
Definition
test_misc_unix.cpp:7
content2
std::string content2
Definition
test_misc_unix.cpp:14
TEST
TEST(Misc, Tempfile)
Definition
test_misc_unix.cpp:16
test
unittests
test_misc_unix.cpp
Generated by
1.9.8