js/src/jsapi-tests/testToIntWidth.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include <math.h>
    10 #include "jsapi-tests/tests.h"
    11 #include "vm/NumericConversions.h"
    13 using js::detail::ToIntWidth;
    14 using js::detail::ToUintWidth;
    16 BEGIN_TEST(testToUint8TwiceUint8Range)
    17 {
    18     double d = -256;
    19     uint8_t expected = 0;
    20     do {
    21         CHECK(ToUintWidth<uint8_t>(d) == expected);
    23         d++;
    24         expected++;
    25     } while (d <= 256);
    26     return true;
    27 }
    28 END_TEST(testToUint8TwiceUint8Range)
    30 BEGIN_TEST(testToInt8)
    31 {
    32     double d = -128;
    33     int8_t expected = -128;
    34     do {
    35         CHECK(ToIntWidth<int8_t>(d) == expected);
    37         d++;
    38         expected++;
    39     } while (expected < 127);
    40     return true;
    41 }
    42 END_TEST(testToInt8)
    44 BEGIN_TEST(testToUint32Large)
    45 {
    46     CHECK(ToUintWidth<uint32_t>(pow(2.0, 83)) == 0);
    47     CHECK(ToUintWidth<uint32_t>(pow(2.0, 83) + pow(2.0, 31)) == (1U << 31));
    48     CHECK(ToUintWidth<uint32_t>(pow(2.0, 83) + 2 * pow(2.0, 31)) == 0);
    49     CHECK(ToUintWidth<uint32_t>(pow(2.0, 83) + 3 * pow(2.0, 31)) == (1U << 31));
    50     CHECK(ToUintWidth<uint32_t>(pow(2.0, 84)) == 0);
    51     CHECK(ToUintWidth<uint32_t>(pow(2.0, 84) + pow(2.0, 31)) == 0);
    52     CHECK(ToUintWidth<uint32_t>(pow(2.0, 84) + pow(2.0, 32)) == 0);
    53     return true;
    54 }
    55 END_TEST(testToUint32Large)
    57 BEGIN_TEST(testToUint64Large)
    58 {
    59     CHECK(ToUintWidth<uint64_t>(pow(2.0, 115)) == 0);
    60     CHECK(ToUintWidth<uint64_t>(pow(2.0, 115) + pow(2.0, 63)) == (1ULL << 63));
    61     CHECK(ToUintWidth<uint64_t>(pow(2.0, 115) + 2 * pow(2.0, 63)) == 0);
    62     CHECK(ToUintWidth<uint64_t>(pow(2.0, 115) + 3 * pow(2.0, 63)) == (1ULL << 63));
    63     CHECK(ToUintWidth<uint64_t>(pow(2.0, 116)) == 0);
    64     CHECK(ToUintWidth<uint64_t>(pow(2.0, 116) + pow(2.0, 63)) == 0);
    65     CHECK(ToUintWidth<uint64_t>(pow(2.0, 116) + pow(2.0, 64)) == 0);
    66     return true;
    67 }
    68 END_TEST(testToUint64Large)

mercurial