1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/location.h"
7 #include "base/compiler_specific.h"
8 #include "base/debug/debugging_buildflags.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
16 // This is a typical use: taking Location::Current as a default parameter.
17 // So even though this looks contrived, it confirms that such usage works as
19 Location WhereAmI(const Location& location = Location::Current()) {
25 TEST(LocationTest, CurrentYieldsCorrectValue) {
26 int previous_line = __LINE__;
27 Location here = WhereAmI();
28 EXPECT_NE(here.program_counter(), WhereAmI().program_counter());
29 #if SUPPORTS_LOCATION_BUILTINS
30 EXPECT_THAT(here.file_name(), ::testing::EndsWith("location_unittest.cc"));
31 #if BUILDFLAG(ENABLE_LOCATION_SOURCE)
32 EXPECT_EQ(here.line_number(), previous_line + 1);
33 EXPECT_STREQ("TestBody", here.function_name());
35 #elif defined(OFFICIAL_BUILD)
36 #error Location builtins must be supported in official builds.
37 #elif BUILDFLAG(FROM_HERE_USES_LOCATION_BUILTINS)
38 #error FROM_HERE requires location builtins to be supported.
40 ALLOW_UNUSED_LOCAL(previous_line);