File: EnvironmentTest.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (48 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===-- EnvironmentTest.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"

#include "lldb/Utility/Environment.h"

using namespace lldb_private;

TEST(EnvironmentTest, EnvpConstruction) {
  const char **Envp1 = nullptr;
  EXPECT_EQ(0u, Environment(Envp1).size());

  const char *Envp2[] = {"FOO=BAR", nullptr};
  EXPECT_EQ("BAR", Environment(Envp2).lookup("FOO"));

  const char *Envp3[] = {"FOO=BAR", "FOO=BAZ", nullptr};
  EXPECT_EQ("BAR", Environment(Envp3).lookup("FOO"));

  const char *Envp4[] = {"FOO=", "BAR", nullptr};
  Environment Env4(Envp4);
  ASSERT_EQ(2u, Env4.size());
  EXPECT_EQ("", Environment(Envp4).find("FOO")->second);
  EXPECT_EQ("", Environment(Envp4).find("BAR")->second);

  const char *Envp5[] = {"FOO=BAR=BAZ", nullptr};
  EXPECT_EQ("BAR=BAZ", Environment(Envp5).lookup("FOO"));
}

TEST(EnvironmentTest, EnvpConversion) {
  std::string FOO_EQ_BAR("FOO=BAR");
  std::string BAR_EQ_BAZ("BAR=BAZ");

  Environment Env;
  Env.insert(FOO_EQ_BAR);
  Env.insert(BAR_EQ_BAZ);
  Environment::Envp Envp = Env.getEnvp();
  const char *const *Envp_ = Envp;

  EXPECT_TRUE(FOO_EQ_BAR == Envp_[0] || FOO_EQ_BAR == Envp_[1]);
  EXPECT_TRUE(BAR_EQ_BAZ == Envp_[0] || BAR_EQ_BAZ == Envp_[1]);
  EXPECT_EQ(nullptr, Envp_[2]);
}