1f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com/*
2f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com * Copyright 2013 Google Inc.
3f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com *
4f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com * Use of this source code is governed by a BSD-style license that can be
5f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com * found in the LICENSE file.
6f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com */
7f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
8f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com#include "SkTFitsIn.h"
98f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "SkTypes.h"
108f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "Test.h"
11e4fafb146e85cdfcf9d5418597b6818aa0754adatfarina@chromium.org
12f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com#include <limits>
13f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
14f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
15f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
16e4fafb146e85cdfcf9d5418597b6818aa0754adatfarina@chromium.orgDEF_TEST(FitsIn, reporter) {
17f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  1, int8_t, true);
18f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, int8_t, true);
19f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  (int32_t)(std::numeric_limits<int8_t>::max)(),    int8_t, true);
20f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
21f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  (int32_t)(std::numeric_limits<int8_t>::min)(),    int8_t, true);
22f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
23f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
24f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  1, uint8_t, true);
25f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, uint8_t, false);
26f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  (int32_t)(std::numeric_limits<uint8_t>::max)(),    uint8_t, true);
27f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
28f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t,  0, uint8_t, true);
29f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, uint8_t, false);
30f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -127, uint8_t, false);
31f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -128, uint8_t, false);
32f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
33f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1000, int8_t, false);
34f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1000, uint8_t, false);
35f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
36f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1, int32_t, true);
37f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, int32_t, true);
38f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1, uint32_t, true);
39f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, uint32_t, false);
40f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
41f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1, int64_t, true);
42f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, int64_t, true);
43f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, 1, uint64_t, true);
44f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(int32_t, -1, uint64_t, false);
45f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
46f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, int8_t, true);
47f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, uint8_t, true);
48f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, int32_t, true);
49f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, uint32_t, true);
50f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, int64_t, true);
51f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, 1, uint64_t, true);
52f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
53f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
54f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
55f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
56f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
57f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
58f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
59f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
60f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, int8_t, true);
61f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, uint8_t, true);
62f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, int32_t, true);
63f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, uint32_t, true);
64f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, int64_t, true);
65f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    TEST(uint64_t, 1, uint64_t, true);
66f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com
67f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    // Uncommenting the following should cause compile failures.
68f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com    //TEST(float, 1, uint64_t, true);
69f5cc5b140c1c00c536e02b5cfbe158bb2d5c2c15bungeman@google.com}
70