text
stringlengths
0
2.2M
//: the supplied memory
//:
//: 6 The method behaves as expected when input length is not a
//: multiple of the supplied RNG 'result_type'.
//:
//: 7 'generateSeed' does a BSLS_ASSERT to check for null pointers or
//: zero length.
//
// Plan:
//: 1 Create a 'SeedGenerator' with a predictable RNG and test that the
//: values written to memory match the output of the RNG. (C-1,2)
//:
//: 2 Pre-load memory with known data, and test that it is all
//: overwritten after a call to 'generateSeed'. (C-3)
//:
//: 3 Pre-load memory with known data, and test that memory beyond the
//: end of the specified memory is not overwritten after a call to
//: 'generateSeed' (C-4)
//:
//: 4 Call 'generateSeed' with a length of zero and verify the RNG was
//: not called, and the supplied memory was not written. (C-6)
//:
//: 5 Call 'generateSeed' with lengths that are not multiples of the
//: size of 'MockRNG::result_type'. (C-6)
//:
//: 6 Call 'generateSeed' with combinations of a null pointer and a 0
//: length. (C-7)
//
// Testing:
// void generateSeed(char *seedLocation, size_t seedLength)
// --------------------------------------------------------------------
if (verbose)
printf("\nTESTING 'generateSeed'"
"\n======================\n");
if (verbose) printf("Create a 'SeedGenerator' with a predictable RNG"
" and test that the values written to memory match"
" the output of the RNG. (C-1,2)\n");
{
MockRNG rng;
Obj generator(rng);
char seed[8];
generator.generateSeed(seed, 8);
verifyResultMatchesRNG(seed, 8);
}
if (verbose) printf("Preload memory with known data, and test that it"
" is all overwritten after a call to"
" 'generateSeed'. (C-3)\n");
{
MockRNG rng;
Obj generator(rng);
char seed[8];
const char maxChar = static_cast<char>(255);
fill(seed, 8, maxChar);
generator.generateSeed(seed, 8);
verifyResultMatchesRNG(seed, 8);
}
if (verbose) printf("Preload memory with known data, and test that"
" memory beyond the end of the specified memory is"
" not overwritten after a call to 'generateSeed'"
" (C-4)\n");
{
MockRNG rng;
Obj generator(rng);
char seed[24];
const char maxChar = static_cast<char>(255);
fill(seed, 24, maxChar);
generator.generateSeed(&seed[8], 8);
for (int i = 0; i < 8; ++i) {
if (veryVerbose) printf("Asserting seed[%i]: %hhu from"
" generated seed is inchanged\n",
i ,
seed[i]);
ASSERT(seed[i] == maxChar);
}
verifyResultMatchesRNG(&seed[8], 8);
for (int i = 16; i < 24; ++i) {
if (veryVerbose) printf("Asserting seed[%i]: %hhu from"
" generated seed is inchanged\n",
i ,
seed[i]);
ASSERT(seed[i] == maxChar);
}
}
if (verbose) printf("Call 'generateSeed' with a length of zero and"