egl_cache_test.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define LOG_TAG "EGL_test"
  17. //#define LOG_NDEBUG 0
  18. #include <gtest/gtest.h>
  19. #include <utils/Log.h>
  20. #include "egl_cache.h"
  21. #include "egl_display.h"
  22. namespace android {
  23. class EGLCacheTest : public ::testing::Test {
  24. protected:
  25. virtual void SetUp() {
  26. mCache = egl_cache_t::get();
  27. }
  28. virtual void TearDown() {
  29. mCache->setCacheFilename("");
  30. mCache->terminate();
  31. }
  32. egl_cache_t* mCache;
  33. };
  34. TEST_F(EGLCacheTest, UninitializedCacheAlwaysMisses) {
  35. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  36. mCache->setBlob("abcd", 4, "efgh", 4);
  37. ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
  38. ASSERT_EQ(0xee, buf[0]);
  39. ASSERT_EQ(0xee, buf[1]);
  40. ASSERT_EQ(0xee, buf[2]);
  41. ASSERT_EQ(0xee, buf[3]);
  42. }
  43. TEST_F(EGLCacheTest, InitializedCacheAlwaysHits) {
  44. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  45. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  46. mCache->setBlob("abcd", 4, "efgh", 4);
  47. ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
  48. ASSERT_EQ('e', buf[0]);
  49. ASSERT_EQ('f', buf[1]);
  50. ASSERT_EQ('g', buf[2]);
  51. ASSERT_EQ('h', buf[3]);
  52. }
  53. TEST_F(EGLCacheTest, TerminatedCacheAlwaysMisses) {
  54. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  55. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  56. mCache->setBlob("abcd", 4, "efgh", 4);
  57. mCache->terminate();
  58. ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
  59. ASSERT_EQ(0xee, buf[0]);
  60. ASSERT_EQ(0xee, buf[1]);
  61. ASSERT_EQ(0xee, buf[2]);
  62. ASSERT_EQ(0xee, buf[3]);
  63. }
  64. class EGLCacheSerializationTest : public EGLCacheTest {
  65. protected:
  66. virtual void SetUp() {
  67. EGLCacheTest::SetUp();
  68. char* tn = tempnam("/sdcard", "EGL_test-cache-");
  69. mFilename = tn;
  70. free(tn);
  71. }
  72. virtual void TearDown() {
  73. unlink(mFilename.string());
  74. EGLCacheTest::TearDown();
  75. }
  76. String8 mFilename;
  77. };
  78. TEST_F(EGLCacheSerializationTest, ReinitializedCacheContainsValues) {
  79. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  80. mCache->setCacheFilename(mFilename);
  81. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  82. mCache->setBlob("abcd", 4, "efgh", 4);
  83. mCache->terminate();
  84. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  85. ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
  86. ASSERT_EQ('e', buf[0]);
  87. ASSERT_EQ('f', buf[1]);
  88. ASSERT_EQ('g', buf[2]);
  89. ASSERT_EQ('h', buf[3]);
  90. }
  91. }