Hash :
66e0feec
        
        Author :
  
        
        Date :
2019-09-03T18:45:43
        
      
Remove default template args in ResourceMap. Only need GLuints now for GLsyncs. Bug: angleproject:3611 Change-Id: Id8b11851d8d5d30e6743433c772b9fa85eb875f5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1783406 Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ResourceMap_unittest:
//   Unit tests for the ResourceMap template class.
//
#include <gtest/gtest.h>
#include "libANGLE/ResourceMap.h"
using namespace gl;
namespace
{
// Tests assigning slots in the map and then deleting elements.
TEST(ResourceMapTest, AssignAndErase)
{
    constexpr size_t kSize = 64;
    ResourceMap<size_t, GLuint> resourceMap;
    std::vector<size_t> objects(kSize, 1);
    for (size_t index = 0; index < kSize; ++index)
    {
        resourceMap.assign(index + 1, &objects[index]);
    }
    for (size_t index = 0; index < kSize; ++index)
    {
        size_t *found = nullptr;
        ASSERT_TRUE(resourceMap.erase(index + 1, &found));
        ASSERT_EQ(&objects[index], found);
    }
    ASSERT_TRUE(resourceMap.empty());
}
// Tests assigning slots in the map and then using clear() to free it.
TEST(ResourceMapTest, AssignAndClear)
{
    constexpr size_t kSize = 64;
    ResourceMap<size_t, GLuint> resourceMap;
    std::vector<size_t> objects(kSize, 1);
    for (size_t index = 0; index < kSize; ++index)
    {
        resourceMap.assign(index + 1, &objects[index]);
    }
    resourceMap.clear();
    ASSERT_TRUE(resourceMap.empty());
}
// Tests growing a map more than double the size.
TEST(ResourceMapTest, BigGrowth)
{
    constexpr size_t kSize = 8;
    ResourceMap<size_t, GLuint> resourceMap;
    std::vector<size_t> objects;
    for (size_t index = 0; index < kSize; ++index)
    {
        objects.push_back(index);
    }
    // Assign a large value.
    constexpr size_t kLargeIndex = 128;
    objects.push_back(kLargeIndex);
    for (size_t &object : objects)
    {
        resourceMap.assign(object, &object);
    }
    for (size_t object : objects)
    {
        size_t *found = nullptr;
        ASSERT_TRUE(resourceMap.erase(object, &found));
        ASSERT_EQ(object, *found);
    }
    ASSERT_TRUE(resourceMap.empty());
}
// Tests querying unassigned or erased values.
TEST(ResourceMapTest, QueryUnassigned)
{
    constexpr size_t kSize = 8;
    ResourceMap<size_t, GLuint> resourceMap;
    std::vector<size_t> objects;
    for (size_t index = 0; index < kSize; ++index)
    {
        objects.push_back(index);
    }
    ASSERT_FALSE(resourceMap.contains(0));
    ASSERT_EQ(nullptr, resourceMap.query(0));
    ASSERT_FALSE(resourceMap.contains(100));
    ASSERT_EQ(nullptr, resourceMap.query(100));
    for (size_t &object : objects)
    {
        resourceMap.assign(object, &object);
    }
    ASSERT_FALSE(resourceMap.empty());
    for (size_t &object : objects)
    {
        ASSERT_TRUE(resourceMap.contains(object));
        ASSERT_EQ(&object, resourceMap.query(object));
    }
    ASSERT_FALSE(resourceMap.contains(10));
    ASSERT_EQ(nullptr, resourceMap.query(10));
    ASSERT_FALSE(resourceMap.contains(100));
    ASSERT_EQ(nullptr, resourceMap.query(100));
    for (size_t object : objects)
    {
        size_t *found = nullptr;
        ASSERT_TRUE(resourceMap.erase(object, &found));
        ASSERT_EQ(object, *found);
    }
    ASSERT_TRUE(resourceMap.empty());
    ASSERT_FALSE(resourceMap.contains(0));
    ASSERT_EQ(nullptr, resourceMap.query(0));
    ASSERT_FALSE(resourceMap.contains(100));
    ASSERT_EQ(nullptr, resourceMap.query(100));
}
}  // anonymous namespace