Use 3-arg MakeInstruction to reduce logic in tests
authorDavid Neto <dneto@google.com>
Thu, 1 Oct 2015 15:24:11 +0000 (11:24 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
Avoids open-coded vector inserts and two variables in various
tests.  Should improve readability.

test/TextToBinary.Annotation.cpp
test/TextToBinary.Debug.cpp
test/TextToBinary.Image.cpp
test/TextToBinary.Memory.cpp
test/TextToBinary.ModeSetting.cpp

index b2e54cc..a429424 100644 (file)
@@ -51,12 +51,10 @@ TEST_P(OpDecorateSimpleTest, AnySimpleDecoration) {
   std::stringstream input;
   input << "OpDecorate %1 " << GetParam().name();
   for (auto operand : GetParam().operands()) input << " " << operand;
-  std::vector<uint32_t> expected_operands{1, uint32_t(GetParam().value())};
-  expected_operands.insert(expected_operands.end(),
-                           GetParam().operands().begin(),
-                           GetParam().operands().end());
-  EXPECT_THAT(CompiledInstructions(input.str()),
-              Eq(MakeInstruction(spv::OpDecorate, expected_operands)));
+  EXPECT_THAT(
+      CompiledInstructions(input.str()),
+      Eq(MakeInstruction(spv::OpDecorate, {1, uint32_t(GetParam().value())},
+                         GetParam().operands())));
 }
 
 #define CASE(NAME) spv::Decoration##NAME, #NAME
index d1369a5..0985903 100644 (file)
@@ -92,12 +92,10 @@ TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalFileId) {
 TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalSourceText) {
   std::string fake_source = "To be or not to be";
   std::string input = "OpSource GLSL 450 %file_id \"" + fake_source + "\"";
-  std::vector<uint32_t> expected_operands = {spv::SourceLanguageGLSL, 450, 1};
-  std::vector<uint32_t> encoded_source = MakeVector(fake_source);
-  expected_operands.insert(expected_operands.end(), encoded_source.begin(),
-                           encoded_source.end());
-  EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpSource, expected_operands)));
+  EXPECT_THAT(
+      CompiledInstructions(input),
+      Eq(MakeInstruction(spv::OpSource, {spv::SourceLanguageGLSL, 450, 1},
+                         MakeVector(fake_source))));
 };
 
 // Test OpSourceContinued
@@ -152,10 +150,8 @@ using OpStringTest =
 TEST_P(OpStringTest, AnyString) {
   // TODO(dneto): utf-8, quoting, escaping
   std::string input = std::string("%result = OpString \"") + GetParam() + "\"";
-  std::vector<uint32_t> expected_operands = MakeVector(GetParam());
-  expected_operands.insert(expected_operands.begin(), 1);  // The ID of the result.
   EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpString, expected_operands)));
+              Eq(MakeInstruction(spv::OpString, {1}, MakeVector(GetParam()))));
 }
 
 // TODO(dneto): utf-8, quoting, escaping
@@ -169,10 +165,8 @@ using OpNameTest =
 TEST_P(OpNameTest, AnyString) {
   // TODO(dneto): utf-8, quoting, escaping
   std::string input = std::string("OpName %target \"") + GetParam() + "\"";
-  std::vector<uint32_t> expected_operands = MakeVector(GetParam());
-  expected_operands.insert(expected_operands.begin(), 1);  // The ID of the target.
   EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpName, expected_operands)));
+              Eq(MakeInstruction(spv::OpName, {1}, MakeVector(GetParam()))));
 }
 
 // TODO(dneto): utf-8, quoting, escaping
@@ -187,12 +181,9 @@ TEST_P(OpMemberNameTest, AnyString) {
   // TODO(dneto): utf-8, quoting, escaping
   std::string input =
       std::string("OpMemberName %type 42 \"") + GetParam() + "\"";
-  std::vector<uint32_t> expected_operands = {1, 42};
-  std::vector<uint32_t> encoded_string = MakeVector(GetParam());
-  expected_operands.insert(expected_operands.end(), encoded_string.begin(),
-                           encoded_string.end());
-  EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpMemberName, expected_operands)));
+  EXPECT_THAT(
+      CompiledInstructions(input),
+      Eq(MakeInstruction(spv::OpMemberName, {1, 42}, MakeVector(GetParam()))));
 }
 
 // TODO(dneto): utf-8, quoting, escaping
index 290755d..30c9171 100644 (file)
@@ -52,12 +52,9 @@ using ImageOperandsTest = spvtest::TextToBinaryTestBase<
 TEST_P(ImageOperandsTest, Sample) {
   std::string input =
       "%result = OpImageFetch %type %image %coord " + GetParam().image_operands;
-  std::vector<uint32_t> expected_operands{1, 2, 3, 4};
-  expected_operands.insert(expected_operands.end(),
-                           GetParam().expected_mask_and_operands.begin(),
-                           GetParam().expected_mask_and_operands.end());
   EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpImageFetch, expected_operands)));
+              Eq(MakeInstruction(spv::OpImageFetch, {1, 2, 3, 4},
+                                 GetParam().expected_mask_and_operands)));
 }
 
 #define MASK(NAME) spv::ImageOperands##NAME##Mask
index 82104d4..6226198 100644 (file)
@@ -49,11 +49,9 @@ TEST_P(MemoryAccessTest, AnySingleMemoryAccessMask) {
   std::stringstream input;
   input << "OpStore %ptr %value " << GetParam().name();
   for (auto operand : GetParam().operands()) input << " " << operand;
-  std::vector<uint32_t> expected_operands{1, 2, GetParam().value()};
-  expected_operands.insert(expected_operands.end(), GetParam().operands().begin(),
-                           GetParam().operands().end());
   EXPECT_THAT(CompiledInstructions(input.str()),
-              Eq(MakeInstruction(spv::OpStore, expected_operands)));
+              Eq(MakeInstruction(spv::OpStore, {1, 2, GetParam().value()},
+                                 GetParam().operands())));
 }
 
 INSTANTIATE_TEST_CASE_P(
index 9601841..86897dc 100644 (file)
@@ -104,14 +104,10 @@ TEST_P(OpEntryPointTest, AnyEntryPointCase) {
   // TODO(dneto): utf-8, escaping, quoting cases for entry point name.
   std::string input = "OpEntryPoint " + GetParam().execution_name + " %1 \"" +
                       GetParam().entry_point_name + "\"";
-  std::vector<uint32_t> expected_operands{GetParam().get_execution_value(), 1};
-  std::vector<uint32_t> encoded_entry_point_name =
-      MakeVector(GetParam().entry_point_name);
-  expected_operands.insert(expected_operands.end(),
-                           encoded_entry_point_name.begin(),
-                           encoded_entry_point_name.end());
   EXPECT_THAT(CompiledInstructions(input),
-              Eq(MakeInstruction(spv::OpEntryPoint, expected_operands)));
+              Eq(MakeInstruction(spv::OpEntryPoint,
+                                 {GetParam().get_execution_value(), 1},
+                                 MakeVector(GetParam().entry_point_name))));
 }
 
 // clang-format off
@@ -139,11 +135,9 @@ TEST_P(OpExecutionModeTest, AnyExecutionMode) {
   std::stringstream input;
   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)));
+              Eq(MakeInstruction(spv::OpExecutionMode, {1, GetParam().value()},
+                                 GetParam().operands())));
 }
 
 #define CASE(NAME) spv::ExecutionMode##NAME, #NAME