Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions tests/test_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "test_helpers.hpp"

#include <gtest/gtest.h>
#include "../src/PasswordGen.hpp"

#include <string>
#include <vector>
Expand All @@ -8,24 +7,24 @@
using namespace std::string_literals;

// Test suite for hex encoding/decoding
class HexUtilsTest : public ::testing::Test

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'Test': base class undefined [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'Test': is not a member of '`global namespace'' [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'testing': the symbol to the left of a '::' must be a type [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'Test': base class undefined [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'Test': is not a member of '`global namespace'' [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 10 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'testing': the symbol to the left of a '::' must be a type [D:\a\seal\seal\build\seal_tests.vcxproj]
{
};

TEST_F(HexUtilsTest, ToHexBasicEncoding)

Check failure on line 14 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 14 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

syntax error: identifier 'ToHexBasicEncoding' [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 14 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 14 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

syntax error: identifier 'ToHexBasicEncoding' [D:\a\seal\seal\build\seal_tests.vcxproj]
{
std::vector<unsigned char> data = {0x00, 0xFF, 0x0A, 0xB5};
std::string hex = seal::utils::to_hex(data);

EXPECT_EQ(hex, "00ff0ab5");

Check failure on line 19 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'EXPECT_EQ': identifier not found [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 19 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'EXPECT_EQ': identifier not found [D:\a\seal\seal\build\seal_tests.vcxproj]
}

Check warning on line 20 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 20 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

TEST_F(HexUtilsTest, ToHexEmptyInput)

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

function 'int TEST_F(HexUtilsTest)' already has a body [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

syntax error: identifier 'ToHexEmptyInput' [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

function 'int TEST_F(HexUtilsTest)' already has a body [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 22 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

syntax error: identifier 'ToHexEmptyInput' [D:\a\seal\seal\build\seal_tests.vcxproj]
{
std::vector<unsigned char> empty;
std::string hex = seal::utils::to_hex(empty);

EXPECT_TRUE(hex.empty());

Check failure on line 27 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'EXPECT_TRUE': identifier not found [D:\a\seal\seal\build\seal_tests.vcxproj]

Check failure on line 27 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'EXPECT_TRUE': identifier not found [D:\a\seal\seal\build\seal_tests.vcxproj]
}

TEST_F(HexUtilsTest, ToHexSingleByte)
Expand Down Expand Up @@ -154,7 +153,7 @@
std::string result = seal::utils::stripSpaces(input);

EXPECT_EQ(result, "helloworld");
}

Check warning on line 156 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 156 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

TEST_F(StringUtilsTest, StripSpacesAllSpaces)
{
Expand Down Expand Up @@ -205,7 +204,7 @@

EXPECT_EQ(tokens.size(), 1u);
EXPECT_EQ(tokens[0], longHex);
}

Check warning on line 207 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 207 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

TEST_F(HexTokenExtractionTest, MultipleTokens)
{
Expand Down Expand Up @@ -264,3 +263,25 @@

EXPECT_TRUE(tokens.empty());
}

// Test suite for password generation
class PasswordGenTest : public ::testing::Test
{
};

TEST_F(PasswordGenTest, ClampsLength)
{
EXPECT_EQ(seal::GeneratePassword(1).size(), 8u);
EXPECT_EQ(seal::GeneratePassword(999).size(), 128u);
EXPECT_EQ(seal::GeneratePassword(20).size(), 20u);
}

Check warning on line 277 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / test

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 277 in tests/test_utils.cpp

View workflow job for this annotation

GitHub Actions / sonar

'TEST_F': function should return a value; 'void' return type assumed [D:\a\seal\seal\build\seal_tests.vcxproj]

TEST_F(PasswordGenTest, UsesDocumentedCharset)
{
static constexpr std::string_view allowed =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+";

auto password = seal::GeneratePassword(64);
for (char ch : password.view())
EXPECT_NE(allowed.find(ch), std::string_view::npos);
}
Loading