summaryrefslogtreecommitdiff
path: root/test/include/ossl_random.cpp
blob: 1b9a2b88dac97d0ef0a96e6a89a2cee9ab73accf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "ossl_random.hpp"

#include <gmock/gmock.h> // IWYU pragma: keep
#include <gtest/gtest.h> // IWYU pragma: keep

namespace
{

using testing::IsEmpty;
using testing::MatchesRegex;

TEST(Bmcweb, GetRandomUUID)
{
    using bmcweb::getRandomUUID;
    // 78e96a4b-62fe-48d8-ac09-7f75a94671e0
    EXPECT_THAT(
        getRandomUUID(),
        MatchesRegex(
            "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"));
}

TEST(Bmcweb, GetRandomIdOfLength)
{
    using bmcweb::getRandomIdOfLength;
    EXPECT_THAT(getRandomIdOfLength(1), MatchesRegex("^[a-zA-Z0-9]$"));
    EXPECT_THAT(getRandomIdOfLength(10), MatchesRegex("^[a-zA-Z0-9]{10}$"));
    EXPECT_THAT(getRandomIdOfLength(0), IsEmpty());
}

} // namespace