Cleanup: Use EnumCase for ExecutionMode test
authorDavid Neto <dneto@google.com>
Mon, 28 Sep 2015 15:22:23 +0000 (11:22 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
test/TextToBinary.ModeSetting.cpp

index f60f461..6e24935 100644 (file)
@@ -131,71 +131,61 @@ INSTANTIATE_TEST_CASE_P(TextToBinaryEntryPoint, OpEntryPointTest,
 
 // Test OpExecutionMode
 
-// A single test case for a simple OpExecutionMode.
-// An execution mode has no operands, or just literal numbers as operands.
-struct ExecutionModeCase {
-  uint32_t get_mode_value() const { return static_cast<uint32_t>(mode_value); }
-  spv::ExecutionMode mode_value;
-  std::string mode_name;
-  std::vector<uint32_t> operands;
-};
-
 using OpExecutionModeTest = spvtest::TextToBinaryTestBase<
-    ::testing::TestWithParam<ExecutionModeCase>>;
+    ::testing::TestWithParam<EnumCase<spv::ExecutionMode>>>;
 
 TEST_P(OpExecutionModeTest, AnyExecutionMode) {
   // This string should assemble, but should not validate.
   std::stringstream input;
-  input << "OpExecutionMode %1 " << GetParam().mode_name;
-  for (auto operand : GetParam().operands) input << " " << operand;
-  std::vector<uint32_t> expected_operands{1, GetParam().get_mode_value()};
-  expected_operands.insert(expected_operands.end(), GetParam().operands.begin(),
-                           GetParam().operands.end());
+  input << "OpExecutionMode %1 " << GetParam().name();
+  for (auto operand : GetParam().operands()) input << " " << operand;
+  std::vector<uint32_t> expected_operands{1, GetParam().value()};
+  expected_operands.insert(expected_operands.end(), GetParam().operands().begin(),
+                           GetParam().operands().end());
   EXPECT_THAT(CompiledInstructions(input.str()),
               Eq(MakeInstruction(spv::OpExecutionMode, expected_operands)));
 }
 
-// clang-format off
 #define CASE(NAME) spv::ExecutionMode##NAME, #NAME
-INSTANTIATE_TEST_CASE_P(TextToBinaryExecutionMode, OpExecutionModeTest,
-                        ::testing::ValuesIn(std::vector<ExecutionModeCase>{
-                          // The operand literal values are arbitrarily chosen,
-                          // but there are the right number of them.
-                            {CASE(Invocations), {101}},
-                            {CASE(SpacingEqual), {}},
-                            {CASE(SpacingFractionalEven), {}},
-                            {CASE(SpacingFractionalOdd), {}},
-                            {CASE(VertexOrderCw), {}},
-                            {CASE(VertexOrderCcw), {}},
-                            {CASE(PixelCenterInteger), {}},
-                            {CASE(OriginUpperLeft), {}},
-                            {CASE(OriginLowerLeft), {}},
-                            {CASE(EarlyFragmentTests), {}},
-                            {CASE(PointMode), {}},
-                            {CASE(Xfb), {}},
-                            {CASE(DepthReplacing), {}},
-                            {CASE(DepthGreater), {}},
-                            {CASE(DepthLess), {}},
-                            {CASE(DepthUnchanged), {}},
-                            {CASE(LocalSize), {64,1,2}},
-                            {CASE(LocalSizeHint), {8,2,4}},
-                            {CASE(InputPoints), {}},
-                            {CASE(InputLines), {}},
-                            {CASE(InputLinesAdjacency), {}},
-                            {CASE(InputTriangles), {}},
-                            {CASE(InputTrianglesAdjacency), {}},
-                            {CASE(InputQuads), {}},
-                            {CASE(InputIsolines), {}},
-                            {CASE(OutputVertices), {21}},
-                            {CASE(OutputPoints), {}},
-                            {CASE(OutputLineStrip), {}},
-                            {CASE(OutputTriangleStrip), {}},
-                            {CASE(VecTypeHint), {96}},
-                            {CASE(ContractionOff), {}},
-                            {CASE(IndependentForwardProgress), {}},
-                        }));
+INSTANTIATE_TEST_CASE_P(
+    TextToBinaryExecutionMode, OpExecutionModeTest,
+    ::testing::ValuesIn(std::vector<EnumCase<spv::ExecutionMode>>{
+        // The operand literal values are arbitrarily chosen,
+        // but there are the right number of them.
+        {CASE(Invocations), {101}},
+        {CASE(SpacingEqual), {}},
+        {CASE(SpacingFractionalEven), {}},
+        {CASE(SpacingFractionalOdd), {}},
+        {CASE(VertexOrderCw), {}},
+        {CASE(VertexOrderCcw), {}},
+        {CASE(PixelCenterInteger), {}},
+        {CASE(OriginUpperLeft), {}},
+        {CASE(OriginLowerLeft), {}},
+        {CASE(EarlyFragmentTests), {}},
+        {CASE(PointMode), {}},
+        {CASE(Xfb), {}},
+        {CASE(DepthReplacing), {}},
+        {CASE(DepthGreater), {}},
+        {CASE(DepthLess), {}},
+        {CASE(DepthUnchanged), {}},
+        {CASE(LocalSize), {64, 1, 2}},
+        {CASE(LocalSizeHint), {8, 2, 4}},
+        {CASE(InputPoints), {}},
+        {CASE(InputLines), {}},
+        {CASE(InputLinesAdjacency), {}},
+        {CASE(InputTriangles), {}},
+        {CASE(InputTrianglesAdjacency), {}},
+        {CASE(InputQuads), {}},
+        {CASE(InputIsolines), {}},
+        {CASE(OutputVertices), {21}},
+        {CASE(OutputPoints), {}},
+        {CASE(OutputLineStrip), {}},
+        {CASE(OutputTriangleStrip), {}},
+        {CASE(VecTypeHint), {96}},
+        {CASE(ContractionOff), {}},
+        {CASE(IndependentForwardProgress), {}},
+    }));
 #undef CASE
-// clang-format on
 
 // Test OpCapability