summaryrefslogtreecommitdiffstats
path: root/mozglue/tests/gtest/TestNativeNtGTest.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /mozglue/tests/gtest/TestNativeNtGTest.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mozglue/tests/gtest/TestNativeNtGTest.cpp')
-rw-r--r--mozglue/tests/gtest/TestNativeNtGTest.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/mozglue/tests/gtest/TestNativeNtGTest.cpp b/mozglue/tests/gtest/TestNativeNtGTest.cpp
new file mode 100644
index 0000000000..cc48f16fdd
--- /dev/null
+++ b/mozglue/tests/gtest/TestNativeNtGTest.cpp
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <windows.h>
+
+#include "gtest/gtest.h"
+
+#include "mozilla/NativeNt.h"
+#include "nsHashKeys.h"
+#include "nsTHashSet.h"
+
+TEST(TestNativeNtGTest, GenerateDependentModuleSet)
+{
+ mozilla::nt::PEHeaders executable(::GetModuleHandleW(nullptr));
+ nsTHashSet<nsStringCaseInsensitiveHashKey> dependentModules;
+ executable.EnumImportChunks([&](const char* aModule) {
+ dependentModules.Insert(
+ mozilla::nt::GetLeafName(NS_ConvertASCIItoUTF16(aModule)));
+ });
+
+ EXPECT_TRUE(dependentModules.Contains(u"mozglue.dll"_ns));
+ EXPECT_TRUE(dependentModules.Contains(u"MOZGLUE.dll"_ns));
+ EXPECT_FALSE(dependentModules.Contains(u"xxx.dll"_ns));
+}
+
+TEST(TestNativeNtGTest, GetLeafName)
+{
+ nsAutoString str;
+ str = mozilla::nt::GetLeafName(u""_ns);
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(u"\\"_ns);
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(u"\\\\"_ns);
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(u"abc\\def\\ghi"_ns);
+ EXPECT_STREQ(str.get(), L"ghi");
+ str = mozilla::nt::GetLeafName(u"abcdef"_ns);
+ EXPECT_STREQ(str.get(), L"abcdef");
+ str = mozilla::nt::GetLeafName(u"\\abcdef"_ns);
+ EXPECT_STREQ(str.get(), L"abcdef");
+
+ const auto kEntireText =
+ u"\\"_ns
+ u"\\\\abc"_ns
+ u"\\x\\y\\z"_ns
+ u"123\\456\\"_ns
+ u"789"_ns;
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 0, 0));
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 0, 1));
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 1, 5));
+ EXPECT_STREQ(str.get(), L"abc");
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 6, 6));
+ EXPECT_STREQ(str.get(), L"z");
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 12, 8));
+ EXPECT_STREQ(str.get(), L"");
+ str = mozilla::nt::GetLeafName(Substring(kEntireText, 20));
+ EXPECT_STREQ(str.get(), L"789");
+}