skia2/tests/GrGLExtensionsTest.cpp
Vladimir Levin 70fb479ae6 Ensure that removing last extension from GrGLExtension doesn't assert.
This patch fixes an assert that triggers when removing the last
extension in the list, since the index operator goes out of bounds.

Added a test that fails without the code changes and passes with the
changes.

R=bsalomon@chromium.org

Change-Id: I0d561b150899c178f638dde088af773fddf112d9
Reviewed-on: https://skia-review.googlesource.com/72000
Commit-Queue: Vladimir Levin <vmpstr@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2017-11-15 20:25:42 +00:00

54 lines
1.5 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
// This test is a GPU-backend specific test.
#if SK_SUPPORT_GPU
#include "gl/GrGLDefines.h"
#include "gl/GrGLExtensions.h"
#include "Test.h"
const GrGLubyte* simpleGetString(GrGLenum name) {
return (const GrGLubyte*)(name == GR_GL_VERSION ? "3.0" : "");
}
void simpleGetIntegerv(GrGLenum name, GrGLint* params) {
if (name == GR_GL_NUM_EXTENSIONS) {
*params = 2;
} else {
*params = 0;
}
}
const GrGLubyte* simpleGetStringi(GrGLenum name, GrGLuint index) {
if (name != GR_GL_EXTENSIONS || index >= 2)
return (const GrGLubyte*)"";
return (const GrGLubyte*)(index == 0 ? "test_extension_1" : "test_extension_2");
}
DEF_TEST(GrGLExtensionsTest_remove, reporter) {
GrGLExtensions ext;
ext.init(kNone_GrGLStandard,
&simpleGetString,
&simpleGetStringi,
&simpleGetIntegerv,
nullptr,
nullptr);
REPORTER_ASSERT(reporter, ext.isInitialized());
REPORTER_ASSERT(reporter, ext.has("test_extension_1"));
REPORTER_ASSERT(reporter, ext.has("test_extension_2"));
REPORTER_ASSERT(reporter, ext.remove("test_extension_2"));
REPORTER_ASSERT(reporter, !ext.has("test_extension_2"));
REPORTER_ASSERT(reporter, ext.remove("test_extension_1"));
REPORTER_ASSERT(reporter, !ext.has("test_extension_1"));
}
#endif