]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - tests/inttypes_test.cpp
Switch aarch64 to __builtin_bswap16.
[android-sdk/platform-bionic.git] / tests / inttypes_test.cpp
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
17 #include <inttypes.h>
19 #include <errno.h>
20 #include <gtest/gtest.h>
21 #include <stdio.h>
23 TEST(inttypes, misc) {
24   char buf[512];
26   intptr_t i = 0;
27   uintptr_t u = 0;
29   snprintf(buf, sizeof(buf), "%08" PRIdPTR, i);
30   snprintf(buf, sizeof(buf), "%08" PRIiPTR, i);
31   snprintf(buf, sizeof(buf), "%08" PRIoPTR, i);
32   snprintf(buf, sizeof(buf), "%08" PRIuPTR, u);
33   snprintf(buf, sizeof(buf), "%08" PRIxPTR, u);
34   snprintf(buf, sizeof(buf), "%08" PRIXPTR, u);
36   sscanf(buf, "%08" SCNdPTR, &i);
37   sscanf(buf, "%08" SCNiPTR, &i);
38   sscanf(buf, "%08" SCNoPTR, &u);
39   sscanf(buf, "%08" SCNuPTR, &u);
40   sscanf(buf, "%08" SCNxPTR, &u);
41 }
43 TEST(inttypes, wcstoimax) {
44   ASSERT_EQ(123, wcstoimax(L"123", NULL, 10));
45 }
47 TEST(inttypes, wcstoumax) {
48   ASSERT_EQ(123U, wcstoumax(L"123", NULL, 10));
49 }
51 TEST(inttypes, strtoimax_EINVAL) {
52   errno = 0;
53   strtoimax("123", NULL, -1);
54   ASSERT_EQ(EINVAL, errno);
55   errno = 0;
56   strtoimax("123", NULL, 1);
57   ASSERT_EQ(EINVAL, errno);
58   errno = 0;
59   strtoimax("123", NULL, 37);
60   ASSERT_EQ(EINVAL, errno);
61 }
63 TEST(inttypes, strtoumax_EINVAL) {
64   errno = 0;
65   strtoumax("123", NULL, -1);
66   ASSERT_EQ(EINVAL, errno);
67   errno = 0;
68   strtoumax("123", NULL, 1);
69   ASSERT_EQ(EINVAL, errno);
70   errno = 0;
71   strtoumax("123", NULL, 37);
72   ASSERT_EQ(EINVAL, errno);
73 }
75 TEST(inttypes, wcstoimax_EINVAL) {
76   errno = 0;
77   wcstoimax(L"123", NULL, -1);
78   ASSERT_EQ(EINVAL, errno);
79   errno = 0;
80   wcstoimax(L"123", NULL, 1);
81   ASSERT_EQ(EINVAL, errno);
82   errno = 0;
83   wcstoimax(L"123", NULL, 37);
84   ASSERT_EQ(EINVAL, errno);
85 }
87 TEST(inttypes, wcstoumax_EINVAL) {
88   errno = 0;
89   wcstoumax(L"123", NULL, -1);
90   ASSERT_EQ(EINVAL, errno);
91   errno = 0;
92   wcstoumax(L"123", NULL, 1);
93   ASSERT_EQ(EINVAL, errno);
94   errno = 0;
95   wcstoumax(L"123", NULL, 37);
96   ASSERT_EQ(EINVAL, errno);
97 }