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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 "SkTemplates.h"
9 #include "Test.h"
10
11 // Tests for some of the helpers in SkTemplates.h
12 static void test_automalloc_realloc(skiatest::Reporter* reporter) {
13 SkAutoSTMalloc<1, int> array;
14
15 // test we have a valid pointer, should not crash
16 array[0] = 1;
17 REPORTER_ASSERT(reporter, array[0] == 1);
18
19 // using realloc for init
20 array.realloc(1);
21
22 array[0] = 1;
23 REPORTER_ASSERT(reporter, array[0] == 1);
24
25 // verify realloc can grow
26 array.realloc(2);
27 REPORTER_ASSERT(reporter, array[0] == 1);
28
29 // realloc can shrink
30 array.realloc(1);
31 REPORTER_ASSERT(reporter, array[0] == 1);
32
33 // should not crash
34 array.realloc(0);
35
36 // grow and shrink again
37 array.realloc(10);
38 for (int i = 0; i < 10; i++) {
39 array[i] = 10 - i;
40 }
41 array.realloc(20);
42 for (int i = 0; i < 10; i++) {
43 REPORTER_ASSERT(reporter, array[i] == 10 - i);
44 }
45 array.realloc(10);
46 for (int i = 0; i < 10; i++) {
47 REPORTER_ASSERT(reporter, array[i] == 10 - i);
48 }
49
50 array.realloc(1);
51 REPORTER_ASSERT(reporter, array[0] = 10);
52
53 // resets mixed with realloc, below stack alloc size
54 array.reset(0);
55 array.realloc(1);
56 array.reset(1);
57
58 array[0] = 1;
59 REPORTER_ASSERT(reporter, array[0] == 1);
60
61 // reset and realloc > stack size
62 array.reset(2);
63 array.realloc(3);
64 array[0] = 1;
65 REPORTER_ASSERT(reporter, array[0] == 1);
66 array.realloc(1);
67 REPORTER_ASSERT(reporter, array[0] == 1);
68 }
69
70 DEF_TEST(Templates, reporter) {
71 test_automalloc_realloc(reporter);
72 }
OLDNEW
« 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