Home | History | Annotate | Download | only in tests
      1 #include "Test.h"
      2 #include "SkSize.h"
      3 
      4 static void TestISize(skiatest::Reporter* reporter) {
      5     SkISize  a, b;
      6 
      7     a.set(0, 0);
      8     REPORTER_ASSERT(reporter, a.isEmpty());
      9     a.set(5, -5);
     10     REPORTER_ASSERT(reporter, a.isEmpty());
     11     a.clampNegToZero();
     12     REPORTER_ASSERT(reporter, a.isEmpty());
     13     b.set(5, 0);
     14     REPORTER_ASSERT(reporter, a == b);
     15 
     16     a.set(3, 5);
     17     REPORTER_ASSERT(reporter, !a.isEmpty());
     18     b = a;
     19     REPORTER_ASSERT(reporter, !b.isEmpty());
     20     REPORTER_ASSERT(reporter, a == b);
     21     REPORTER_ASSERT(reporter, !(a != b));
     22     REPORTER_ASSERT(reporter,
     23                     a.fWidth == b.fWidth && a.fHeight == b.fHeight);
     24 }
     25 
     26 static void TestSize(skiatest::Reporter* reporter) {
     27     TestISize(reporter);
     28 
     29     SkSize a, b;
     30     int ix = 5;
     31     int iy = 3;
     32     SkScalar x = SkIntToScalar(ix);
     33     SkScalar y = SkIntToScalar(iy);
     34 
     35     a.set(0, 0);
     36     REPORTER_ASSERT(reporter, a.isEmpty());
     37     a.set(x, -x);
     38     REPORTER_ASSERT(reporter, a.isEmpty());
     39     a.clampNegToZero();
     40     REPORTER_ASSERT(reporter, a.isEmpty());
     41     b.set(x, 0);
     42     REPORTER_ASSERT(reporter, a == b);
     43 
     44     a.set(y, x);
     45     REPORTER_ASSERT(reporter, !a.isEmpty());
     46     b = a;
     47     REPORTER_ASSERT(reporter, !b.isEmpty());
     48     REPORTER_ASSERT(reporter, a == b);
     49     REPORTER_ASSERT(reporter, !(a != b));
     50     REPORTER_ASSERT(reporter,
     51                     a.fWidth == b.fWidth && a.fHeight == b.fHeight);
     52 
     53     SkISize ia;
     54     ia.set(ix, iy);
     55     a.set(x, y);
     56     REPORTER_ASSERT(reporter, a.round() == ia);
     57 };
     58 
     59 #include "TestClassDef.h"
     60 DEFINE_TESTCLASS("Size", TestSizeClass, TestSize)
     61