mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 20:29:39 +08:00
Guard use of <unistd.h> in test.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@268346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -22,7 +22,11 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool is_valid_random_device(const std::string &token) {
|
bool is_valid_random_device(const std::string &token) {
|
||||||
#if defined(_LIBCPP_USING_DEV_RANDOM)
|
#if defined(_LIBCPP_USING_DEV_RANDOM)
|
||||||
@@ -41,13 +45,37 @@ void check_random_device_invalid(const std::string &token) {
|
|||||||
try {
|
try {
|
||||||
std::random_device r(token);
|
std::random_device r(token);
|
||||||
assert(false);
|
assert(false);
|
||||||
} catch (const std::system_error &e) {
|
} catch (const std::system_error&) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
{ std::random_device r; }
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
{
|
||||||
|
std::random_device r;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string token = "wrong file";
|
||||||
|
check_random_device_invalid(token);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string token = "/dev/urandom";
|
||||||
|
if (is_valid_random_device(token))
|
||||||
|
check_random_device_valid(token);
|
||||||
|
else
|
||||||
|
check_random_device_invalid(token);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string token = "/dev/random";
|
||||||
|
if (is_valid_random_device(token))
|
||||||
|
check_random_device_valid(token);
|
||||||
|
else
|
||||||
|
check_random_device_invalid(token);
|
||||||
|
}
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
// Test that random_device(const string&) properly handles getting
|
||||||
|
// a file descriptor with the value '0'. Do this by closing the standard
|
||||||
|
// streams so that the descriptor '0' is available.
|
||||||
{
|
{
|
||||||
int ec;
|
int ec;
|
||||||
ec = close(STDIN_FILENO);
|
ec = close(STDIN_FILENO);
|
||||||
@@ -58,28 +86,5 @@ int main() {
|
|||||||
assert(!ec);
|
assert(!ec);
|
||||||
std::random_device r;
|
std::random_device r;
|
||||||
}
|
}
|
||||||
|
#endif // !defined(_WIN32)
|
||||||
{
|
|
||||||
std::string token = "wrong file";
|
|
||||||
if (is_valid_random_device(token))
|
|
||||||
check_random_device_valid(token);
|
|
||||||
else
|
|
||||||
check_random_device_invalid(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::string token = "/dev/urandom";
|
|
||||||
if (is_valid_random_device(token))
|
|
||||||
check_random_device_valid(token);
|
|
||||||
else
|
|
||||||
check_random_device_invalid(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::string token = "/dev/random";
|
|
||||||
if (is_valid_random_device(token))
|
|
||||||
check_random_device_valid(token);
|
|
||||||
else
|
|
||||||
check_random_device_invalid(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user