@Test
public void testRemoveUnused() throws Exception {

  // Make a shader job with an empty fragment shader, and declare one uniform in the pipeline
  // state such that the uniform is not used.
  final String emptyShader = "void main() { }";
  final PipelineInfo pipelineInfo = new PipelineInfo();
  pipelineInfo.addUniform("unused", BasicType.FLOAT, Optional.empty(),
      Collections.singletonList(10.0));
  final ShaderJob shaderJob = new GlslShaderJob(Optional.empty(),
      pipelineInfo, ParseHelper.parse(emptyShader));
  // Check that initially there is indeed one uniform in the pipeline state.
  assertEquals(1, shaderJob.getPipelineInfo().getNumUniforms());
  // There should be exactly one opportunity to remove a piece of unused pipeline state.
  List<RemoveRedundantUniformMetadataReductionOpportunity> ops =
      RemoveRedundantUniformMetadataReductionOpportunities
      .findOpportunities(shaderJob,
          new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0),
              new IdGenerator()));
  assertEquals(1, ops.size());
  ops.get(0).applyReduction();
  // Check that after applying the reduction opportunity there are no uniforms in the pipeline
  // state and that the shader has not changed.
  CompareAsts.assertEqualAsts(emptyShader, shaderJob.getFragmentShader().get());
  assertEquals(0, shaderJob.getPipelineInfo().getNumUniforms());
}