| 41 | const uint32_t kExpectedSpvVersion = 0x10100; |
| 42 | |
| 43 | TEST(CppInterface, SuccessfulRoundTrip) { |
| 44 | const std::string input_text = "%2 = OpSizeOf %1 %3\n"; |
| 45 | SpirvTools t(SPV_ENV_UNIVERSAL_1_1); |
| 46 | |
| 47 | std::vector<uint32_t> binary; |
| 48 | EXPECT_TRUE(t.Assemble(input_text, &binary)); |
| 49 | EXPECT_TRUE(binary.size() > 5u); |
| 50 | EXPECT_EQ(spv::MagicNumber, binary[0]); |
| 51 | EXPECT_EQ(kExpectedSpvVersion, binary[1]); |
| 52 | |
| 53 | // This cannot pass validation since %1 is not defined. |
| 54 | t.SetMessageConsumer([](spv_message_level_t level, const char* source, |
| 55 | const spv_position_t& position, const char* message) { |
| 56 | EXPECT_EQ(SPV_MSG_ERROR, level); |
| 57 | EXPECT_STREQ("input", source); |
| 58 | EXPECT_EQ(0u, position.line); |
| 59 | EXPECT_EQ(0u, position.column); |
| 60 | EXPECT_EQ(1u, position.index); |
| 61 | EXPECT_STREQ("ID '1[%1]' has not been defined\n %2 = OpSizeOf %1 %3\n", |
| 62 | message); |
| 63 | }); |
| 64 | EXPECT_FALSE(t.Validate(binary)); |
| 65 | |
| 66 | std::string output_text; |
| 67 | EXPECT_TRUE(t.Disassemble(binary, &output_text)); |
| 68 | EXPECT_EQ(input_text, output_text); |
| 69 | } |
| 70 | |
| 71 | TEST(CppInterface, AssembleEmptyModule) { |
| 72 | std::vector<uint32_t> binary(10, 42); |
nothing calls this directly
no test coverage detected