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

Unified Diff: tests/TemplatesTest.cpp

Issue 1069013002: add realloc method to SkAutoSTMalloc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 5 years, 8 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
« no previous file with comments | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/TemplatesTest.cpp
diff --git a/tests/TemplatesTest.cpp b/tests/TemplatesTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..31859f3f0cea620af3868ce26c93a01601be2b20
--- /dev/null
+++ b/tests/TemplatesTest.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTemplates.h"
+#include "Test.h"
+
+// Tests for some of the helpers in SkTemplates.h
+static void test_automalloc_realloc(skiatest::Reporter* reporter) {
+ SkAutoSTMalloc<1, int> array;
+
+ // test we have a valid pointer, should not crash
+ array[0] = 1;
+ REPORTER_ASSERT(reporter, array[0] == 1);
+
+ // using realloc for init
+ array.realloc(1);
+
+ array[0] = 1;
+ REPORTER_ASSERT(reporter, array[0] == 1);
+
+ // verify realloc can grow
+ array.realloc(2);
+ REPORTER_ASSERT(reporter, array[0] == 1);
+
+ // realloc can shrink
+ array.realloc(1);
+ REPORTER_ASSERT(reporter, array[0] == 1);
+
+ // should not crash
+ array.realloc(0);
+
+ // grow and shrink again
+ array.realloc(10);
+ for (int i = 0; i < 10; i++) {
+ array[i] = 10 - i;
+ }
+ array.realloc(20);
+ for (int i = 0; i < 10; i++) {
+ REPORTER_ASSERT(reporter, array[i] == 10 - i);
+ }
+ array.realloc(10);
+ for (int i = 0; i < 10; i++) {
+ REPORTER_ASSERT(reporter, array[i] == 10 - i);
+ }
+
+ array.realloc(1);
+ REPORTER_ASSERT(reporter, array[0] = 10);
+
+ // resets mixed with realloc, below stack alloc size
+ array.reset(0);
+ array.realloc(1);
+ array.reset(1);
+
+ array[0] = 1;
+ REPORTER_ASSERT(reporter, array[0] == 1);
+
+ // reset and realloc > stack size
+ array.reset(2);
+ array.realloc(3);
+ array[0] = 1;
+ REPORTER_ASSERT(reporter, array[0] == 1);
+ array.realloc(1);
+ REPORTER_ASSERT(reporter, array[0] == 1);
+}
+
+DEF_TEST(Templates, reporter) {
+ test_automalloc_realloc(reporter);
+}
« no previous file with comments | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698