fixup! [M120 Migration] Notify media device state to webbrowser
[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/trace_event/base_tracing.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 #if BUILDFLAG(ENABLE_BASE_TRACING)
12 #include "third_party/perfetto/include/perfetto/test/traced_value_test_support.h"  // no-presubmit-check
13 #endif  // BUILDFLAG(ENABLE_BASE_TRACING)
14
15 namespace base {
16
17 namespace {
18
19 // This is a typical use: taking Location::Current as a default parameter.
20 // So even though this looks contrived, it confirms that such usage works as
21 // expected.
22 Location WhereAmI(const Location& location = Location::Current()) {
23   return location;
24 }
25
26 }  // namespace
27
28 TEST(LocationTest, CurrentYieldsCorrectValue) {
29   [[maybe_unused]] int previous_line = __LINE__;
30   Location here = WhereAmI();
31   EXPECT_NE(here.program_counter(), WhereAmI().program_counter());
32   EXPECT_THAT(here.file_name(), ::testing::EndsWith("location_unittest.cc"));
33   EXPECT_EQ(here.line_number(), previous_line + 1);
34   EXPECT_STREQ("TestBody", here.function_name());
35 }
36
37 #if BUILDFLAG(ENABLE_BASE_TRACING)
38 TEST(LocationTest, TracingSupport) {
39   EXPECT_EQ(perfetto::TracedValueToString(Location::CreateForTesting(
40                 "func", "file", 42, WhereAmI().program_counter())),
41             "{function_name:func,file_name:file,line_number:42}");
42 }
43 #endif  // BUILDFLAG(ENABLE_BASE_TRACING)
44
45 }  // namespace base