aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/corelib/jsextensions/propertylist.h2
-rw-r--r--src/lib/corelib/jsextensions/propertylist.mm16
-rw-r--r--tests/auto/blackbox/testdata/jsextensions/propertylist.qbs26
3 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/corelib/jsextensions/propertylist.h b/src/lib/corelib/jsextensions/propertylist.h
index 1b211af99..69a8696dd 100644
--- a/src/lib/corelib/jsextensions/propertylist.h
+++ b/src/lib/corelib/jsextensions/propertylist.h
@@ -50,6 +50,8 @@ public:
static QScriptValue ctor(QScriptContext *context, QScriptEngine *engine);
PropertyList(QScriptContext *context);
~PropertyList();
+ Q_INVOKABLE bool isEmpty() const;
+ Q_INVOKABLE void clear();
Q_INVOKABLE void readFromString(const QString &input);
Q_INVOKABLE void readFromFile(const QString &filePath);
Q_INVOKABLE void writeToFile(const QString &filePath, const QString &plistFormat);
diff --git a/src/lib/corelib/jsextensions/propertylist.mm b/src/lib/corelib/jsextensions/propertylist.mm
index ac0323e2c..4c35a3911 100644
--- a/src/lib/corelib/jsextensions/propertylist.mm
+++ b/src/lib/corelib/jsextensions/propertylist.mm
@@ -109,6 +109,22 @@ PropertyList::PropertyList(QScriptContext *context)
Q_ASSERT(thisObject().engine() == engine());
}
+bool PropertyList::isEmpty() const
+{
+ Q_ASSERT(thisObject().engine() == engine());
+ PropertyList *p = qscriptvalue_cast<PropertyList*>(thisObject());
+ return !p->d->propertyListObject;
+}
+
+void PropertyList::clear()
+{
+ Q_ASSERT(thisObject().engine() == engine());
+ PropertyList *p = qscriptvalue_cast<PropertyList*>(thisObject());
+ [p->d->propertyListObject release];
+ p->d->propertyListObject = nil;
+ p->d->propertyListFormat = 0;
+}
+
void PropertyList::readFromString(const QString &input)
{
Q_ASSERT(thisObject().engine() == engine());
diff --git a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs b/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs
index cdd1c1af3..5b80eeafb 100644
--- a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs
+++ b/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs
@@ -5,6 +5,32 @@ import qbs.TextFile
Product {
type: {
+ var plistobj = new PropertyList();
+ if (!plistobj.isEmpty()) {
+ throw "newly created PropertyList was not empty!";
+ }
+
+ if (plistobj.format() !== undefined) {
+ throw "newly created PropertyList did not have an undefined format";
+ }
+
+ plistobj.clear();
+
+ if (!plistobj.isEmpty() || plistobj.format() !== undefined) {
+ throw "clear() somehow had an effect on an empty PropertyList";
+ }
+
+ plistobj.readFromString('{"key":["value"]}');
+ if (plistobj.isEmpty() || plistobj.format() !== "json") {
+ throw "readFromString did not set format to JSON or object thinks it is empty";
+ }
+
+ plistobj.clear();
+
+ if (!plistobj.isEmpty() || plistobj.format() !== undefined) {
+ throw "clear() had no effect on a non-empty PropertyList";
+ }
+
var obj = {
"Array": ["ListItem1", "ListItem2", "ListItem3"],
"Integer": 1,