Index: tests/TemplatesTest.cpp |
diff --git a/tests/TemplatesTest.cpp b/tests/TemplatesTest.cpp |
index 31859f3f0cea620af3868ce26c93a01601be2b20..4698dbb483f27fdefb7860e99ca6a17789f5bdc1 100644 |
--- a/tests/TemplatesTest.cpp |
+++ b/tests/TemplatesTest.cpp |
@@ -67,6 +67,38 @@ static void test_automalloc_realloc(skiatest::Reporter* reporter) { |
REPORTER_ASSERT(reporter, array[0] == 1); |
} |
+constexpr int static kStackPreallocCount = 10; |
+ |
+// Ensures the buffers in SkTemplates.h all have a consistent api. |
+template<typename TBuffer> static void test_buffer_apis(skiatest::Reporter* reporter) { |
+ REPORTER_ASSERT(reporter, !TBuffer(0lu).get()); |
+ REPORTER_ASSERT(reporter, TBuffer(1).get()); |
+ REPORTER_ASSERT(reporter, TBuffer(kStackPreallocCount).get()); |
+ REPORTER_ASSERT(reporter, TBuffer(kStackPreallocCount + 1).get()); |
+ |
+ TBuffer buffer; |
+ // The default constructor may or may not init to empty, depending on the type of buffer. |
+ |
+ buffer.reset(1); |
+ REPORTER_ASSERT(reporter, buffer.get()); |
+ |
+ buffer.reset(kStackPreallocCount); |
+ REPORTER_ASSERT(reporter, buffer.get()); |
+ |
+ buffer.reset(kStackPreallocCount + 1); |
+ REPORTER_ASSERT(reporter, buffer.get()); |
+ |
+ buffer.reset(0); |
+ REPORTER_ASSERT(reporter, !buffer.get()); |
+} |
+ |
DEF_TEST(Templates, reporter) { |
test_automalloc_realloc(reporter); |
} |
+ |
+DEF_TEST(TemplateBuffers, reporter) { |
+ test_buffer_apis<SkAutoTArray<int> >(reporter); |
+ test_buffer_apis<SkAutoSTArray<kStackPreallocCount, int> >(reporter); |
+ test_buffer_apis<SkAutoTMalloc<int> >(reporter); |
+ test_buffer_apis<SkAutoSTMalloc<kStackPreallocCount, int> >(reporter); |
+} |