Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/unittests/heap/cppgc/source-location-unittest.cc')
-rw-r--r--deps/v8/test/unittests/heap/cppgc/source-location-unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/deps/v8/test/unittests/heap/cppgc/source-location-unittest.cc b/deps/v8/test/unittests/heap/cppgc/source-location-unittest.cc
new file mode 100644
index 00000000000..b477dc167d8
--- /dev/null
+++ b/deps/v8/test/unittests/heap/cppgc/source-location-unittest.cc
@@ -0,0 +1,61 @@
+// Copyright 2020 the V8 project 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 "include/cppgc/source-location.h"
+
+#include "src/base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cppgc {
+namespace internal {
+
+namespace {
+constexpr char kFileName[] = "source-location-unittest.cc";
+
+bool Contains(const std::string& base_string, const std::string& substring) {
+ return base_string.find(substring) != std::string::npos;
+}
+
+} // namespace
+
+TEST(SourceLocationTest, DefaultCtor) {
+ constexpr SourceLocation loc;
+ EXPECT_EQ(nullptr, loc.Function());
+ EXPECT_EQ(nullptr, loc.FileName());
+ EXPECT_EQ(0u, loc.Line());
+}
+
+void TestSourceLocationCurrent() {
+ static constexpr char kFunctionName[] = "TestSourceLocationCurrent";
+ static constexpr size_t kNextLine = __LINE__ + 1;
+ constexpr auto loc = SourceLocation::Current();
+#if !CPPGC_SUPPORTS_SOURCE_LOCATION
+ EXPECT_EQ(nullptr, loc.Function());
+ EXPECT_EQ(nullptr, loc.FileName());
+ EXPECT_EQ(0u, loc.Line());
+ USE(kNextLine);
+ return;
+#endif
+ EXPECT_EQ(kNextLine, loc.Line());
+ EXPECT_TRUE(Contains(loc.FileName(), kFileName));
+ EXPECT_TRUE(Contains(loc.Function(), kFunctionName));
+}
+
+TEST(SourceLocationTest, Current) { TestSourceLocationCurrent(); }
+
+void TestToString() {
+ static const std::string kDescriptor = std::string(__func__) + "@" +
+ __FILE__ + ":" +
+ std::to_string(__LINE__ + 1);
+ constexpr auto loc = SourceLocation::Current();
+ const auto string = loc.ToString();
+ EXPECT_EQ(kDescriptor, string);
+}
+
+#if CPPGC_SUPPORTS_SOURCE_LOCATION
+TEST(SourceLocationTest, ToString) { TestToString(); }
+#endif
+
+} // namespace internal
+} // namespace cppgc