summaryrefslogtreecommitdiffstats
path: root/xpcom
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:40:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:40:09 +0000
commitc1701504b2366542c32c5e6eeff1ba62cc75f8f6 (patch)
tree81b15ef2846efcdbb09422dd283399e769cb7ef9 /xpcom
parentReleasing progress-linux version 115.10.0esr-1~progress7.99u1. (diff)
downloadfirefox-esr-c1701504b2366542c32c5e6eeff1ba62cc75f8f6.tar.xz
firefox-esr-c1701504b2366542c32c5e6eeff1ba62cc75f8f6.zip
Merging upstream version 115.11.0esr.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--xpcom/base/nsINIParser.cpp1
-rw-r--r--xpcom/tests/gtest/TestINIParser.cpp60
-rw-r--r--xpcom/tests/gtest/moz.build1
3 files changed, 61 insertions, 1 deletions
diff --git a/xpcom/base/nsINIParser.cpp b/xpcom/base/nsINIParser.cpp
index c1eec56f10..de1307887f 100644
--- a/xpcom/base/nsINIParser.cpp
+++ b/xpcom/base/nsINIParser.cpp
@@ -242,7 +242,6 @@ nsresult nsINIParser::DeleteString(const char* aSection, const char* aKey) {
mSections.Remove(aSection);
} else {
mSections.InsertOrUpdate(aSection, std::move(val->next));
- delete val;
}
return NS_OK;
}
diff --git a/xpcom/tests/gtest/TestINIParser.cpp b/xpcom/tests/gtest/TestINIParser.cpp
new file mode 100644
index 0000000000..8c156f23dd
--- /dev/null
+++ b/xpcom/tests/gtest/TestINIParser.cpp
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "nsCOMPtr.h"
+#include "gtest/gtest.h"
+#include "mozilla/gtest/MozAssertions.h"
+
+#include "nsINIParser.h"
+
+TEST(INIParser, DeleteString)
+{
+ nsINIParser* parser = new nsINIParser();
+ nsresult rv = parser->InitFromString(
+ "[sec]\r\
+key1=val1\r\
+key2=val2\r\
+key3=val3\r\
+key4=val4"_ns);
+ EXPECT_NS_SUCCEEDED(rv);
+
+ rv = parser->DeleteString("sec", "key3");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteString("sec", "key4");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteString("sec", "key1");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteString("sec", "key2");
+ EXPECT_NS_SUCCEEDED(rv);
+
+ delete parser;
+}
+
+TEST(INIParser, DeleteSection)
+{
+ nsINIParser* parser = new nsINIParser();
+ nsresult rv = parser->InitFromString(
+ "[sec1]\r\
+key=val\r\
+\r\
+[sec2]\r\
+key=val\r\
+[sec3]\r\
+key=val\r\
+[sec4]\r\
+key=val"_ns);
+ EXPECT_NS_SUCCEEDED(rv);
+
+ rv = parser->DeleteSection("sec3");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteSection("sec4");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteSection("sec1");
+ EXPECT_NS_SUCCEEDED(rv);
+ rv = parser->DeleteSection("sec2");
+ EXPECT_NS_SUCCEEDED(rv);
+
+ delete parser;
+}
diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build
index 3347c56ba5..af33d34f38 100644
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -25,6 +25,7 @@ UNIFIED_SOURCES += [
"TestGCPostBarriers.cpp",
"TestID.cpp",
"TestIDUtils.cpp",
+ "TestINIParser.cpp",
"TestInputStreamLengthHelper.cpp",
"TestJSHolderMap.cpp",
"TestLogCommandLineHandler.cpp",