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