b6b5b7a808
This is a reland of 009f51e43f
Original change's description:
> simplify SkTFitsIn, try 2
>
> Originally we wrote this in C++14 constexpr,
> but because this is used from public headers, we can't use
> C++14 yet. Now a somewhat sillier looking C++11 version.
>
> All the old tests still pass, and one new added.
> Updated the comments a bit for correctness and readability.
>
> Change-Id: I99c01e1346c1a5a36278cc08f30538112e5259aa
> Reviewed-on: https://skia-review.googlesource.com/134425
> Commit-Queue: Mike Klein <mtklein@chromium.org>
> Commit-Queue: Ben Wagner <bungeman@google.com>
> Auto-Submit: Mike Klein <mtklein@chromium.org>
> Reviewed-by: Ben Wagner <bungeman@google.com>
Change-Id: I99676faac6153830538c1396a325ca1456dfb126
Reviewed-on: https://skia-review.googlesource.com/134800
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
/*
|
|
* Copyright 2013 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkTFitsIn.h"
|
|
#include "SkTypes.h"
|
|
#include "Test.h"
|
|
|
|
#include <limits>
|
|
|
|
#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
|
|
|
|
DEF_TEST(FitsIn, reporter) {
|
|
TEST(uint16_t, 257, int8_t, false);
|
|
|
|
TEST(int32_t, 1, int8_t, true);
|
|
TEST(int32_t, -1, int8_t, true);
|
|
TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::max)(), int8_t, true);
|
|
TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
|
|
TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::min)(), int8_t, true);
|
|
TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
|
|
|
|
TEST(int32_t, 1, uint8_t, true);
|
|
TEST(int32_t, -1, uint8_t, false);
|
|
TEST(int32_t, (int32_t)(std::numeric_limits<uint8_t>::max)(), uint8_t, true);
|
|
TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
|
|
TEST(int32_t, 0, uint8_t, true);
|
|
TEST(int32_t, -1, uint8_t, false);
|
|
TEST(int32_t, -127, uint8_t, false);
|
|
TEST(int32_t, -128, uint8_t, false);
|
|
|
|
TEST(int32_t, 1000, int8_t, false);
|
|
TEST(int32_t, 1000, uint8_t, false);
|
|
|
|
TEST(int32_t, 1, int32_t, true);
|
|
TEST(int32_t, -1, int32_t, true);
|
|
TEST(int32_t, 1, uint32_t, true);
|
|
TEST(int32_t, -1, uint32_t, false);
|
|
|
|
TEST(int32_t, 1, int64_t, true);
|
|
TEST(int32_t, -1, int64_t, true);
|
|
TEST(int32_t, 1, uint64_t, true);
|
|
TEST(int32_t, -1, uint64_t, false);
|
|
|
|
TEST(uint32_t, 1, int8_t, true);
|
|
TEST(uint32_t, 1, uint8_t, true);
|
|
TEST(uint32_t, 1, int32_t, true);
|
|
TEST(uint32_t, 1, uint32_t, true);
|
|
TEST(uint32_t, 1, int64_t, true);
|
|
TEST(uint32_t, 1, uint64_t, true);
|
|
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
|
|
TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
|
|
|
|
TEST(uint64_t, 1, int8_t, true);
|
|
TEST(uint64_t, 1, uint8_t, true);
|
|
TEST(uint64_t, 1, int32_t, true);
|
|
TEST(uint64_t, 1, uint32_t, true);
|
|
TEST(uint64_t, 1, int64_t, true);
|
|
TEST(uint64_t, 1, uint64_t, true);
|
|
|
|
// Uncommenting the following should cause compile failures.
|
|
//TEST(float, 1, uint64_t, true);
|
|
}
|