Fix data() method and add unit test.
I wrote code that called SkAutoTArray::data() and discovered that it
was broken, but not generating compile errors because it's part of a
template and never instantiated anywhere else. I fixed the
implementation and added it to our container unit test to prevent later
regression. This revealed another issue, that "containers in
SkTemplates.h [should] all have a consistent api", according to
test_container_apis. However, data() was never added to the non-array
container APIs. So I added data() to the other containers as well.
Change-Id: I52532c91fdab3fc8c4539053ba8420815b7b0ee5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323276
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/tests/TemplatesTest.cpp b/tests/TemplatesTest.cpp
index e3e52a3..f073b4c 100644
--- a/tests/TemplatesTest.cpp
+++ b/tests/TemplatesTest.cpp
@@ -77,24 +77,32 @@
template<typename TContainer, typename TCount>
static void test_container_apis(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !TContainer((TCount)0).get());
+ REPORTER_ASSERT(reporter, !TContainer((TCount)0).data());
REPORTER_ASSERT(reporter, TContainer((TCount)1).get());
+ REPORTER_ASSERT(reporter, TContainer((TCount)1).data());
REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount).get());
+ REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount).data());
REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount + 1).get());
+ REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount + 1).data());
TContainer container;
// The default constructor may or may not init to empty, depending on the type of container.
container.reset((TCount)1);
REPORTER_ASSERT(reporter, container.get());
+ REPORTER_ASSERT(reporter, container.get() == container.data());
container.reset((TCount)kStackPreallocCount);
REPORTER_ASSERT(reporter, container.get());
+ REPORTER_ASSERT(reporter, container.get() == container.data());
container.reset((TCount)kStackPreallocCount + 1);
REPORTER_ASSERT(reporter, container.get());
+ REPORTER_ASSERT(reporter, container.get() == container.data());
container.reset((TCount)0);
REPORTER_ASSERT(reporter, !container.get());
+ REPORTER_ASSERT(reporter, !container.data());
}
DEF_TEST(TemplateContainerAPIs, reporter) {