blob: b66d53b51927d33b5fe48d9314643fcec6103aa0 [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
8#include "Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00009#include "TestClassDef.h"
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000010#include "SkTypes.h"
11#include "SkTFitsIn.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000012
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000013#include <limits>
14
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000015#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
16
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000017DEF_TEST(FitsIn, reporter) {
bungeman@google.comf5cc5b12013-07-12 18:22:49 +000018 TEST(int32_t, 1, int8_t, true);
19 TEST(int32_t, -1, int8_t, true);
20 TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::max)(), int8_t, true);
21 TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
22 TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::min)(), int8_t, true);
23 TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
24
25 TEST(int32_t, 1, uint8_t, true);
26 TEST(int32_t, -1, uint8_t, false);
27 TEST(int32_t, (int32_t)(std::numeric_limits<uint8_t>::max)(), uint8_t, true);
28 TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
29 TEST(int32_t, 0, uint8_t, true);
30 TEST(int32_t, -1, uint8_t, false);
31 TEST(int32_t, -127, uint8_t, false);
32 TEST(int32_t, -128, uint8_t, false);
33
34 TEST(int32_t, 1000, int8_t, false);
35 TEST(int32_t, 1000, uint8_t, false);
36
37 TEST(int32_t, 1, int32_t, true);
38 TEST(int32_t, -1, int32_t, true);
39 TEST(int32_t, 1, uint32_t, true);
40 TEST(int32_t, -1, uint32_t, false);
41
42 TEST(int32_t, 1, int64_t, true);
43 TEST(int32_t, -1, int64_t, true);
44 TEST(int32_t, 1, uint64_t, true);
45 TEST(int32_t, -1, uint64_t, false);
46
47 TEST(uint32_t, 1, int8_t, true);
48 TEST(uint32_t, 1, uint8_t, true);
49 TEST(uint32_t, 1, int32_t, true);
50 TEST(uint32_t, 1, uint32_t, true);
51 TEST(uint32_t, 1, int64_t, true);
52 TEST(uint32_t, 1, uint64_t, true);
53
54 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
55 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
56 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
57 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
58 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
59 TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
60
61 TEST(uint64_t, 1, int8_t, true);
62 TEST(uint64_t, 1, uint8_t, true);
63 TEST(uint64_t, 1, int32_t, true);
64 TEST(uint64_t, 1, uint32_t, true);
65 TEST(uint64_t, 1, int64_t, true);
66 TEST(uint64_t, 1, uint64_t, true);
67
68 // Uncommenting the following should cause compile failures.
69 //TEST(float, 1, uint64_t, true);
70}