1 // Copyright 2021 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/glsl/test_helper.h"
16
17 namespace tint {
18 namespace writer {
19 namespace glsl {
20 namespace {
21
22 using GlslGeneratorImplTest_Bitcast = TestHelper;
23
TEST_F(GlslGeneratorImplTest_Bitcast,EmitExpression_Bitcast_Float)24 TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
25 auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(1));
26 WrapInFunction(bitcast);
27
28 GeneratorImpl& gen = Build();
29
30 std::stringstream out;
31 ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
32 EXPECT_EQ(out.str(), "intBitsToFloat(1)");
33 }
34
TEST_F(GlslGeneratorImplTest_Bitcast,EmitExpression_Bitcast_Int)35 TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
36 auto* bitcast = create<ast::BitcastExpression>(ty.i32(), Expr(1u));
37 WrapInFunction(bitcast);
38
39 GeneratorImpl& gen = Build();
40
41 std::stringstream out;
42 ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
43 EXPECT_EQ(out.str(), "int(1u)");
44 }
45
TEST_F(GlslGeneratorImplTest_Bitcast,EmitExpression_Bitcast_Uint)46 TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
47 auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr(1));
48 WrapInFunction(bitcast);
49
50 GeneratorImpl& gen = Build();
51
52 std::stringstream out;
53 ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
54 EXPECT_EQ(out.str(), "uint(1)");
55 }
56
57 } // namespace
58 } // namespace glsl
59 } // namespace writer
60 } // namespace tint
61