blob: a7e25b3998352d7232fcf2eaf252e82c2c2b82b2 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include <lib/stdcompat/source_location.h>
#include "gtest.h"
namespace {
std::tuple<cpp20::source_location, uint32_t, uint32_t> FooBar() {
// clang-format off
uint32_t line = __LINE__ + 1;
auto source_location = cpp20::source_location::current();
uint32_t column = 26;
// clang-format on
return {source_location, line, column};
}
cpp20::source_location ExampleLoggingFunction(
cpp20::source_location location = cpp20::source_location::current()) {
return location;
}
std::tuple<cpp20::source_location, uint32_t, uint32_t> BizBaz() {
// clang-format off
uint32_t line = __LINE__ + 1;
auto source_location = ExampleLoggingFunction();
uint32_t column = 26;
// clang-format on
return {source_location, line, column};
}
TEST(SourceLocationTest, DirectCallValue) {
auto [location, line, column] = FooBar();
EXPECT_EQ(location.file_name(), __FILE__);
EXPECT_THAT(location.function_name(), testing::HasSubstr("FooBar"));
EXPECT_EQ(location.line(), line);
EXPECT_EQ(location.column(), column);
}
TEST(SourceLocationTest, DefaultParameterValue) {
auto [location, line, column] = BizBaz();
EXPECT_EQ(location.file_name(), __FILE__);
EXPECT_THAT(location.function_name(), testing::HasSubstr("BizBaz"));
EXPECT_EQ(location.line(), line);
EXPECT_EQ(location.column(), column);
}
#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && \
!defined(LIB_STDCOMPAT_USE_POLYFILLS)
TEST(SourceLocationTest, IsAliasOfStdInStd20) {
static_assert(std::is_same_v<cpp20::source_location, std::source_location>);
}
#endif // __cpp_lib_source_location >= 201907L && !defined(LIB_STDCOMPAT_USE_POLYFILLS)
} // namespace