skia2/tests/SizeTest.cpp
Hal Canary fafe135349 SkSize can be aggregate-initialized
Previosly, SkSize had a base class, which prevented it.

Also removes unused SkISize::clampNegToZero() and
SkSize::clampNegToZero().

Change-Id: I7b93b42f6f6381c66e294bbedee99ad53c6c3436
Reviewed-on: https://skia-review.googlesource.com/13187
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
2017-04-11 18:57:20 +00:00

64 lines
1.5 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSize.h"
#include "Test.h"
DEF_TEST(ISize, reporter) {
SkISize a, b;
a.set(0, 0);
REPORTER_ASSERT(reporter, a.isEmpty());
a.set(5, -5);
REPORTER_ASSERT(reporter, a.isEmpty());
a = SkISize{5, 0};
REPORTER_ASSERT(reporter, a.isEmpty());
b.set(5, 0);
REPORTER_ASSERT(reporter, a == b);
a.set(3, 5);
REPORTER_ASSERT(reporter, !a.isEmpty());
b = a;
REPORTER_ASSERT(reporter, !b.isEmpty());
REPORTER_ASSERT(reporter, a == b);
REPORTER_ASSERT(reporter, !(a != b));
REPORTER_ASSERT(reporter,
a.fWidth == b.fWidth && a.fHeight == b.fHeight);
}
DEF_TEST(Size, reporter) {
SkSize a, b;
int ix = 5;
int iy = 3;
SkScalar x = SkIntToScalar(ix);
SkScalar y = SkIntToScalar(iy);
a.set(0, 0);
REPORTER_ASSERT(reporter, a.isEmpty());
a.set(x, -x);
REPORTER_ASSERT(reporter, a.isEmpty());
a = SkSize{x, 0};
REPORTER_ASSERT(reporter, a.isEmpty());
b.set(x, 0);
REPORTER_ASSERT(reporter, a == b);
a.set(y, x);
REPORTER_ASSERT(reporter, !a.isEmpty());
b = a;
REPORTER_ASSERT(reporter, !b.isEmpty());
REPORTER_ASSERT(reporter, a == b);
REPORTER_ASSERT(reporter, !(a != b));
REPORTER_ASSERT(reporter,
a.fWidth == b.fWidth && a.fHeight == b.fHeight);
SkISize ia;
ia.set(ix, iy);
a.set(x, y);
REPORTER_ASSERT(reporter, a.toRound() == ia);
}