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

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: break dependency Created 4 years, 6 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/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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DEF_TEST(Templates, reporter) { 70 DEF_TEST(Templates, reporter) {
71 test_automalloc_realloc(reporter); 71 test_automalloc_realloc(reporter);
72 } 72 }
73
74 constexpr int static kStackPreallocCount = 10;
75
76 // Ensures the containers in SkTemplates.h all have a consistent api.
77 template<typename TContainer, typename TCount>
78 static void test_container_apis(skiatest::Reporter* reporter) {
79 REPORTER_ASSERT(reporter, !TContainer((TCount)0).get());
80 REPORTER_ASSERT(reporter, TContainer((TCount)1).get());
81 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount).get());
82 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount + 1).get()) ;
83
84 TContainer container;
85 // The default constructor may or may not init to empty, depending on the ty pe of container.
86
87 container.reset((TCount)1);
88 REPORTER_ASSERT(reporter, container.get());
89
90 container.reset((TCount)kStackPreallocCount);
91 REPORTER_ASSERT(reporter, container.get());
92
93 container.reset((TCount)kStackPreallocCount + 1);
94 REPORTER_ASSERT(reporter, container.get());
95
96 container.reset((TCount)0);
97 REPORTER_ASSERT(reporter, !container.get());
98 }
99
100 DEF_TEST(TemplateContainerAPIs, reporter) {
101 test_container_apis<SkAutoTArray<int>, int>(reporter);
102 test_container_apis<SkAutoSTArray<kStackPreallocCount, int>, int>(reporter);
103 test_container_apis<SkAutoTMalloc<int>, size_t>(reporter);
104 test_container_apis<SkAutoSTMalloc<kStackPreallocCount, int>, size_t>(report er);
105 }
106
107 // Ensures that realloc(0) results in a null pointer.
108 template<typename TAutoMalloc> static void test_realloc_to_zero(skiatest::Report er* reporter) {
109 TAutoMalloc autoMalloc(kStackPreallocCount);
110 REPORTER_ASSERT(reporter, autoMalloc.get());
111
112 autoMalloc.realloc(0);
113 REPORTER_ASSERT(reporter, !autoMalloc.get());
114
115 autoMalloc.realloc(kStackPreallocCount + 1);
116 REPORTER_ASSERT(reporter, autoMalloc.get());
117
118 autoMalloc.realloc(0);
119 REPORTER_ASSERT(reporter, !autoMalloc.get());
120
121 autoMalloc.realloc(kStackPreallocCount);
122 REPORTER_ASSERT(reporter, autoMalloc.get());
123 }
124
125 DEF_TEST(AutoReallocToZero, reporter) {
126 test_realloc_to_zero<SkAutoTMalloc<int> >(reporter);
127 test_realloc_to_zero<SkAutoSTMalloc<kStackPreallocCount, int> >(reporter);
128 }
OLDNEW
« no previous file with comments | « include/private/SkTemplates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698