summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-05-03 00:36:57 +0000
committerEric Fiselier <eric@efcs.ca>2016-05-03 00:36:57 +0000
commit4df2666da18129c9cedd401def06d906a47f41c3 (patch)
treee444e1092060d785f36daa8a698de3423b2ef76b /libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
parent2b34def6622dd34f033cca1cf93091b377bf69b3 (diff)
downloadbcm5719-llvm-4df2666da18129c9cedd401def06d906a47f41c3.tar.gz
bcm5719-llvm-4df2666da18129c9cedd401def06d906a47f41c3.zip
Guard use of <unistd.h> in test.
llvm-svn: 268346
Diffstat (limited to 'libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp')
-rw-r--r--libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
index dfeccc81e30..9709484eb42 100644
--- a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
@@ -22,7 +22,11 @@
#include <random>
#include <system_error>
#include <cassert>
+
+#if !defined(_WIN32)
#include <unistd.h>
+#endif
+
bool is_valid_random_device(const std::string &token) {
#if defined(_LIBCPP_USING_DEV_RANDOM)
@@ -41,32 +45,19 @@ void check_random_device_invalid(const std::string &token) {
try {
std::random_device r(token);
assert(false);
- } catch (const std::system_error &e) {
+ } catch (const std::system_error&) {
}
}
-int main() {
- { std::random_device r; }
+int main() {
{
- int ec;
- ec = close(STDIN_FILENO);
- assert(!ec);
- ec = close(STDOUT_FILENO);
- assert(!ec);
- ec = close(STDERR_FILENO);
- assert(!ec);
std::random_device r;
}
-
{
std::string token = "wrong file";
- if (is_valid_random_device(token))
- check_random_device_valid(token);
- else
- check_random_device_invalid(token);
+ check_random_device_invalid(token);
}
-
{
std::string token = "/dev/urandom";
if (is_valid_random_device(token))
@@ -74,7 +65,6 @@ int main() {
else
check_random_device_invalid(token);
}
-
{
std::string token = "/dev/random";
if (is_valid_random_device(token))
@@ -82,4 +72,19 @@ int main() {
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;
+ ec = close(STDIN_FILENO);
+ assert(!ec);
+ ec = close(STDOUT_FILENO);
+ assert(!ec);
+ ec = close(STDERR_FILENO);
+ assert(!ec);
+ std::random_device r;
+ }
+#endif // !defined(_WIN32)
}
OpenPOWER on IntegriCloud