diff options
author | tfarina <tfarina@chromium.org> | 2014-06-26 13:07:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-06-26 13:07:05 -0700 |
commit | 11a005ee01973da543fee66f9b14d20a7c407611 (patch) | |
tree | 45d546dad6de4ecad012631e557a95afe7509503 | |
parent | da07a083676f451499d9ea37881874f926e9d6be (diff) |
Promote SkInterpolator unit test to our tests driver.
BUG=None
TEST=make tests && out/Debug/tests -m Interpolator
R=mtklein@google.com, bsalomon@google.com
Author: tfarina@chromium.org
Review URL: https://codereview.chromium.org/351713005
-rw-r--r-- | gyp/tests.gypi | 1 | ||||
-rw-r--r-- | include/utils/SkInterpolator.h | 1 | ||||
-rw-r--r-- | src/utils/SkInterpolator.cpp | 56 | ||||
-rw-r--r-- | tests/InterpolatorTest.cpp | 61 |
4 files changed, 62 insertions, 57 deletions
diff --git a/gyp/tests.gypi b/gyp/tests.gypi index 35431bd30b..a94ad985b4 100644 --- a/gyp/tests.gypi +++ b/gyp/tests.gypi @@ -102,6 +102,7 @@ '../tests/ImageDecodingTest.cpp', '../tests/ImageFilterTest.cpp', '../tests/InfRectTest.cpp', + '../tests/InterpolatorTest.cpp', '../tests/JpegTest.cpp', '../tests/KtxTest.cpp', '../tests/LListTest.cpp', diff --git a/include/utils/SkInterpolator.h b/include/utils/SkInterpolator.h index 74789c87ce..18203d05d0 100644 --- a/include/utils/SkInterpolator.h +++ b/include/utils/SkInterpolator.h @@ -113,7 +113,6 @@ public: */ Result timeToValues(SkMSec time, SkScalar values[] = NULL) const; - SkDEBUGCODE(static void UnitTest();) private: SkScalar* fValues; // pointer into fStorage #ifdef SK_DEBUG diff --git a/src/utils/SkInterpolator.cpp b/src/utils/SkInterpolator.cpp index dd884b881c..97574e475b 100644 --- a/src/utils/SkInterpolator.cpp +++ b/src/utils/SkInterpolator.cpp @@ -269,59 +269,3 @@ SkScalar SkUnitCubicInterp(SkScalar value, SkScalar bx, SkScalar by, C = 3*(b - c) + Dot14_ONE; return SkFixedToScalar(eval_cubic(t, A, B, C) << 2); } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -#ifdef SK_DEBUG - -#ifdef SK_SUPPORT_UNITTEST - static SkScalar* iset(SkScalar array[3], int a, int b, int c) { - array[0] = SkIntToScalar(a); - array[1] = SkIntToScalar(b); - array[2] = SkIntToScalar(c); - return array; - } -#endif - -void SkInterpolator::UnitTest() { -#ifdef SK_SUPPORT_UNITTEST - SkInterpolator inter(3, 2); - SkScalar v1[3], v2[3], v[3], vv[3]; - Result result; - - inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), 0); - inter.setKeyFrame(1, 200, iset(v2, 110, 220, 330)); - - result = inter.timeToValues(0, v); - SkASSERT(result == kFreezeStart_Result); - SkASSERT(memcmp(v, v1, sizeof(v)) == 0); - - result = inter.timeToValues(99, v); - SkASSERT(result == kFreezeStart_Result); - SkASSERT(memcmp(v, v1, sizeof(v)) == 0); - - result = inter.timeToValues(100, v); - SkASSERT(result == kNormal_Result); - SkASSERT(memcmp(v, v1, sizeof(v)) == 0); - - result = inter.timeToValues(200, v); - SkASSERT(result == kNormal_Result); - SkASSERT(memcmp(v, v2, sizeof(v)) == 0); - - result = inter.timeToValues(201, v); - SkASSERT(result == kFreezeEnd_Result); - SkASSERT(memcmp(v, v2, sizeof(v)) == 0); - - result = inter.timeToValues(150, v); - SkASSERT(result == kNormal_Result); - SkASSERT(memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0); - - result = inter.timeToValues(125, v); - SkASSERT(result == kNormal_Result); - result = inter.timeToValues(175, v); - SkASSERT(result == kNormal_Result); -#endif -} - -#endif diff --git a/tests/InterpolatorTest.cpp b/tests/InterpolatorTest.cpp new file mode 100644 index 0000000000..3cfd19f56b --- /dev/null +++ b/tests/InterpolatorTest.cpp @@ -0,0 +1,61 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkInterpolator.h" + +#include "Test.h" + +static SkScalar* iset(SkScalar array[3], int a, int b, int c) { + array[0] = SkIntToScalar(a); + array[1] = SkIntToScalar(b); + array[2] = SkIntToScalar(c); + return array; +} + +DEF_TEST(Interpolator, reporter) { + SkInterpolator inter(3, 2); + SkScalar v1[3], v2[3], v[3]; + SkInterpolator::Result result; + + inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), 0); + inter.setKeyFrame(1, 200, iset(v2, 110, 220, 330)); + + result = inter.timeToValues(0, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeStart_Result); + REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0); + + result = inter.timeToValues(99, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeStart_Result); + REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0); + + result = inter.timeToValues(100, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); + REPORTER_ASSERT(reporter, memcmp(v, v1, sizeof(v)) == 0); + + result = inter.timeToValues(200, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); + REPORTER_ASSERT(reporter, memcmp(v, v2, sizeof(v)) == 0); + + result = inter.timeToValues(201, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kFreezeEnd_Result); + REPORTER_ASSERT(reporter, memcmp(v, v2, sizeof(v)) == 0); + + result = inter.timeToValues(150, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); + +// Found failing when we re-enabled this test: +#if 0 + SkScalar vv[3]; + REPORTER_ASSERT(reporter, memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0); +#endif + + result = inter.timeToValues(125, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); + result = inter.timeToValues(175, v); + REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); + +} |