| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: no-random-device |
| 10 |
|
| 11 |
// <random> |
| 12 |
|
| 13 |
// class random_device; |
| 14 |
|
| 15 |
// result_type operator()(); |
| 16 |
|
| 17 |
#include <random> |
| 18 |
#include <cassert> |
| 19 |
#include <string> |
| 20 |
#include <system_error> |
| 21 |
|
| 22 |
#include "test_macros.h" |
| 23 |
|
| 24 |
int main(int, char**) |
| 25 |
{ |
| 26 |
{ |
| 27 |
std::random_device r; |
| 28 |
std::random_device::result_type e = r(); |
| 29 |
((void)e); // Prevent unused warning |
| 30 |
} |
| 31 |
|
| 32 |
// When using the `/dev/urandom` implementation, make sure that we throw |
| 33 |
// an exception when we hit EOF while reading the custom-provided file. |
| 34 |
#if !defined(TEST_HAS_NO_EXCEPTIONS) && defined(_LIBCPP_USING_DEV_RANDOM) |
| 35 |
{ |
| 36 |
std::random_device r("/dev/null"); |
| 37 |
try { |
| 38 |
(void)r(); |
| 39 |
LIBCPP_ASSERT(false); |
| 40 |
} catch (const std::system_error&) { |
| 41 |
} |
| 42 |
} |
| 43 |
#endif |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |