reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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 -------------------------------------*- C++ -*-===//
//
// 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]);
}