1 //===- unittest/Support/ProcessTest.cpp -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/Process.h"
11 #include "gtest/gtest.h"
22 TEST(ProcessTest, GetRandomNumberTest) {
23 const unsigned r1 = Process::GetRandomNumber();
24 const unsigned r2 = Process::GetRandomNumber();
25 // It should be extremely unlikely that both r1 and r2 are 0.
26 EXPECT_NE((r1 | r2), 0u);
30 #define setenv(name, var, ignore) _putenv_s(name, var)
33 #if HAVE_SETENV || _MSC_VER
34 TEST(ProcessTest, Basic) {
35 setenv("__LLVM_TEST_ENVIRON_VAR__", "abc", true);
36 Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
37 EXPECT_TRUE(val.hasValue());
38 EXPECT_STREQ("abc", val->c_str());
41 TEST(ProcessTest, None) {
42 Optional<std::string> val(
43 Process::GetEnv("__LLVM_TEST_ENVIRON_NO_SUCH_VAR__"));
44 EXPECT_FALSE(val.hasValue());
49 TEST(ProcessTest, Wchar) {
50 SetEnvironmentVariableW(L"__LLVM_TEST_ENVIRON_VAR__", L"abcdefghijklmnopqrs");
51 Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
52 EXPECT_TRUE(val.hasValue());
53 EXPECT_STREQ("abcdefghijklmnopqrs", val->c_str());
57 } // end anonymous namespace