Home | History | Annotate | Download | only in EGLTest
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "EGL_test"
     18 //#define LOG_NDEBUG 0
     19 
     20 #include <gtest/gtest.h>
     21 
     22 #include <utils/Log.h>
     23 
     24 #include "egl_cache.h"
     25 #include "egl_display.h"
     26 
     27 namespace android {
     28 
     29 class EGLCacheTest : public ::testing::Test {
     30 protected:
     31     virtual void SetUp() {
     32         mCache = egl_cache_t::get();
     33     }
     34 
     35     virtual void TearDown() {
     36         mCache->setCacheFilename("");
     37         mCache->terminate();
     38     }
     39 
     40     egl_cache_t* mCache;
     41 };
     42 
     43 TEST_F(EGLCacheTest, UninitializedCacheAlwaysMisses) {
     44     char buf[4] = { 0xee, 0xee, 0xee, 0xee };
     45     mCache->setBlob("abcd", 4, "efgh", 4);
     46     ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
     47     ASSERT_EQ(0xee, buf[0]);
     48     ASSERT_EQ(0xee, buf[1]);
     49     ASSERT_EQ(0xee, buf[2]);
     50     ASSERT_EQ(0xee, buf[3]);
     51 }
     52 
     53 TEST_F(EGLCacheTest, InitializedCacheAlwaysHits) {
     54     char buf[4] = { 0xee, 0xee, 0xee, 0xee };
     55     mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
     56     mCache->setBlob("abcd", 4, "efgh", 4);
     57     ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
     58     ASSERT_EQ('e', buf[0]);
     59     ASSERT_EQ('f', buf[1]);
     60     ASSERT_EQ('g', buf[2]);
     61     ASSERT_EQ('h', buf[3]);
     62 }
     63 
     64 TEST_F(EGLCacheTest, TerminatedCacheAlwaysMisses) {
     65     char buf[4] = { 0xee, 0xee, 0xee, 0xee };
     66     mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
     67     mCache->setBlob("abcd", 4, "efgh", 4);
     68     mCache->terminate();
     69     ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
     70     ASSERT_EQ(0xee, buf[0]);
     71     ASSERT_EQ(0xee, buf[1]);
     72     ASSERT_EQ(0xee, buf[2]);
     73     ASSERT_EQ(0xee, buf[3]);
     74 }
     75 
     76 class EGLCacheSerializationTest : public EGLCacheTest {
     77 
     78 protected:
     79 
     80     virtual void SetUp() {
     81         EGLCacheTest::SetUp();
     82 
     83         char* tn = tempnam("/sdcard", "EGL_test-cache-");
     84         mFilename = tn;
     85         free(tn);
     86     }
     87 
     88     virtual void TearDown() {
     89         unlink(mFilename.string());
     90         EGLCacheTest::TearDown();
     91     }
     92 
     93     String8 mFilename;
     94 };
     95 
     96 TEST_F(EGLCacheSerializationTest, ReinitializedCacheContainsValues) {
     97     char buf[4] = { 0xee, 0xee, 0xee, 0xee };
     98     mCache->setCacheFilename(mFilename);
     99     mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
    100     mCache->setBlob("abcd", 4, "efgh", 4);
    101     mCache->terminate();
    102     mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
    103     ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
    104     ASSERT_EQ('e', buf[0]);
    105     ASSERT_EQ('f', buf[1]);
    106     ASSERT_EQ('g', buf[2]);
    107     ASSERT_EQ('h', buf[3]);
    108 }
    109 
    110 }
    111