• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
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 "src/writer/spirv/instruction.h"
16 
17 #include "gtest/gtest.h"
18 
19 namespace tint {
20 namespace writer {
21 namespace spirv {
22 namespace {
23 
24 using InstructionTest = testing::Test;
25 
TEST_F(InstructionTest,Create)26 TEST_F(InstructionTest, Create) {
27   Instruction i(spv::Op::OpEntryPoint, {Operand::Float(1.2f), Operand::Int(1),
28                                         Operand::String("my_str")});
29   EXPECT_EQ(i.opcode(), spv::Op::OpEntryPoint);
30   ASSERT_EQ(i.operands().size(), 3u);
31 
32   const auto& ops = i.operands();
33   EXPECT_TRUE(ops[0].IsFloat());
34   EXPECT_FLOAT_EQ(ops[0].to_f(), 1.2f);
35 
36   EXPECT_TRUE(ops[1].IsInt());
37   EXPECT_EQ(ops[1].to_i(), 1u);
38 
39   EXPECT_TRUE(ops[2].IsString());
40   EXPECT_EQ(ops[2].to_s(), "my_str");
41 }
42 
TEST_F(InstructionTest,Length)43 TEST_F(InstructionTest, Length) {
44   Instruction i(spv::Op::OpEntryPoint, {Operand::Float(1.2f), Operand::Int(1),
45                                         Operand::String("my_str")});
46   EXPECT_EQ(i.word_length(), 5u);
47 }
48 
49 }  // namespace
50 }  // namespace spirv
51 }  // namespace writer
52 }  // namespace tint
53