OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_safestr.cpp
Go to the documentation of this file.
1
// OpenVPN -- An application to securely tunnel IP networks
2
// over a single port, with support for SSL/TLS-based
3
// session authentication and key exchange,
4
// packet encryption, packet authentication, and
5
// packet compression.
6
//
7
// Copyright (C) 2012- OpenVPN Inc.
8
//
9
// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10
//
11
12
13
#include "
test_common.hpp
"
14
15
#include <
openvpn/buffer/safestr.hpp
>
16
17
using namespace
openvpn
;
18
19
static
void
compare
(
const
SafeString
&s1,
const
SafeString
&s2,
const
bool
expect_eq)
20
{
21
ASSERT_EQ(s1 == s2.
c_str
(), expect_eq);
22
ASSERT_NE(s1 != s2.
c_str
(), expect_eq);
23
ASSERT_EQ(s1 == s2.
to_string
(), expect_eq);
24
ASSERT_NE(s1 != s2.
to_string
(), expect_eq);
25
}
26
27
TEST
(safestr, test_1)
28
{
29
SafeString
a(
"mybigsecret"
);
30
SafeString
b(
"mybigsekret"
);
31
SafeString
c(
"mybigsekrets"
);
32
SafeString
a2(
"mybigsecret"
);
33
34
compare
(a, a2,
true
);
35
compare
(a2, a,
true
);
36
compare
(a, b,
false
);
37
compare
(a, c,
false
);
38
compare
(b, c,
false
);
39
compare
(b, a,
false
);
40
compare
(c, a,
false
);
41
compare
(c, b,
false
);
42
}
openvpn::SafeString
A string-like type that clears the buffer contents on delete.
Definition
safestr.hpp:27
openvpn::SafeString::c_str
const char * c_str() const
Definition
safestr.hpp:55
openvpn::SafeString::to_string
std::string to_string() const
Definition
safestr.hpp:64
openvpn
Definition
ovpncli.cpp:97
safestr.hpp
test_common.hpp
compare
static void compare(const SafeString &s1, const SafeString &s2, const bool expect_eq)
Definition
test_safestr.cpp:19
TEST
TEST(safestr, test_1)
Definition
test_safestr.cpp:27
test
unittests
test_safestr.cpp
Generated by
1.9.8