From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- mozglue/tests/gtest/TestNativeNtGTest.cpp | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 mozglue/tests/gtest/TestNativeNtGTest.cpp (limited to 'mozglue/tests/gtest/TestNativeNtGTest.cpp') 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 + +#include "gtest/gtest.h" + +#include "mozilla/NativeNt.h" +#include "nsHashKeys.h" +#include "nsTHashSet.h" + +TEST(TestNativeNtGTest, GenerateDependentModuleSet) +{ + mozilla::nt::PEHeaders executable(::GetModuleHandleW(nullptr)); + nsTHashSet 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"); +} -- cgit v1.2.3