test_climits.cpp revision 84011c7599ab8a4463cefda5e8ce8a59987640d8
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#include <climits>
29
30namespace {
31const int kPassed = 0;
32const int kFailed = 1;
33#define FAIL_UNLESS(f) if (!android::f()) return kFailed;
34}  // anonymous namespace
35
36namespace android
37{
38bool testLimits()
39{
40    // char
41    volatile char c1 = CHAR_BIT;
42    volatile char c2 = CHAR_MAX;
43    volatile char c3 = CHAR_MIN;
44
45    // int
46    volatile int i1 = INT_MAX;
47    volatile int i2 = INT_MIN;
48
49    // short
50    volatile short s1 = SHRT_MAX;
51    volatile short s2 = SHRT_MIN;
52
53    // long
54    volatile long l1 = LONG_MAX;
55    volatile long l2 = LONG_MIN;
56
57    // long long
58    volatile long long ll1 = LLONG_MAX;
59    volatile long long ll2 = LLONG_MIN;
60
61    volatile unsigned long mb = MB_LEN_MAX;
62
63    // signed char
64    volatile signed char sc1 = SCHAR_MIN;
65    volatile signed char sc2 = SCHAR_MAX;
66
67    // unsigned
68    volatile unsigned int ui = UINT_MAX;
69    volatile unsigned short us = USHRT_MAX;
70    volatile unsigned long ul = ULONG_MAX;
71    volatile unsigned long long ull = ULLONG_MAX;
72
73    return true;
74}
75
76}  // namespace android
77
78int main(int argc, char **argv)
79{
80    FAIL_UNLESS(testLimits);
81    return kPassed;
82}
83