SizeTest.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/SkSize.h"
  8. #include "tests/Test.h"
  9. DEF_TEST(ISize, reporter) {
  10. SkISize a, b;
  11. a.set(0, 0);
  12. REPORTER_ASSERT(reporter, a.isEmpty());
  13. a.set(5, -5);
  14. REPORTER_ASSERT(reporter, a.isEmpty());
  15. a = SkISize{5, 0};
  16. REPORTER_ASSERT(reporter, a.isEmpty());
  17. b.set(5, 0);
  18. REPORTER_ASSERT(reporter, a == b);
  19. a.set(3, 5);
  20. REPORTER_ASSERT(reporter, !a.isEmpty());
  21. b = a;
  22. REPORTER_ASSERT(reporter, !b.isEmpty());
  23. REPORTER_ASSERT(reporter, a == b);
  24. REPORTER_ASSERT(reporter, !(a != b));
  25. REPORTER_ASSERT(reporter,
  26. a.fWidth == b.fWidth && a.fHeight == b.fHeight);
  27. }
  28. DEF_TEST(Size, reporter) {
  29. SkSize a, b;
  30. int ix = 5;
  31. int iy = 3;
  32. SkScalar x = SkIntToScalar(ix);
  33. SkScalar y = SkIntToScalar(iy);
  34. a.set(0, 0);
  35. REPORTER_ASSERT(reporter, a.isEmpty());
  36. a.set(x, -x);
  37. REPORTER_ASSERT(reporter, a.isEmpty());
  38. a = SkSize{x, 0};
  39. REPORTER_ASSERT(reporter, a.isEmpty());
  40. b.set(x, 0);
  41. REPORTER_ASSERT(reporter, a == b);
  42. a.set(y, x);
  43. REPORTER_ASSERT(reporter, !a.isEmpty());
  44. b = a;
  45. REPORTER_ASSERT(reporter, !b.isEmpty());
  46. REPORTER_ASSERT(reporter, a == b);
  47. REPORTER_ASSERT(reporter, !(a != b));
  48. REPORTER_ASSERT(reporter,
  49. a.fWidth == b.fWidth && a.fHeight == b.fHeight);
  50. SkISize ia;
  51. ia.set(ix, iy);
  52. a.set(x, y);
  53. REPORTER_ASSERT(reporter, a.toRound() == ia);
  54. }