1 //===- unittest/Support/ProcessTest.cpp -----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/Process.h"
10 #include "gtest/gtest.h"
21 TEST(ProcessTest
, GetRandomNumberTest
) {
22 const unsigned r1
= Process::GetRandomNumber();
23 const unsigned r2
= Process::GetRandomNumber();
24 // It should be extremely unlikely that both r1 and r2 are 0.
25 EXPECT_NE((r1
| r2
), 0u);
29 #define setenv(name, var, ignore) _putenv_s(name, var)
32 #if HAVE_SETENV || _MSC_VER
33 TEST(ProcessTest
, Basic
) {
34 setenv("__LLVM_TEST_ENVIRON_VAR__", "abc", true);
35 Optional
<std::string
> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
36 EXPECT_TRUE(val
.hasValue());
37 EXPECT_STREQ("abc", val
->c_str());
40 TEST(ProcessTest
, None
) {
41 Optional
<std::string
> val(
42 Process::GetEnv("__LLVM_TEST_ENVIRON_NO_SUCH_VAR__"));
43 EXPECT_FALSE(val
.hasValue());
49 TEST(ProcessTest
, EmptyVal
) {
50 SetEnvironmentVariableA("__LLVM_TEST_ENVIRON_VAR__", "");
51 Optional
<std::string
> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
52 EXPECT_TRUE(val
.hasValue());
53 EXPECT_STREQ("", val
->c_str());
56 TEST(ProcessTest
, Wchar
) {
57 SetEnvironmentVariableW(L
"__LLVM_TEST_ENVIRON_VAR__", L
"abcdefghijklmnopqrs");
58 Optional
<std::string
> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
59 EXPECT_TRUE(val
.hasValue());
60 EXPECT_STREQ("abcdefghijklmnopqrs", val
->c_str());
64 } // end anonymous namespace