forked from irods/irods
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ 7098] Add utility to generate random alphanumeric strings
Adds a function which randomly generates an alphanumeric character and concatenates a string which is returned to the user. Unit tests included.
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set(IRODS_TEST_TARGET irods_random) | ||
|
||
set(IRODS_TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/test_random.cpp) | ||
|
||
set(IRODS_TEST_INCLUDE_PATH ${IRODS_EXTERNALS_FULLPATH_FMT}/include) | ||
|
||
set(IRODS_TEST_LINK_LIBRARIES irods_common | ||
${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "irods/irods_exception.hpp" | ||
#include "irods/irods_random.hpp" | ||
|
||
#include <algorithm> | ||
#include <cctype> | ||
#include <string> | ||
|
||
TEST_CASE("test_generate_random_alphanumeric_string") | ||
{ | ||
SECTION("zero length") | ||
{ | ||
CHECK(irods::generate_random_alphanumeric_string(0).empty()); | ||
} | ||
|
||
SECTION("one character") | ||
{ | ||
constexpr std::size_t character_count = 1; | ||
const auto s = irods::generate_random_alphanumeric_string(character_count); | ||
REQUIRE(!s.empty()); | ||
CHECK(s.size() == character_count); | ||
CHECK(std::all_of(std::begin(s), std::end(s), [](const auto& c) { return std::isalnum(c); })); | ||
} | ||
|
||
SECTION("a lot of characters") | ||
{ | ||
constexpr std::size_t character_count = 1'000'000; | ||
const auto s = irods::generate_random_alphanumeric_string(character_count); | ||
REQUIRE(!s.empty()); | ||
CHECK(s.size() == character_count); | ||
CHECK(std::all_of(std::begin(s), std::end(s), [](const auto& c) { return std::isalnum(c); })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters