[M108 Migration][VD] Support set time and time zone offset
[platform/framework/web/chromium-efl.git] / base / location_unittest.cc
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/location.h"
6
7 #include "base/debug/debugging_buildflags.h"
8 #include "base/trace_event/base_tracing.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 #if BUILDFLAG(ENABLE_BASE_TRACING)
13 #include "third_party/perfetto/include/perfetto/test/traced_value_test_support.h"  // no-presubmit-check
14 #endif  // BUILDFLAG(ENABLE_BASE_TRACING)
15
16 namespace base {
17
18 namespace {
19
20 // This is a typical use: taking Location::Current as a default parameter.
21 // So even though this looks contrived, it confirms that such usage works as
22 // expected.
23 Location WhereAmI(const Location& location = Location::Current()) {
24   return location;
25 }
26
27 }  // namespace
28
29 TEST(LocationTest, CurrentYieldsCorrectValue) {
30   [[maybe_unused]] int previous_line = __LINE__;
31   Location here = WhereAmI();
32   EXPECT_NE(here.program_counter(), WhereAmI().program_counter());
33 #if SUPPORTS_LOCATION_BUILTINS
34   EXPECT_THAT(here.file_name(), ::testing::EndsWith("location_unittest.cc"));
35 #if BUILDFLAG(ENABLE_LOCATION_SOURCE)
36   EXPECT_EQ(here.line_number(), previous_line + 1);
37   EXPECT_STREQ("TestBody", here.function_name());
38 #endif
39 #elif defined(OFFICIAL_BUILD)
40 #error Location builtins must be supported in official builds.
41 #elif BUILDFLAG(FROM_HERE_USES_LOCATION_BUILTINS)
42 #error FROM_HERE requires location builtins to be supported.
43 #endif
44 }
45
46 #if BUILDFLAG(ENABLE_BASE_TRACING)
47 TEST(LocationTest, TracingSupport) {
48   EXPECT_EQ(perfetto::TracedValueToString(
49                 Location("func", "file", 42, WhereAmI().program_counter())),
50             "{function_name:func,file_name:file,line_number:42}");
51 }
52 #endif  // BUILDFLAG(ENABLE_BASE_TRACING)
53
54 }  // namespace base