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 #include "host-common/testing/MockAndroidAgentFactory.h"
21
22 #include <gtest/gtest.h>
23
24
25 namespace emugl {
26
27
28
TEST(SnapshotGlRenderingSampleTest,OverrideDispatch)29 TEST(SnapshotGlRenderingSampleTest, OverrideDispatch) {
30 const GLESv2Dispatch* gl = LazyLoadedGLESv2Dispatch::get();
31 const GLESv2Dispatch* testGl = getSnapshotTestDispatch();
32 EXPECT_NE(nullptr, gl);
33 EXPECT_NE(nullptr, testGl);
34 EXPECT_NE(gl->glDrawArrays, testGl->glDrawArrays);
35 EXPECT_NE(gl->glDrawElements, testGl->glDrawElements);
36 }
37
38 class SnapshotTestTriangle : public HelloTriangle {
39 public:
~SnapshotTestTriangle()40 virtual ~SnapshotTestTriangle() {}
41
drawLoop()42 void drawLoop() {
43 this->initialize();
44 while (mFrameCount < 5) {
45 this->draw();
46 mFrameCount++;
47 mFb->flushWindowSurfaceColorBuffer(mSurface);
48 if (mUseSubWindow) {
49 mFb->post(mColorBuffer);
50 mWindow->messageLoop();
51 }
52 }
53 }
54
55 protected:
getGlDispatch()56 const GLESv2Dispatch* getGlDispatch() { return getSnapshotTestDispatch(); }
57
58 int mFrameCount = 0;
59 };
60
61 template <typename T>
62 class SnapshotGlRenderingSampleTest : public ::testing::Test {
63 protected:
SetUpTestSuite()64 static void SetUpTestSuite() {
65 android::emulation::injectConsoleAgents(
66 android::emulation::MockAndroidConsoleFactory());
67 }
68
TearDownTestSuite()69 static void TearDownTestSuite() { }
70
SetUp()71 virtual void SetUp() override {
72 // setupStandaloneLibrarySearchPaths();
73 emugl::set_emugl_window_operations(*getConsoleAgents()->emu);
74 //const EGLDispatch* egl = LazyLoadedEGLDispatch::get();
75
76 LazyLoadedGLESv2Dispatch::get();
77 getSnapshotTestDispatch();
78
79 mApp.reset(new T());
80 }
81
TearDown()82 virtual void TearDown() override {
83 mApp.reset();
84 EXPECT_EQ(EGL_SUCCESS, LazyLoadedEGLDispatch::get()->eglGetError())
85 << "SnapshotGlRenderingSampleTest TearDown found an EGL error";
86 }
87
88 std::unique_ptr<T> mApp;
89 };
90
91 // To test with additional SampleApplications, extend them to override drawLoop
92 // and getGlDispatch, then add the type to TestSampleApps.
93 using TestSampleApps = ::testing::Types<SnapshotTestTriangle>;
94 TYPED_TEST_SUITE(SnapshotGlRenderingSampleTest, TestSampleApps);
95
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawOnce)96 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawOnce) {
97 this->mApp->drawOnce();
98 }
99
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawLoop)100 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawLoop) {
101 this->mApp->drawLoop();
102 }
103
104 } // namespace emugl
105