Commit 18841310 by Olli Etuaho Committed by Commit Bot

Clean up MatchOutputCodeTest usage

It's cleaner to use a generic function to test that a sequence of strings is found in a specific order rather than fetching and comparing string locations in test case code. Also make sure that string occurrences can't overlap when looking for a specific number of occurrences of the same string. TEST=angle_unittests Change-Id: I8ca66c73c7aaa5be8469ded466f51d97a36c801b Reviewed-on: https://chromium-review.googlesource.com/793041Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent c677795f
......@@ -714,21 +714,11 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, GlViewportIndexIsSet)
"}\n";
compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER);
const char glViewportIndexAssignment[] = "gl_ViewportIndex = int(ViewID_OVR)";
// Check that the viewport index is selected.
EXPECT_TRUE(foundInAllGLSLCode(glViewportIndexAssignment));
// Setting gl_ViewportIndex must happen after ViewID_OVR's initialization.
const char viewIDOVRAssignment[] = "ViewID_OVR = (uint(gl_InstanceID) % 3u)";
size_t viewIDOVRAssignmentLoc = findInCode(SH_GLSL_COMPATIBILITY_OUTPUT, viewIDOVRAssignment);
size_t glViewportIndexAssignmentLoc =
findInCode(SH_GLSL_COMPATIBILITY_OUTPUT, glViewportIndexAssignment);
EXPECT_LT(viewIDOVRAssignmentLoc, glViewportIndexAssignmentLoc);
viewIDOVRAssignmentLoc = findInCode(SH_ESSL_OUTPUT, viewIDOVRAssignment);
glViewportIndexAssignmentLoc = findInCode(SH_ESSL_OUTPUT, glViewportIndexAssignment);
EXPECT_LT(viewIDOVRAssignmentLoc, glViewportIndexAssignmentLoc);
std::vector<const char *> expectedStrings = {"ViewID_OVR = (uint(gl_InstanceID) % 3u)",
"gl_ViewportIndex = int(ViewID_OVR)"};
EXPECT_TRUE(foundInCodeInOrder(SH_ESSL_OUTPUT, expectedStrings));
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
}
// The test checks that the layer is selected after the initialization of ViewID_OVR for
......@@ -744,20 +734,12 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, GlLayerIsSet)
"}\n";
compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER);
const char glLayerAssignment[] = "gl_Layer = (int(ViewID_OVR) + multiviewBaseViewLayerIndex)";
// Check that the layer is selected.
EXPECT_TRUE(foundInAllGLSLCode(glLayerAssignment));
// Setting gl_Layer must happen after ViewID_OVR's initialization.
const char viewIDOVRAssignment[] = "ViewID_OVR = (uint(gl_InstanceID) % 3u)";
size_t viewIDOVRAssignmentLoc = findInCode(SH_GLSL_COMPATIBILITY_OUTPUT, viewIDOVRAssignment);
size_t glLayerAssignmentLoc = findInCode(SH_GLSL_COMPATIBILITY_OUTPUT, glLayerAssignment);
EXPECT_LT(viewIDOVRAssignmentLoc, glLayerAssignmentLoc);
viewIDOVRAssignmentLoc = findInCode(SH_ESSL_OUTPUT, viewIDOVRAssignment);
glLayerAssignmentLoc = findInCode(SH_ESSL_OUTPUT, glLayerAssignment);
EXPECT_LT(viewIDOVRAssignmentLoc, glLayerAssignmentLoc);
std::vector<const char *> expectedStrings = {
"ViewID_OVR = (uint(gl_InstanceID) % 3u)",
"gl_Layer = (int(ViewID_OVR) + multiviewBaseViewLayerIndex)"};
EXPECT_TRUE(foundInCodeInOrder(SH_ESSL_OUTPUT, expectedStrings));
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
}
} // namespace
\ No newline at end of file
......@@ -140,19 +140,13 @@ bool MatchOutputCodeTest::compileWithSettings(ShShaderOutput output,
bool MatchOutputCodeTest::foundInCode(ShShaderOutput output, const char *stringToFind) const
{
return findInCode(output, stringToFind) != std::string::npos;
}
size_t MatchOutputCodeTest::findInCode(ShShaderOutput output, const char *stringToFind) const
{
const auto code = mOutputCode.find(output);
EXPECT_NE(mOutputCode.end(), code);
if (code == mOutputCode.end())
{
return std::string::npos;
}
return code->second.find(stringToFind);
return code->second.find(stringToFind) != std::string::npos;
}
bool MatchOutputCodeTest::foundInCodeInOrder(ShShaderOutput output,
......@@ -191,6 +185,9 @@ bool MatchOutputCodeTest::foundInCode(ShShaderOutput output,
size_t currentPos = 0;
int occurencesLeft = expectedOccurrences;
const size_t searchStringLength = strlen(stringToFind);
while (occurencesLeft-- > 0)
{
auto position = code->second.find(stringToFind, currentPos);
......@@ -198,8 +195,10 @@ bool MatchOutputCodeTest::foundInCode(ShShaderOutput output,
{
return false;
}
currentPos = position + 1;
// Search strings should not overlap.
currentPos = position + searchStringLength;
}
// Make sure that there aren't extra occurrences.
return code->second.find(stringToFind, currentPos) == std::string::npos;
}
......
......@@ -65,9 +65,6 @@ class MatchOutputCodeTest : public testing::Test
}
bool foundInCode(ShShaderOutput output, const char *stringToFind) const;
// Returns the position of the first character of the first match in the translated output
// source. If no matches are found, then string::npos is returned.
size_t findInCode(ShShaderOutput output, const char *stringToFind) const;
// Test that the strings are found in the specified output in the specified order.
bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment