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
16
17using namespace openvpn;
18
19static 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
27TEST(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}
A string-like type that clears the buffer contents on delete.
Definition safestr.hpp:27
const char * c_str() const
Definition safestr.hpp:55
std::string to_string() const
Definition safestr.hpp:64
static void compare(const SafeString &s1, const SafeString &s2, const bool expect_eq)
TEST(safestr, test_1)