Hash :
c853804c
Author :
Date :
2017-09-27T11:20:15
Add support for arrays of arrays to VariableLocation Array indices are sorted so that the outermost index is in the back. This is because we want to be consistent with future arrays of arrays parsing code. In parsing we'll have a utility function to make a TType object into an array, and there it's most natural to push the new outermost sizes to the back of the vector. Further patches will still be needed to parse arrays of arrays and add support to arrays of arrays into the API. BUG=angleproject:2125 TEST=angle_unittests, angle_end2end_tests Change-Id: I6c88edabf68ae9dbd803ec6d20543016c408b702 Reviewed-on: https://chromium-review.googlesource.com/686414 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
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
//
// Copyright (c) 2015 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.
// utilities_unittest.cpp: Unit tests for ANGLE's GL utility functions
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "common/utilities.h"
namespace
{
// Test parsing valid single array indices
TEST(ParseResourceName, ArrayIndex)
{
std::vector<unsigned int> indices;
EXPECT_EQ("foo", gl::ParseResourceName("foo[123]", &indices));
ASSERT_EQ(1u, indices.size());
EXPECT_EQ(123u, indices[0]);
EXPECT_EQ("bar", gl::ParseResourceName("bar[0]", &indices));
ASSERT_EQ(1u, indices.size());
EXPECT_EQ(0u, indices[0]);
}
// Parsing a negative array index should result in INVALID_INDEX.
TEST(ParseResourceName, NegativeArrayIndex)
{
std::vector<unsigned int> indices;
EXPECT_EQ("foo", gl::ParseResourceName("foo[-1]", &indices));
ASSERT_EQ(1u, indices.size());
EXPECT_EQ(GL_INVALID_INDEX, indices.back());
}
// Parsing no array indices should result in an empty array.
TEST(ParseResourceName, NoArrayIndex)
{
std::vector<unsigned int> indices;
EXPECT_EQ("foo", gl::ParseResourceName("foo", &indices));
EXPECT_TRUE(indices.empty());
}
// The ParseResourceName function should work when a nullptr is passed as the indices output vector.
TEST(ParseResourceName, NULLArrayIndices)
{
EXPECT_EQ("foo", gl::ParseResourceName("foo[10]", nullptr));
}
// Parsing multiple array indices should result in outermost array indices being last in the vector.
TEST(ParseResourceName, MultipleArrayIndices)
{
std::vector<unsigned int> indices;
EXPECT_EQ("foo", gl::ParseResourceName("foo[12][34][56]", &indices));
ASSERT_EQ(3u, indices.size());
// Indices are sorted with outermost array index last.
EXPECT_EQ(56u, indices[0]);
EXPECT_EQ(34u, indices[1]);
EXPECT_EQ(12u, indices[2]);
}
// Trailing whitespace should not be accepted by ParseResourceName.
TEST(ParseResourceName, TrailingWhitespace)
{
std::vector<unsigned int> indices;
EXPECT_EQ("foo ", gl::ParseResourceName("foo ", &indices));
EXPECT_TRUE(indices.empty());
EXPECT_EQ("foo[10] ", gl::ParseResourceName("foo[10] ", &indices));
EXPECT_TRUE(indices.empty());
EXPECT_EQ("foo[10][20] ", gl::ParseResourceName("foo[10][20] ", &indices));
EXPECT_TRUE(indices.empty());
}
}