|
@@ -1,118 +0,0 @@
|
|
-# HG changeset patch
|
|
|
|
-# User Dave Townsend <dtownsend@oxymoronical.com>
|
|
|
|
-# Date 1714766716 0
|
|
|
|
-# Node ID 30f2b471b2f08adf4835ce240a52e1fdb0c2fffc
|
|
|
|
-# Parent c78612e6df17a627ab6d4b02e06e8c696a3afebb
|
|
|
|
-Bug 1893340: Test nsINIParser for string and section deletion a=dmeehan
|
|
|
|
-
|
|
|
|
-Original Revision: https://phabricator.services.mozilla.com/D208981
|
|
|
|
-
|
|
|
|
-Differential Revision: https://phabricator.services.mozilla.com/D209332
|
|
|
|
-
|
|
|
|
-diff --git a/xpcom/base/nsINIParser.cpp b/xpcom/base/nsINIParser.cpp
|
|
|
|
---- a/xpcom/base/nsINIParser.cpp
|
|
|
|
-+++ b/xpcom/base/nsINIParser.cpp
|
|
|
|
-@@ -260,17 +260,16 @@ nsINIParser::DeleteString(const char* aS
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Special case the first result
|
|
|
|
- if (strcmp(val->key, aKey) == 0) {
|
|
|
|
- if (!val->next) {
|
|
|
|
- mSections.Remove(aSection);
|
|
|
|
- } else {
|
|
|
|
- mSections.Put(aSection, val->next.release());
|
|
|
|
-- delete val;
|
|
|
|
- }
|
|
|
|
- return NS_OK;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- while (val->next) {
|
|
|
|
- if (strcmp(val->next->key, aKey) == 0) {
|
|
|
|
- val->next = std::move(val->next->next);
|
|
|
|
-
|
|
|
|
-diff --git a/xpcom/tests/gtest/TestINIParser.cpp b/xpcom/tests/gtest/TestINIParser.cpp
|
|
|
|
-new file mode 100644
|
|
|
|
---- /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
|
|
|
|
---- a/xpcom/tests/gtest/moz.build
|
|
|
|
-+++ b/xpcom/tests/gtest/moz.build
|
|
|
|
-@@ -20,16 +20,17 @@ UNIFIED_SOURCES += [
|
|
|
|
- 'TestEncoding.cpp',
|
|
|
|
- 'TestEscape.cpp',
|
|
|
|
- 'TestEventPriorities.cpp',
|
|
|
|
- 'TestEventTargetQI.cpp',
|
|
|
|
- 'TestExpirationTracker.cpp',
|
|
|
|
- 'TestFile.cpp',
|
|
|
|
- 'TestGCPostBarriers.cpp',
|
|
|
|
- 'TestID.cpp',
|
|
|
|
-+ "TestINIParser.cpp",
|
|
|
|
- 'TestMoveString.cpp',
|
|
|
|
- 'TestMozPromise.cpp',
|
|
|
|
- 'TestMultiplexInputStream.cpp',
|
|
|
|
- 'TestNsDeque.cpp',
|
|
|
|
- 'TestNSPRLogModulesParser.cpp',
|
|
|
|
- 'TestObserverArray.cpp',
|
|
|
|
- 'TestObserverService.cpp',
|
|
|
|
- 'TestPipes.cpp',
|
|
|