Skip to content

Commit

Permalink
test: crypto testcase added
Browse files Browse the repository at this point in the history
* testcase added to crypto module for code coverage

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Aug 8, 2024
1 parent 1bb62c0 commit 87095e6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/faker-cxx/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ FAKER_CXX_EXPORT std::string sha256(std::optional<std::string> = std::nullopt);
* @endcode
*/
FAKER_CXX_EXPORT std::string md5(std::optional<std::string> = std::nullopt);
}
}
42 changes: 42 additions & 0 deletions tests/modules/crypto_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ TEST_F(CryptoTest, ChecksSHA256Hash)
ASSERT_TRUE(isSHA256Hash(generatedRandomHash));
}

TEST_F(CryptoTest, ShouldGenerateSHA256HashWithData)
{
const auto generatedRandomHash = sha256("SHA256 TEST");

ASSERT_EQ(generatedRandomHash.length(), 64);
}

TEST_F(CryptoTest, ChecksSHA256HashWithData)
{
const auto generatedRandomHash = sha256("SHA256 TEST");

ASSERT_TRUE(isSHA256Hash(generatedRandomHash));
}

TEST_F(CryptoTest, ShouldGenerateSHA256HashWithLongData)
{
const auto generatedRandomHash = sha256("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde978");

ASSERT_EQ(generatedRandomHash.length(), 64);
}

TEST_F(CryptoTest, ChecksSHA256HashWithLongData)
{
const auto generatedRandomHash = sha256("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde978");

ASSERT_TRUE(isSHA256Hash(generatedRandomHash));
}

TEST_F(CryptoTest, ShouldGenerateMD5Hash)
{
const auto generatedRandomHash = md5();
Expand All @@ -53,3 +81,17 @@ TEST_F(CryptoTest, ChecksMD5Regex)

ASSERT_TRUE(isMD5Hash(generatedRandomHash));
}

TEST_F(CryptoTest, ShouldGenerateMD5HashWithData)
{
const auto generatedRandomHash = md5("MD5 TEST");

ASSERT_EQ(generatedRandomHash.length(), 32);
}

TEST_F(CryptoTest, ChecksMD5RegexWithData)
{
const auto generatedRandomHash = md5("MD5 TEST");

ASSERT_TRUE(isMD5Hash(generatedRandomHash));
}

0 comments on commit 87095e6

Please sign in to comment.