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

Side by Side Diff: tests/TemplatesTest.cpp

Issue 2084213003: Make container classes in SkTemplates.h more consistent (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make buffer classes in SkTemplates.h more consistent Created 4 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 unified diff | Download patch
« include/private/SkTemplates.h ('K') | « include/private/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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTemplates.h" 8 #include "SkTemplates.h"
9 #include "Test.h" 9 #include "Test.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 // reset and realloc > stack size 61 // reset and realloc > stack size
62 array.reset(2); 62 array.reset(2);
63 array.realloc(3); 63 array.realloc(3);
64 array[0] = 1; 64 array[0] = 1;
65 REPORTER_ASSERT(reporter, array[0] == 1); 65 REPORTER_ASSERT(reporter, array[0] == 1);
66 array.realloc(1); 66 array.realloc(1);
67 REPORTER_ASSERT(reporter, array[0] == 1); 67 REPORTER_ASSERT(reporter, array[0] == 1);
68 } 68 }
69 69
70 constexpr int static kStackPreallocCount = 10;
71
72 // Ensures the buffers in SkTemplates.h all have a consistent api.
73 template<typename TBuffer> static void test_buffer_apis(skiatest::Reporter* repo rter) {
74 REPORTER_ASSERT(reporter, !TBuffer(0lu).get());
75 REPORTER_ASSERT(reporter, TBuffer(1).get());
76 REPORTER_ASSERT(reporter, TBuffer(kStackPreallocCount).get());
77 REPORTER_ASSERT(reporter, TBuffer(kStackPreallocCount + 1).get());
78
79 TBuffer buffer;
80 // The default constructor may or may not init to empty, depending on the ty pe of buffer.
81
82 buffer.reset(1);
83 REPORTER_ASSERT(reporter, buffer.get());
84
85 buffer.reset(kStackPreallocCount);
86 REPORTER_ASSERT(reporter, buffer.get());
87
88 buffer.reset(kStackPreallocCount + 1);
89 REPORTER_ASSERT(reporter, buffer.get());
90
91 buffer.reset(0);
92 REPORTER_ASSERT(reporter, !buffer.get());
93 }
94
70 DEF_TEST(Templates, reporter) { 95 DEF_TEST(Templates, reporter) {
71 test_automalloc_realloc(reporter); 96 test_automalloc_realloc(reporter);
72 } 97 }
98
99 DEF_TEST(TemplateBuffers, reporter) {
100 test_buffer_apis<SkAutoTArray<int> >(reporter);
101 test_buffer_apis<SkAutoSTArray<kStackPreallocCount, int> >(reporter);
102 test_buffer_apis<SkAutoTMalloc<int> >(reporter);
103 test_buffer_apis<SkAutoSTMalloc<kStackPreallocCount, int> >(reporter);
104 }
OLDNEW
« include/private/SkTemplates.h ('K') | « include/private/SkTemplates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698