[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / lldb / unittests / Utility / EnvironmentTest.cpp
blobbbc9b1245649ffd606947a9ea1b3d117569bc2a7
1 //===-- EnvironmentTest.cpp -----------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
11 #include "lldb/Utility/Environment.h"
13 using namespace lldb_private;
15 TEST(EnvironmentTest, EnvpConstruction) {
16 const char **Envp1 = nullptr;
17 EXPECT_EQ(0u, Environment(Envp1).size());
19 const char *Envp2[] = {"FOO=BAR", nullptr};
20 EXPECT_EQ("BAR", Environment(Envp2).lookup("FOO"));
22 const char *Envp3[] = {"FOO=BAR", "FOO=BAZ", nullptr};
23 EXPECT_EQ("BAR", Environment(Envp3).lookup("FOO"));
25 const char *Envp4[] = {"FOO=", "BAR", nullptr};
26 Environment Env4(Envp4);
27 ASSERT_EQ(2u, Env4.size());
28 EXPECT_EQ("", Environment(Envp4).find("FOO")->second);
29 EXPECT_EQ("", Environment(Envp4).find("BAR")->second);
31 const char *Envp5[] = {"FOO=BAR=BAZ", nullptr};
32 EXPECT_EQ("BAR=BAZ", Environment(Envp5).lookup("FOO"));
35 TEST(EnvironmentTest, EnvpConversion) {
36 std::string FOO_EQ_BAR("FOO=BAR");
37 std::string BAR_EQ_BAZ("BAR=BAZ");
39 Environment Env;
40 Env.insert(FOO_EQ_BAR);
41 Env.insert(BAR_EQ_BAZ);
42 Environment::Envp Envp = Env.getEnvp();
43 const char *const *Envp_ = Envp;
45 EXPECT_TRUE(FOO_EQ_BAR == Envp_[0] || FOO_EQ_BAR == Envp_[1]);
46 EXPECT_TRUE(BAR_EQ_BAZ == Envp_[0] || BAR_EQ_BAZ == Envp_[1]);
47 EXPECT_EQ(nullptr, Envp_[2]);