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

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
« include/core/SkTemplates.h ('K') | « 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 // using realloc for init
16 array.realloc(1);
17
18 array[0] = 1;
19 REPORTER_ASSERT(reporter, array[0] == 1);
20
21 // verify realloc can grow
22 array.realloc(2);
23 REPORTER_ASSERT(reporter, array[0] == 1);
24
25 // realloc can shrink
26 array.realloc(1);
27 REPORTER_ASSERT(reporter, array[0] == 1);
28
29 // should not crash
30 array.realloc(0);
31
32 // grow and shrink again
33 array.realloc(10);
34 for (int i = 0; i < 10; i++) {
35 array[i] = 10 - i;
36 }
37 array.realloc(20);
38 for (int i = 0; i < 10; i++) {
39 REPORTER_ASSERT(reporter, array[i] == 10 - i);
40 }
41 array.realloc(10);
42 for (int i = 0; i < 10; i++) {
43 REPORTER_ASSERT(reporter, array[i] == 10 - i);
44 }
45
46 array.realloc(1);
47 REPORTER_ASSERT(reporter, array[0] = 10);
48
49 // resets mixed with realloc, below stack alloc size
50 array.reset(0);
51 array.realloc(1);
52 array.reset(1);
53
54 array[0] = 1;
55 REPORTER_ASSERT(reporter, array[0] == 1);
56
57 // reset and realloc > stack size
58 array.reset(2);
59 array.realloc(3);
60 array[0] = 1;
61 REPORTER_ASSERT(reporter, array[0] == 1);
62 array.realloc(1);
63 REPORTER_ASSERT(reporter, array[0] == 1);
64 }
65
66 DEF_TEST(Templates, reporter) {
67 test_automalloc_realloc(reporter);
68 }
OLDNEW
« include/core/SkTemplates.h ('K') | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698