summaryrefslogtreecommitdiffstats
path: root/opengl/tests/EGLTest/egl_cache_test.cpp
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2011-12-16 14:45:56 -0800
committerSteve Kondik <shade@chemlab.org>2011-12-16 14:45:56 -0800
commitbec96948c8ea41c022fe7e68ccdfdaa1a1128871 (patch)
treed18f611794386ae7058f3a4b66e2c867bf14c70a /opengl/tests/EGLTest/egl_cache_test.cpp
parent7e350ef016b80203bc1b1c275729fe8c441a7728 (diff)
parent8b6ed2d17d5e7e47944026679c9cba66611ab27f (diff)
downloadframeworks_base-bec96948c8ea41c022fe7e68ccdfdaa1a1128871.zip
frameworks_base-bec96948c8ea41c022fe7e68ccdfdaa1a1128871.tar.gz
frameworks_base-bec96948c8ea41c022fe7e68ccdfdaa1a1128871.tar.bz2
Merge branch 'ics-mr1' of https://android.googlesource.com/platform/frameworks/base into aosp
Conflicts: core/res/res/values/strings.xml policy/src/com/android/internal/policy/impl/GlobalActions.java services/java/com/android/server/WifiService.java services/sensorservice/SensorDevice.cpp telephony/java/com/android/internal/telephony/RIL.java Change-Id: I89ec56d5ff282a2eb879ca40fb6d74ebcf752837
Diffstat (limited to 'opengl/tests/EGLTest/egl_cache_test.cpp')
-rw-r--r--opengl/tests/EGLTest/egl_cache_test.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/opengl/tests/EGLTest/egl_cache_test.cpp b/opengl/tests/EGLTest/egl_cache_test.cpp
new file mode 100644
index 0000000..c7d9e3e
--- /dev/null
+++ b/opengl/tests/EGLTest/egl_cache_test.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "EGL_test"
+//#define LOG_NDEBUG 0
+
+#include <gtest/gtest.h>
+
+#include <utils/Log.h>
+
+#include "egl_cache.h"
+#include "egl_display.h"
+
+namespace android {
+
+class EGLCacheTest : public ::testing::Test {
+protected:
+ virtual void SetUp() {
+ mCache = egl_cache_t::get();
+ }
+
+ virtual void TearDown() {
+ mCache->setCacheFilename("");
+ mCache->terminate();
+ }
+
+ egl_cache_t* mCache;
+};
+
+TEST_F(EGLCacheTest, UninitializedCacheAlwaysMisses) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ(0xee, buf[0]);
+ ASSERT_EQ(0xee, buf[1]);
+ ASSERT_EQ(0xee, buf[2]);
+ ASSERT_EQ(0xee, buf[3]);
+}
+
+TEST_F(EGLCacheTest, InitializedCacheAlwaysHits) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ('e', buf[0]);
+ ASSERT_EQ('f', buf[1]);
+ ASSERT_EQ('g', buf[2]);
+ ASSERT_EQ('h', buf[3]);
+}
+
+TEST_F(EGLCacheTest, TerminatedCacheAlwaysMisses) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ mCache->terminate();
+ ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ(0xee, buf[0]);
+ ASSERT_EQ(0xee, buf[1]);
+ ASSERT_EQ(0xee, buf[2]);
+ ASSERT_EQ(0xee, buf[3]);
+}
+
+class EGLCacheSerializationTest : public EGLCacheTest {
+
+protected:
+
+ virtual void SetUp() {
+ EGLCacheTest::SetUp();
+
+ char* tn = tempnam("/sdcard", "EGL_test-cache-");
+ mFilename = tn;
+ free(tn);
+ }
+
+ virtual void TearDown() {
+ unlink(mFilename.string());
+ EGLCacheTest::TearDown();
+ }
+
+ String8 mFilename;
+};
+
+TEST_F(EGLCacheSerializationTest, ReinitializedCacheContainsValues) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->setCacheFilename(mFilename);
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ mCache->terminate();
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ('e', buf[0]);
+ ASSERT_EQ('f', buf[1]);
+ ASSERT_EQ('g', buf[2]);
+ ASSERT_EQ('h', buf[3]);
+}
+
+}