File: nonce_generator_tests.cpp

package info (click to toggle)
cpprest 2.10.19-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,916 kB
  • sloc: cpp: 71,086; sh: 275; makefile: 170; javascript: 147
file content (60 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (3)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/***
 * Copyright (C) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 *
 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 *
 * nonce_generator_tests.cpp
 *
 * Tests for nonce_generator class.
 *
 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 ****/

#include "stdafx.h"

using namespace utility;

namespace tests
{
namespace functional
{
namespace utils_tests
{
SUITE(nonce_generator_tests)
{
    TEST(nonce_generator_set_length)
    {
        utility::nonce_generator gen;
        VERIFY_ARE_EQUAL(utility::nonce_generator::default_length, gen.generate().length());

        gen.set_length(1);
        VERIFY_ARE_EQUAL(1, gen.generate().length());

        gen.set_length(0);
        VERIFY_ARE_EQUAL(0, gen.generate().length());

        gen.set_length(500);
        VERIFY_ARE_EQUAL(500, gen.generate().length());
    }

    TEST(nonce_generator_unique_strings)
    {
        // Generate 100 nonces and check each is unique.
        std::vector<utility::string_t> nonces(100);
        utility::nonce_generator gen;
        for (auto&& v : nonces)
        {
            v = gen.generate();
        }
        for (auto v : nonces)
        {
            VERIFY_ARE_EQUAL(1, std::count(nonces.begin(), nonces.end(), v));
        }
    }

} // SUITE(nonce_generator_tests)

} // namespace utils_tests
} // namespace functional
} // namespace tests