InfRectTest.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2011 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkRect.h"
  8. #include "include/private/SkFloatingPoint.h"
  9. #include "include/utils/SkRandom.h"
  10. #include "tests/Test.h"
  11. static void check_invalid(skiatest::Reporter* reporter,
  12. SkScalar l, SkScalar t, SkScalar r, SkScalar b) {
  13. SkRect rect;
  14. rect.set(l, t, r, b);
  15. REPORTER_ASSERT(reporter, !rect.isFinite());
  16. }
  17. // Tests that isFinite() will reject any rect with +/-inf values
  18. // as one of its coordinates.
  19. DEF_TEST(InfRect, reporter) {
  20. float inf = SK_FloatInfinity;
  21. float nan = SK_FloatNaN;
  22. SkASSERT(!(nan == nan));
  23. SkScalar small = SkIntToScalar(10);
  24. SkScalar big = SkIntToScalar(100);
  25. REPORTER_ASSERT(reporter, SkRect::MakeEmpty().isFinite());
  26. SkRect rect = SkRect::MakeXYWH(small, small, big, big);
  27. REPORTER_ASSERT(reporter, rect.isFinite());
  28. const SkScalar invalid[] = { nan, inf, -inf };
  29. for (size_t i = 0; i < SK_ARRAY_COUNT(invalid); ++i) {
  30. check_invalid(reporter, small, small, big, invalid[i]);
  31. check_invalid(reporter, small, small, invalid[i], big);
  32. check_invalid(reporter, small, invalid[i], big, big);
  33. check_invalid(reporter, invalid[i], small, big, big);
  34. }
  35. }
  36. // need tests for SkStrSearch