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