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 //===----------------------------------------------------------------------===//
11 #ifndef INTEGRATION_DISABLE_PRINTF
12 #include "src/stdio/sprintf.h"
15 #include "test/IntegrationTest/test.h"
17 static bool my_streq(const char *lhs
, const char *rhs
) {
20 if (((lhs
== static_cast<char *>(nullptr)) &&
21 (rhs
!= static_cast<char *>(nullptr))) ||
22 ((lhs
!= static_cast<char *>(nullptr)) &&
23 (rhs
== static_cast<char *>(nullptr)))) {
27 for (l
= lhs
, r
= rhs
; *l
!= '\0' && *r
!= '\0'; ++l
, ++r
)
31 return *l
== '\0' && *r
== '\0';
34 static int my_strlen(const char *str
) {
35 const char *other
= str
;
38 return static_cast<int>(other
- str
);
41 TEST_MAIN(int argc
, char **argv
, char **envp
) {
43 ASSERT_TRUE(my_streq(argv
[1], "%s %c %d"));
44 ASSERT_EQ(my_strlen(argv
[1]), 8);
45 ASSERT_TRUE(my_streq(argv
[2], "First arg"));
46 ASSERT_EQ(my_strlen(argv
[2]), 9);
47 ASSERT_TRUE(my_streq(argv
[3], "a"));
48 ASSERT_EQ(my_strlen(argv
[3]), 1);
49 ASSERT_TRUE(my_streq(argv
[4], "0"));
50 ASSERT_EQ(my_strlen(argv
[4]), 1);
52 #ifndef INTEGRATION_DISABLE_PRINTF
55 LIBC_NAMESPACE::sprintf(buf
, argv
[1], argv
[2], argv
[3][0], argv
[4][0]),
57 ASSERT_TRUE(my_streq(buf
, "First arg a 48"));