| 1 |
// Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#include "test/test_fixture.h" |
| 16 |
|
| 17 |
namespace svptools { |
| 18 |
namespace { |
| 19 |
|
| 20 |
using spvtest::ScopedContext; |
| 21 |
using spvtest::TextToBinaryTest; |
| 22 |
|
| 23 |
TEST_F(TextToBinaryTest, InstOpcodeProducesResultIDButNoIDDefinedFails) { |
| 24 |
SetText("OpTypeMatrix %1 %2 1000"); |
| 25 |
EXPECT_EQ(SPV_ERROR_INVALID_TEXT, |
| 26 |
spvTextToBinary(ScopedContext().context, text.str, text.length, |
| 27 |
&binary, &diagnostic)); |
| 28 |
ASSERT_NE(nullptr, diagnostic); |
| 29 |
EXPECT_STREQ( |
| 30 |
"Expected <result-id> at the beginning of an instruction, found " |
| 31 |
"'OpTypeMatrix'.", |
| 32 |
diagnostic->error); |
| 33 |
EXPECT_EQ(0u, diagnostic->position.line); |
| 34 |
} |
| 35 |
|
| 36 |
TEST_F(TextToBinaryTest, |
| 37 |
InstDefinesResultIDButOpcodeDoesNotProduceAResultFails) { |
| 38 |
SetText("\n\n%foo = OpName %1 \"bar\""); |
| 39 |
EXPECT_EQ(SPV_ERROR_INVALID_TEXT, |
| 40 |
spvTextToBinary(ScopedContext().context, text.str, text.length, |
| 41 |
&binary, &diagnostic)); |
| 42 |
ASSERT_NE(nullptr, diagnostic); |
| 43 |
EXPECT_STREQ( |
| 44 |
"Cannot set ID %foo because OpName does not produce a result ID.", |
| 45 |
diagnostic->error); |
| 46 |
EXPECT_EQ(2u, diagnostic->position.line); |
| 47 |
} |
| 48 |
|
| 49 |
} // namespace |
| 50 |
} // namespace svptools |