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 <android-base/test_utils.h>
  21. #include "egl_cache.h"
  22. #include "egl_display.h"
  23. #include <memory>
  24. namespace android {
  25. class EGLCacheTest : public ::testing::Test {
  26. protected:
  27. virtual void SetUp() {
  28. mCache = egl_cache_t::get();
  29. }
  30. virtual void TearDown() {
  31. mCache->setCacheFilename("");
  32. mCache->terminate();
  33. }
  34. egl_cache_t* mCache;
  35. };
  36. TEST_F(EGLCacheTest, UninitializedCacheAlwaysMisses) {
  37. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  38. mCache->setBlob("abcd", 4, "efgh", 4);
  39. ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
  40. ASSERT_EQ(0xee, buf[0]);
  41. ASSERT_EQ(0xee, buf[1]);
  42. ASSERT_EQ(0xee, buf[2]);
  43. ASSERT_EQ(0xee, buf[3]);
  44. }
  45. TEST_F(EGLCacheTest, InitializedCacheAlwaysHits) {
  46. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  47. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  48. mCache->setBlob("abcd", 4, "efgh", 4);
  49. ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
  50. ASSERT_EQ('e', buf[0]);
  51. ASSERT_EQ('f', buf[1]);
  52. ASSERT_EQ('g', buf[2]);
  53. ASSERT_EQ('h', buf[3]);
  54. }
  55. TEST_F(EGLCacheTest, TerminatedCacheAlwaysMisses) {
  56. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  57. mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
  58. mCache->setBlob("abcd", 4, "efgh", 4);
  59. mCache->terminate();
  60. ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
  61. ASSERT_EQ(0xee, buf[0]);
  62. ASSERT_EQ(0xee, buf[1]);
  63. ASSERT_EQ(0xee, buf[2]);
  64. ASSERT_EQ(0xee, buf[3]);
  65. }
  66. class EGLCacheSerializationTest : public EGLCacheTest {
  67. protected:
  68. virtual void SetUp() {
  69. EGLCacheTest::SetUp();
  70. mTempFile.reset(new TemporaryFile());
  71. }
  72. virtual void TearDown() {
  73. mTempFile.reset(nullptr);
  74. EGLCacheTest::TearDown();
  75. }
  76. std::unique_ptr<TemporaryFile> mTempFile;
  77. };
  78. TEST_F(EGLCacheSerializationTest, ReinitializedCacheContainsValues) {
  79. uint8_t buf[4] = { 0xee, 0xee, 0xee, 0xee };
  80. mCache->setCacheFilename(&mTempFile->path[0]);
  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. }