2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <features.h> // Get __BIONIC__ or __GLIBC__ so we can tell what we're using.
20 #if defined(__GLIBC__)
22 // At the time of writing, libcxx -- which is dragged in by gtest -- assumes
23 // declarations from glibc of things that aren't available without _GNU_SOURCE.
24 // This means we can't even build this test (which is a problem because that
25 // means it doesn't get included in CTS).
26 // For glibc 2.15, the symbols in question are:
27 // at_quick_exit, quick_exit, vasprintf, strtoll_l, strtoull_l, and strtold_l.
29 # if __GLIBC_PREREQ(2, 19)
30 # error check whether we can build this now...
38 #include <gtest/gtest.h>
40 TEST(string, posix_strerror_r) {
44 ASSERT_EQ(0, strerror_r(0, buf, sizeof(buf)));
45 ASSERT_STREQ("Success", buf);
46 ASSERT_EQ(0, strerror_r(1, buf, sizeof(buf)));
47 ASSERT_STREQ("Operation not permitted", buf);
50 ASSERT_EQ(0, strerror_r(-1, buf, sizeof(buf)));
51 ASSERT_STREQ("Unknown error -1", buf);
52 ASSERT_EQ(0, strerror_r(1234, buf, sizeof(buf)));
53 ASSERT_STREQ("Unknown error 1234", buf);
57 memset(buf, 0, sizeof(buf));
58 ASSERT_EQ(-1, strerror_r(4567, buf, 2));
59 ASSERT_STREQ("U", buf);
60 // The POSIX strerror_r sets errno to ERANGE (the GNU one doesn't).
61 ASSERT_EQ(ERANGE, errno);