blob: dbbb6d4ca6272c5716a014aa5b6eab610eb2aea2 [file] [log] [blame]
Elliott Hughes74f08332013-07-02 15:23:38 -07001/*
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 */
16
Elliott Hughes74f08332013-07-02 15:23:38 -070017#include <inttypes.h>
18
Elliott Hughesb05ec5a2014-09-23 14:53:10 -070019#include <errno.h>
20#include <gtest/gtest.h>
21#include <stdio.h>
22
Elliott Hughes74f08332013-07-02 15:23:38 -070023TEST(inttypes, misc) {
24 char buf[512];
25
26 intptr_t i = 0;
27 uintptr_t u = 0;
28
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);
35
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}
Elliott Hughes01ae00f2014-04-29 16:28:56 -070042
43TEST(inttypes, wcstoimax) {
44 ASSERT_EQ(123, wcstoimax(L"123", NULL, 10));
45}
46
47TEST(inttypes, wcstoumax) {
48 ASSERT_EQ(123U, wcstoumax(L"123", NULL, 10));
49}
Elliott Hughesb05ec5a2014-09-23 14:53:10 -070050
51TEST(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}
62
63TEST(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}
74
75TEST(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}
86
87TEST(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}