• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "GLSnapshotTestDispatch.h"
16 #include "GLSnapshotTesting.h"
17 #include "Standalone.h"
18 #include "HelloTriangle.h"
19 #include "host-common/AndroidAgentFactory.h"
20 
21 #include <gtest/gtest.h>
22 
23 
24 namespace emugl {
25 
26 
27 
TEST(SnapshotGlRenderingSampleTest,OverrideDispatch)28 TEST(SnapshotGlRenderingSampleTest, OverrideDispatch) {
29     const GLESv2Dispatch* gl = LazyLoadedGLESv2Dispatch::get();
30     const GLESv2Dispatch* testGl = getSnapshotTestDispatch();
31     EXPECT_NE(nullptr, gl);
32     EXPECT_NE(nullptr, testGl);
33     EXPECT_NE(gl->glDrawArrays, testGl->glDrawArrays);
34     EXPECT_NE(gl->glDrawElements, testGl->glDrawElements);
35 }
36 
37 class SnapshotTestTriangle : public HelloTriangle {
38 public:
~SnapshotTestTriangle()39     virtual ~SnapshotTestTriangle() {}
40 
drawLoop()41     void drawLoop() {
42         this->initialize();
43         while (mFrameCount < 5) {
44             this->draw();
45             mFrameCount++;
46             mFb->flushWindowSurfaceColorBuffer(mSurface);
47             if (mUseSubWindow) {
48                 mFb->post(mColorBuffer);
49                 mWindow->messageLoop();
50             }
51         }
52     }
53 
54 protected:
getGlDispatch()55     const GLESv2Dispatch* getGlDispatch() { return getSnapshotTestDispatch(); }
56 
57     int mFrameCount = 0;
58 };
59 
60 template <typename T>
61 class SnapshotGlRenderingSampleTest : public ::testing::Test {
62 protected:
SetUp()63     virtual void SetUp() override {
64         // setupStandaloneLibrarySearchPaths();
65         emugl::set_emugl_window_operations(*getConsoleAgents()->emu);
66         //const EGLDispatch* egl = LazyLoadedEGLDispatch::get();
67 
68         LazyLoadedGLESv2Dispatch::get();
69         getSnapshotTestDispatch();
70 
71         mApp.reset(new T());
72     }
73 
TearDown()74     virtual void TearDown() override {
75         mApp.reset();
76         EXPECT_EQ(EGL_SUCCESS, LazyLoadedEGLDispatch::get()->eglGetError())
77                 << "SnapshotGlRenderingSampleTest TearDown found an EGL error";
78     }
79 
80     std::unique_ptr<T> mApp;
81 };
82 
83 // To test with additional SampleApplications, extend them to override drawLoop
84 // and getGlDispatch, then add the type to TestSampleApps.
85 using TestSampleApps = ::testing::Types<SnapshotTestTriangle>;
86 TYPED_TEST_SUITE(SnapshotGlRenderingSampleTest, TestSampleApps);
87 
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawOnce)88 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawOnce) {
89     this->mApp->drawOnce();
90 }
91 
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawLoop)92 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawLoop) {
93     this->mApp->drawLoop();
94 }
95 
96 }  // namespace emugl
97