1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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/. */
10 #include "js/Conversions.h"
12 #include "jsapi-tests/tests.h"
14 using JS::ToSignedInteger
;
15 using JS::ToUnsignedInteger
;
17 BEGIN_TEST(testToUint8TwiceUint8Range
) {
21 CHECK(ToUnsignedInteger
<uint8_t>(d
) == expected
);
28 END_TEST(testToUint8TwiceUint8Range
)
30 BEGIN_TEST(testToInt8
) {
32 int8_t expected
= -128;
34 CHECK(ToSignedInteger
<int8_t>(d
) == expected
);
38 } while (expected
< 127);
43 BEGIN_TEST(testToUint32Large
) {
44 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 83)) == 0);
45 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 83) + pow(2.0, 31)) == (1U << 31));
46 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 83) + 2 * pow(2.0, 31)) == 0);
47 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 83) + 3 * pow(2.0, 31)) ==
49 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 84)) == 0);
50 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 84) + pow(2.0, 31)) == 0);
51 CHECK(ToUnsignedInteger
<uint32_t>(pow(2.0, 84) + pow(2.0, 32)) == 0);
54 END_TEST(testToUint32Large
)
56 BEGIN_TEST(testToUint64Large
) {
57 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 115)) == 0);
58 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 115) + pow(2.0, 63)) ==
60 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 115) + 2 * pow(2.0, 63)) == 0);
61 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 115) + 3 * pow(2.0, 63)) ==
63 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 116)) == 0);
64 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 116) + pow(2.0, 63)) == 0);
65 CHECK(ToUnsignedInteger
<uint64_t>(pow(2.0, 116) + pow(2.0, 64)) == 0);
68 END_TEST(testToUint64Large
)