Add unit test for Type::minimumValue and Type::maximumValue.

This test confirms that our logic to derive the min and max value of a
given integer type actually matches reality.

Change-Id: I1cb5fba6bfb9ffdcf4972d8feed79cf71e11d0ca
Bug: skia:10932
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/413376
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-05-27 15:53:13 -04:00 committed by Skia Commit-Bot
parent 35981296a8
commit 7d341a37f7
2 changed files with 36 additions and 0 deletions

View File

@ -270,6 +270,7 @@ tests_sources = [
"$_tests/SkSLMetalTestbed.cpp",
"$_tests/SkSLSPIRVTestbed.cpp",
"$_tests/SkSLTest.cpp",
"$_tests/SkSLTypeTest.cpp",
"$_tests/SkScalerCacheTest.cpp",
"$_tests/SkShaperJSONWriterTest.cpp",
"$_tests/SkSharedMutexTest.cpp",

35
tests/SkSLTypeTest.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <limits>
#include "src/gpu/GrCaps.h"
#include "src/sksl/SkSLContext.h"
#include "src/sksl/SkSLErrorReporter.h"
#include "tests/Test.h"
DEF_TEST(SkSLTypeLimits, r) {
GrShaderCaps caps(GrContextOptions{});
SkSL::TestingOnly_AbortErrorReporter errors;
SkSL::Context context(errors, caps);
using int_limits = std::numeric_limits<int32_t>;
REPORTER_ASSERT(r, context.fTypes.fInt->minimumValue() == int_limits::min());
REPORTER_ASSERT(r, context.fTypes.fInt->maximumValue() == int_limits::max());
using short_limits = std::numeric_limits<int16_t>;
REPORTER_ASSERT(r, context.fTypes.fShort->minimumValue() == short_limits::min());
REPORTER_ASSERT(r, context.fTypes.fShort->maximumValue() == short_limits::max());
using uint_limits = std::numeric_limits<uint32_t>;
REPORTER_ASSERT(r, context.fTypes.fUInt->minimumValue() == uint_limits::min());
REPORTER_ASSERT(r, context.fTypes.fUInt->maximumValue() == uint_limits::max());
using ushort_limits = std::numeric_limits<uint16_t>;
REPORTER_ASSERT(r, context.fTypes.fUShort->minimumValue() == ushort_limits::min());
REPORTER_ASSERT(r, context.fTypes.fUShort->maximumValue() == ushort_limits::max());
}