diff options
author | 2019-08-06 18:16:23 -0700 | |
---|---|---|
committer | 2019-08-28 11:10:57 -0700 | |
commit | f629f10f62ab695aa0a154aca9a6a53aae476163 (patch) | |
tree | b4b931c683bd71865716c9b3fd4e81573f1a7437 | |
parent | 9fa2cb6c5af15e5386c4632aed4847057c08340b (diff) |
[ANativeWindow] Test with a TestableSurface
TestableSurface is the same as a Surface but with hooks into protected
members so that tests can verify that any internal state returned by the
ANativeWindow interface is in fact correct.
Bug: 137012161
Test: atest
Change-Id: I4320cdee35ec9b523d6b321d22a13f7e61f1a77c
-rw-r--r-- | libs/nativewindow/tests/ANativeWindowTest.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libs/nativewindow/tests/ANativeWindowTest.cpp b/libs/nativewindow/tests/ANativeWindowTest.cpp index a80da24a47..5247e04c32 100644 --- a/libs/nativewindow/tests/ANativeWindowTest.cpp +++ b/libs/nativewindow/tests/ANativeWindowTest.cpp @@ -29,6 +29,15 @@ using namespace android; +class TestableSurface final : public Surface { +public: + explicit TestableSurface(const sp<IGraphicBufferProducer>& bufferProducer) + : Surface(bufferProducer) {} + + // Exposes the internal last dequeue duration that's stored on the Surface. + nsecs_t getLastDequeueDuration() const { return mLastDequeueDuration; } +}; + class ANativeWindowTest : public ::testing::Test { protected: void SetUp() override { @@ -37,7 +46,7 @@ protected: ALOGV("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); BufferQueue::createBufferQueue(&mProducer, &mConsumer); mItemConsumer = new BufferItemConsumer(mConsumer, GRALLOC_USAGE_SW_READ_OFTEN); - mWindow = new Surface(mProducer); + mWindow = new TestableSurface(mProducer); const int success = native_window_api_connect(mWindow.get(), NATIVE_WINDOW_API_CPU); EXPECT_EQ(0, success); } @@ -52,12 +61,14 @@ protected: sp<IGraphicBufferProducer> mProducer; sp<IGraphicBufferConsumer> mConsumer; sp<BufferItemConsumer> mItemConsumer; - sp<ANativeWindow> mWindow; + + sp<TestableSurface> mWindow; }; TEST_F(ANativeWindowTest, getLastDequeueDuration_noDequeue_returnsZero) { int result = ANativeWindow_getLastDequeueDuration(mWindow.get()); EXPECT_EQ(0, result); + EXPECT_EQ(0, mWindow->getLastDequeueDuration() / 1000); } TEST_F(ANativeWindowTest, getLastDequeueDuration_withDequeue_returnsTime) { @@ -69,4 +80,5 @@ TEST_F(ANativeWindowTest, getLastDequeueDuration_withDequeue_returnsTime) { result = ANativeWindow_getLastDequeueDuration(mWindow.get()); EXPECT_GT(result, 0); + EXPECT_EQ(result, mWindow->getLastDequeueDuration() / 1000); } |