blob: 42a0badbd774137945ac260a41cefa10e4feb0c2 [file] [log] [blame]
bungeman@google.comf5cc5b12013-07-12 18:22:49 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkTypes.h"
9#include "include/private/SkTFitsIn.h"
10#include "tests/Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000011
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000012#include <limits>
13
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000014#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
15
Brian Osman50ea3c02019-02-04 10:01:53 -050016enum TestEnum_t : uint8_t {
17 kFoo,
18 kBar,
19 kBaz,
20};
21
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000022DEF_TEST(FitsIn, reporter) {
Mike Kleinb6b5b7a2018-06-11 11:56:57 -040023 TEST(uint16_t, 257, int8_t, false);
24
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000025 TEST(int32_t, 1, int8_t, true);
26 TEST(int32_t, -1, int8_t, true);
27 TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::max)(), int8_t, true);
28 TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
29 TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::min)(), int8_t, true);
30 TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
31
32 TEST(int32_t, 1, uint8_t, true);
33 TEST(int32_t, -1, uint8_t, false);
34 TEST(int32_t, (int32_t)(std::numeric_limits<uint8_t>::max)(), uint8_t, true);
35 TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
36 TEST(int32_t, 0, uint8_t, true);
37 TEST(int32_t, -1, uint8_t, false);
38 TEST(int32_t, -127, uint8_t, false);
39 TEST(int32_t, -128, uint8_t, false);
40
Brian Osman50ea3c02019-02-04 10:01:53 -050041 TEST(uint8_t, 2, TestEnum_t, true);
42 TEST(TestEnum_t, kBar, uint8_t, true);
43
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000044 TEST(int32_t, 1000, int8_t, false);
45 TEST(int32_t, 1000, uint8_t, false);
46
47 TEST(int32_t, 1, int32_t, true);
48 TEST(int32_t, -1, int32_t, true);
49 TEST(int32_t, 1, uint32_t, true);
50 TEST(int32_t, -1, uint32_t, false);
51
52 TEST(int32_t, 1, int64_t, true);
53 TEST(int32_t, -1, int64_t, true);
54 TEST(int32_t, 1, uint64_t, true);
55 TEST(int32_t, -1, uint64_t, false);
56
57 TEST(uint32_t, 1, int8_t, true);
58 TEST(uint32_t, 1, uint8_t, true);
59 TEST(uint32_t, 1, int32_t, true);
60 TEST(uint32_t, 1, uint32_t, true);
61 TEST(uint32_t, 1, int64_t, true);
62 TEST(uint32_t, 1, uint64_t, true);
63
64 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
65 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
66 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
67 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
68 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
69 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
70
71 TEST(uint64_t, 1, int8_t, true);
72 TEST(uint64_t, 1, uint8_t, true);
73 TEST(uint64_t, 1, int32_t, true);
74 TEST(uint64_t, 1, uint32_t, true);
75 TEST(uint64_t, 1, int64_t, true);
76 TEST(uint64_t, 1, uint64_t, true);
77
78 // Uncommenting the following should cause compile failures.
79 //TEST(float, 1, uint64_t, true);
80}