xref: /third_party/skia/tests/FitsInTest.cpp (revision cb93a386)
1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/core/SkTypes.h"
9cb93a386Sopenharmony_ci#include "include/private/SkTFitsIn.h"
10cb93a386Sopenharmony_ci#include "tests/Test.h"
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci#include <limits>
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ci#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_cienum TestEnum_t : uint8_t {
17cb93a386Sopenharmony_ci    kFoo,
18cb93a386Sopenharmony_ci    kBar,
19cb93a386Sopenharmony_ci    kBaz,
20cb93a386Sopenharmony_ci};
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_ciDEF_TEST(FitsIn, reporter) {
23cb93a386Sopenharmony_ci    TEST(uint16_t, 257, int8_t, false);
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci    TEST(int32_t,  1, int8_t, true);
26cb93a386Sopenharmony_ci    TEST(int32_t, -1, int8_t, true);
27cb93a386Sopenharmony_ci    TEST(int32_t,  (int32_t)(std::numeric_limits<int8_t>::max)(),    int8_t, true);
28cb93a386Sopenharmony_ci    TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
29cb93a386Sopenharmony_ci    TEST(int32_t,  (int32_t)(std::numeric_limits<int8_t>::min)(),    int8_t, true);
30cb93a386Sopenharmony_ci    TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci    TEST(int32_t,  1, uint8_t, true);
33cb93a386Sopenharmony_ci    TEST(int32_t, -1, uint8_t, false);
34cb93a386Sopenharmony_ci    TEST(int32_t,  (int32_t)(std::numeric_limits<uint8_t>::max)(),    uint8_t, true);
35cb93a386Sopenharmony_ci    TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
36cb93a386Sopenharmony_ci    TEST(int32_t,  0, uint8_t, true);
37cb93a386Sopenharmony_ci    TEST(int32_t, -1, uint8_t, false);
38cb93a386Sopenharmony_ci    TEST(int32_t, -127, uint8_t, false);
39cb93a386Sopenharmony_ci    TEST(int32_t, -128, uint8_t, false);
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci    TEST(uint8_t, 2, TestEnum_t, true);
42cb93a386Sopenharmony_ci    TEST(TestEnum_t, kBar, uint8_t, true);
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_ci    TEST(int32_t, 1000, int8_t, false);
45cb93a386Sopenharmony_ci    TEST(int32_t, 1000, uint8_t, false);
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci    TEST(int32_t, 1, int32_t, true);
48cb93a386Sopenharmony_ci    TEST(int32_t, -1, int32_t, true);
49cb93a386Sopenharmony_ci    TEST(int32_t, 1, uint32_t, true);
50cb93a386Sopenharmony_ci    TEST(int32_t, -1, uint32_t, false);
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ci    TEST(int32_t, 1, int64_t, true);
53cb93a386Sopenharmony_ci    TEST(int32_t, -1, int64_t, true);
54cb93a386Sopenharmony_ci    TEST(int32_t, 1, uint64_t, true);
55cb93a386Sopenharmony_ci    TEST(int32_t, -1, uint64_t, false);
56cb93a386Sopenharmony_ci
57cb93a386Sopenharmony_ci    TEST(uint32_t, 1, int8_t, true);
58cb93a386Sopenharmony_ci    TEST(uint32_t, 1, uint8_t, true);
59cb93a386Sopenharmony_ci    TEST(uint32_t, 1, int32_t, true);
60cb93a386Sopenharmony_ci    TEST(uint32_t, 1, uint32_t, true);
61cb93a386Sopenharmony_ci    TEST(uint32_t, 1, int64_t, true);
62cb93a386Sopenharmony_ci    TEST(uint32_t, 1, uint64_t, true);
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
65cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
66cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
67cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
68cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
69cb93a386Sopenharmony_ci    TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
70cb93a386Sopenharmony_ci
71cb93a386Sopenharmony_ci    TEST(uint64_t, 1, int8_t, true);
72cb93a386Sopenharmony_ci    TEST(uint64_t, 1, uint8_t, true);
73cb93a386Sopenharmony_ci    TEST(uint64_t, 1, int32_t, true);
74cb93a386Sopenharmony_ci    TEST(uint64_t, 1, uint32_t, true);
75cb93a386Sopenharmony_ci    TEST(uint64_t, 1, int64_t, true);
76cb93a386Sopenharmony_ci    TEST(uint64_t, 1, uint64_t, true);
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_ci    // Uncommenting the following should cause compile failures.
79cb93a386Sopenharmony_ci    //TEST(float, 1, uint64_t, true);
80cb93a386Sopenharmony_ci}
81