184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania/*
284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * Copyright (C) 2009 The Android Open Source Project
384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * All rights reserved.
484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *
584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * Redistribution and use in source and binary forms, with or without
684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * modification, are permitted provided that the following conditions
784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * are met:
884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *  * Redistributions of source code must retain the above copyright
984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *    notice, this list of conditions and the following disclaimer.
1084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *  * Redistributions in binary form must reproduce the above copyright
1184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *    notice, this list of conditions and the following disclaimer in
1284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *    the documentation and/or other materials provided with the
1384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *    distribution.
1484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania *
1584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania * SUCH DAMAGE.
2784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania */
281aa5708e437b96e04f31d9c9f167427411ba5510Niko Catania
291aa5708e437b96e04f31d9c9f167427411ba5510Niko Catania
3084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania#include <climits>
31b381ead492251a797d2df4b260cb01eb1f64cfadDavid 'Digit' Turner#if defined BIONIC && !defined BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
321aa5708e437b96e04f31d9c9f167427411ba5510Niko Catania#error "Wrong header file included!!"
331aa5708e437b96e04f31d9c9f167427411ba5510Niko Catania#endif
341aa5708e437b96e04f31d9c9f167427411ba5510Niko Catania
3584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
3684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catanianamespace {
3784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Cataniaconst int kPassed = 0;
3884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Cataniaconst int kFailed = 1;
3984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania#define FAIL_UNLESS(f) if (!android::f()) return kFailed;
4084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania}  // anonymous namespace
4184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
4284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catanianamespace android
4384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania{
4484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Cataniabool testLimits()
4584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania{
4684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // char
4784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile char c1 = CHAR_BIT;
4884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile char c2 = CHAR_MAX;
4984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile char c3 = CHAR_MIN;
5084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
5184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // int
5284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile int i1 = INT_MAX;
5384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile int i2 = INT_MIN;
5484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
5584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // short
5684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile short s1 = SHRT_MAX;
5784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile short s2 = SHRT_MIN;
5884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
5984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // long
6084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile long l1 = LONG_MAX;
6184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile long l2 = LONG_MIN;
6284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
6384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // long long
6484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile long long ll1 = LLONG_MAX;
6584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile long long ll2 = LLONG_MIN;
6684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
6784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile unsigned long mb = MB_LEN_MAX;
6884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
6984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // signed char
7084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile signed char sc1 = SCHAR_MIN;
7184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile signed char sc2 = SCHAR_MAX;
7284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
7384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    // unsigned
7484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile unsigned int ui = UINT_MAX;
7584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile unsigned short us = USHRT_MAX;
7684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile unsigned long ul = ULONG_MAX;
7784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    volatile unsigned long long ull = ULLONG_MAX;
7884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
7984011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    return true;
8084011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania}
8184011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
8284011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania}  // namespace android
8384011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania
8484011c7599ab8a4463cefda5e8ce8a59987640d8Niko Cataniaint main(int argc, char **argv)
8584011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania{
8684011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    FAIL_UNLESS(testLimits);
8784011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania    return kPassed;
8884011c7599ab8a4463cefda5e8ce8a59987640d8Niko Catania}
89