diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /security/nss/gtests/util_gtest/util_select_unittest.cc | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'security/nss/gtests/util_gtest/util_select_unittest.cc')
-rw-r--r-- | security/nss/gtests/util_gtest/util_select_unittest.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/security/nss/gtests/util_gtest/util_select_unittest.cc b/security/nss/gtests/util_gtest/util_select_unittest.cc new file mode 100644 index 0000000000..f62357c9b3 --- /dev/null +++ b/security/nss/gtests/util_gtest/util_select_unittest.cc @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "gtest/gtest.h" +#include "scoped_ptrs_util.h" + +namespace nss_test { + +class SelectTest : public ::testing::Test { + protected: + void test_select(std::vector<uint8_t> &dest, const std::vector<uint8_t> &src0, + const std::vector<uint8_t> &src1, unsigned char b) { + EXPECT_EQ(src0.size(), src1.size()); + EXPECT_GE(dest.size(), src0.size()); + return NSS_SecureSelect(dest.data(), src0.data(), src1.data(), src0.size(), + b); + }; +}; + +TEST_F(SelectTest, TestSelectZero) { + std::vector<uint8_t> dest(32, 255); + std::vector<uint8_t> src0(32, 0); + std::vector<uint8_t> src1(32, 1); + test_select(dest, src0, src1, 0); + EXPECT_EQ(dest, src0); +} + +TEST_F(SelectTest, TestSelectOne) { + std::vector<uint8_t> dest(32, 255); + std::vector<uint8_t> src0(32, 0); + std::vector<uint8_t> src1(32, 1); + test_select(dest, src0, src1, 1); + EXPECT_EQ(dest, src1); +} + +TEST_F(SelectTest, TestSelect170) { + std::vector<uint8_t> dest(32, 255); + std::vector<uint8_t> src0(32, 0); + std::vector<uint8_t> src1(32, 1); + test_select(dest, src0, src1, 170); + EXPECT_EQ(dest, src1); +} + +TEST_F(SelectTest, TestSelect255) { + std::vector<uint8_t> dest(32, 255); + std::vector<uint8_t> src0(32, 0); + std::vector<uint8_t> src1(32, 1); + test_select(dest, src0, src1, 255); + EXPECT_EQ(dest, src1); +} + +} // namespace nss_test |