2020-07-30 22:27:25 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-04-28 18:49:04 +00:00
|
|
|
#include "src/tint/sem/sampler.h"
|
2022-02-21 15:19:07 +00:00
|
|
|
#include "src/tint/sem/test_helper.h"
|
2022-04-28 18:49:04 +00:00
|
|
|
#include "src/tint/sem/texture.h"
|
2020-07-30 22:27:25 +00:00
|
|
|
|
2022-04-07 16:04:35 +00:00
|
|
|
namespace tint::sem {
|
2020-07-30 22:27:25 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
using SamplerTest = TestHelper;
|
2020-07-30 22:27:25 +00:00
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
TEST_F(SamplerTest, Creation) {
|
2022-05-01 14:40:55 +00:00
|
|
|
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
|
2020-07-30 22:27:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_EQ(a->kind(), ast::SamplerKind::kSampler);
|
|
|
|
EXPECT_EQ(c->kind(), ast::SamplerKind::kComparisonSampler);
|
2022-03-07 18:34:57 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_FALSE(a->IsComparison());
|
|
|
|
EXPECT_TRUE(c->IsComparison());
|
2022-03-07 18:34:57 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_EQ(a, b);
|
|
|
|
EXPECT_NE(a, c);
|
2020-07-30 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 18:34:57 +00:00
|
|
|
TEST_F(SamplerTest, Hash) {
|
2022-05-01 14:40:55 +00:00
|
|
|
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
|
2022-03-07 18:34:57 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_EQ(a->Hash(), b->Hash());
|
|
|
|
EXPECT_NE(a->Hash(), c->Hash());
|
2020-07-30 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 18:34:57 +00:00
|
|
|
TEST_F(SamplerTest, Equals) {
|
2022-05-01 14:40:55 +00:00
|
|
|
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* b = create<Sampler>(ast::SamplerKind::kSampler);
|
|
|
|
auto* c = create<Sampler>(ast::SamplerKind::kComparisonSampler);
|
2022-03-07 18:34:57 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_TRUE(a->Equals(*b));
|
|
|
|
EXPECT_FALSE(a->Equals(*c));
|
|
|
|
EXPECT_FALSE(a->Equals(Void{}));
|
2020-07-30 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 18:52:34 +00:00
|
|
|
TEST_F(SamplerTest, FriendlyNameSampler) {
|
2022-05-01 14:40:55 +00:00
|
|
|
Sampler s{ast::SamplerKind::kSampler};
|
|
|
|
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler");
|
2021-02-09 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SamplerTest, FriendlyNameComparisonSampler) {
|
2022-05-01 14:40:55 +00:00
|
|
|
Sampler s{ast::SamplerKind::kComparisonSampler};
|
|
|
|
EXPECT_EQ(s.FriendlyName(Symbols()), "sampler_comparison");
|
2021-02-09 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 22:27:25 +00:00
|
|
|
} // namespace
|
2022-04-07 16:04:35 +00:00
|
|
|
} // namespace tint::sem
|