Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1747)

Unified Diff: tests/FitsInTest.cpp

Issue 18503009: Fix SkTFits in to work properly with signed/unsigned mixtures. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Address comments by adding comments and assertions. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/win/SkDWriteFontFileStream.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FitsInTest.cpp
===================================================================
--- tests/FitsInTest.cpp (revision 0)
+++ tests/FitsInTest.cpp (working copy)
@@ -0,0 +1,77 @@
+/*
+ * 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 "Test.h"
+
+#include "SkTypes.h"
+#include "SkTFitsIn.h"
+#include <limits>
+
+namespace {
+
+#define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
+
+static void FitsInTest(skiatest::Reporter* reporter) {
+ 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);
+}
+
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("FitsIn", FitsInTestClass, FitsInTest)
+
« no previous file with comments | « src/utils/win/SkDWriteFontFileStream.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698