From 767f3d37ec71b13ed72ea07c9b0b3ff476af3307 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Mon, 1 Nov 2021 02:52:33 +0200 Subject: [PATCH] test: Extract common test utilities to separate file --- src/test/global/TestUtils.cpp | 37 +++++++++++++++++++++ src/test/global/TestUtils.h | 30 +++++++++++++++++ src/test/unittests/net/SecureUtilsTests.cpp | 22 +++--------- 3 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 src/test/global/TestUtils.cpp create mode 100644 src/test/global/TestUtils.h diff --git a/src/test/global/TestUtils.cpp b/src/test/global/TestUtils.cpp new file mode 100644 index 00000000..2aa7ca18 --- /dev/null +++ b/src/test/global/TestUtils.cpp @@ -0,0 +1,37 @@ +/* + barrier -- mouse and keyboard sharing utility + Copyright (C) Barrier contributors + + This package is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + found in the file LICENSE that should have accompanied this file. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "TestUtils.h" +#include + +namespace barrier { + +std::string generate_pseudo_random_bytes(std::size_t seed, std::size_t size) +{ + std::mt19937_64 engine{seed}; + std::uniform_int_distribution dist{0, 255}; + std::vector bytes; + + bytes.reserve(size); + for (std::size_t i = 0; i < size; ++i) { + bytes.push_back(dist(engine)); + } + + return std::string{bytes.data(), bytes.size()}; +} + +} // namespace barrier diff --git a/src/test/global/TestUtils.h b/src/test/global/TestUtils.h new file mode 100644 index 00000000..b27e2c6e --- /dev/null +++ b/src/test/global/TestUtils.h @@ -0,0 +1,30 @@ +/* + barrier -- mouse and keyboard sharing utility + Copyright (C) Barrier contributors + + This package is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + found in the file LICENSE that should have accompanied this file. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef BARRIER_TEST_GLOBAL_TEST_UTILS_H +#define BARRIER_TEST_GLOBAL_TEST_UTILS_H + +#include +#include + +namespace barrier { + +std::string generate_pseudo_random_bytes(std::size_t seed, std::size_t size); + +} // namespace barrier + +#endif // BARRIER_TEST_GLOBAL_TEST_UTILS_H diff --git a/src/test/unittests/net/SecureUtilsTests.cpp b/src/test/unittests/net/SecureUtilsTests.cpp index a77f158f..eb5ae498 100644 --- a/src/test/unittests/net/SecureUtilsTests.cpp +++ b/src/test/unittests/net/SecureUtilsTests.cpp @@ -18,25 +18,9 @@ #include "net/SecureUtils.h" #include "test/global/gtest.h" -#include +#include "test/global/TestUtils.h" -namespace { - -std::string generate_pseudo_random_bytes(std::size_t seed, std::size_t size) -{ - std::mt19937_64 engine{seed}; - std::uniform_int_distribution dist{0, 255}; - std::vector bytes; - - bytes.reserve(size); - for (std::size_t i = 0; i < size; ++i) { - bytes.push_back(dist(engine)); - } - - return std::string{bytes.data(), bytes.size()}; -} - -} // namespace +namespace barrier { TEST(SecureUtilsTest, FormatSslFingerprintHexWithSeparators) { @@ -45,3 +29,5 @@ TEST(SecureUtilsTest, FormatSslFingerprintHexWithSeparators) "28:FD:0A:98:8A:0E:A1:6C:D7:E8:6C:A7:EE:58:41:71:" "CA:B2:8E:49:25:94:90:25:26:05:8D:AF:63:ED:2E:30"); } + +} // namespace barrier