1 //===-- Unittests for getenv ----------------------------------------------===//
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 "src/stdlib/getenv.h"
11 #include "test/IntegrationTest/test.h"
13 static bool my_streq(const char *lhs
, const char *rhs
) {
16 if (((lhs
== static_cast<char *>(nullptr)) &&
17 (rhs
!= static_cast<char *>(nullptr))) ||
18 ((lhs
!= static_cast<char *>(nullptr)) &&
19 (rhs
== static_cast<char *>(nullptr)))) {
23 for (l
= lhs
, r
= rhs
; *l
!= '\0' && *r
!= '\0'; ++l
, ++r
)
27 return *l
== '\0' && *r
== '\0';
30 TEST_MAIN(int argc
, char **argv
, char **envp
) {
32 my_streq(LIBC_NAMESPACE::getenv(""), static_cast<char *>(nullptr)));
34 my_streq(LIBC_NAMESPACE::getenv("="), static_cast<char *>(nullptr)));
35 ASSERT_TRUE(my_streq(LIBC_NAMESPACE::getenv("MISSING ENV VARIABLE"),
36 static_cast<char *>(nullptr)));
38 my_streq(LIBC_NAMESPACE::getenv("PATH"), static_cast<char *>(nullptr)));
39 ASSERT_TRUE(my_streq(LIBC_NAMESPACE::getenv("FRANCE"), "Paris"));
40 ASSERT_FALSE(my_streq(LIBC_NAMESPACE::getenv("FRANCE"), "Berlin"));
41 ASSERT_TRUE(my_streq(LIBC_NAMESPACE::getenv("GERMANY"), "Berlin"));
43 my_streq(LIBC_NAMESPACE::getenv("FRANC"), static_cast<char *>(nullptr)));
44 ASSERT_TRUE(my_streq(LIBC_NAMESPACE::getenv("FRANCE1"),
45 static_cast<char *>(nullptr)));