Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1419)

Unified Diff: tests/MipMapTest.cpp

Issue 19462007: pull mipmap class into its own (private) header (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/core/SkMipMap.cpp ('K') | « src/core/SkMipMap.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MipMapTest.cpp
diff --git a/tests/MipMapTest.cpp b/tests/MipMapTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c305532ebc6591f45297a340adff5cf7694c0141
--- /dev/null
+++ b/tests/MipMapTest.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkMipMap.h"
+#include "SkBitmap.h"
+#include "SkRandom.h"
+
+static void make_bitmap(SkBitmap* bm, SkRandom& rand) {
+ // for now, Build needs a min size of 2, otherwise it will return NULL.
+ // should fix that to support 1 X N, where N > 1 to return non-null.
+ int w = 2 + rand.nextU() % 1000;
+ int h = 2 + rand.nextU() % 1000;
+ bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
+ bm->allocPixels();
+ bm->eraseColor(SK_ColorWHITE);
+}
+
+static void TestMipMap(skiatest::Reporter* reporter) {
+ SkBitmap bm;
+ SkRandom rand;
+
+ for (int i = 0; i < 500; ++i) {
+ make_bitmap(&bm, rand);
+ SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm));
+
+ REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL));
+ REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL));
+
+ SkMipMap::Level prevLevel;
+ prevLevel.fPixels = NULL; // sentinel
+
+ SkScalar scale = SK_Scalar1;
+ for (int j = 0; j < 30; ++j) {
+ scale = scale * 2 / 3;
+
+ SkMipMap::Level level;
+ if (mm->extractLevel(scale, &level)) {
+ REPORTER_ASSERT(reporter, level.fPixels);
+ REPORTER_ASSERT(reporter, level.fWidth > 0);
+ REPORTER_ASSERT(reporter, level.fHeight > 0);
+ REPORTER_ASSERT(reporter, level.fRowBytes >= level.fWidth * 4);
+
+ if (prevLevel.fPixels) {
+ REPORTER_ASSERT(reporter, level.fWidth <= prevLevel.fWidth);
+ REPORTER_ASSERT(reporter, level.fHeight <= prevLevel.fHeight);
+ }
+ prevLevel = level;
+ }
+ }
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("MipMap", MipMapTestClass, TestMipMap)
« src/core/SkMipMap.cpp ('K') | « src/core/SkMipMap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698