浏览代码

Add missing test files

Jean-Christophe Fillion-Robin 14 年之前
父节点
当前提交
5fe4351c8b

+ 56 - 0
Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest2.cpp

@@ -0,0 +1,56 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+#include <QSettings>
+
+// CTK includes
+#include "ctkSettingsPanel.h"
+#include "ctkSettingsPanelTest2Helper.h"
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkSettingsPanelTest2(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+  Q_UNUSED(app);
+
+  {
+    // When QSettings goes out of scope, we are the settings file is up-to-date
+    QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Common ToolKit", "CTK");
+    settings.clear();
+    settings.setValue("list", QVariant(QStringList()));
+  }
+
+  // Regression: Reading empty QStringList property from settings should be handled properly
+
+  ctkSettingsPanel settingsPanel;
+  ctkSettingsPanelTest2Helper * list = new ctkSettingsPanelTest2Helper(&settingsPanel);
+  settingsPanel.registerProperty("list", list, "list", SIGNAL(listChanged()));
+  QSettings settings2(QSettings::IniFormat, QSettings::UserScope, "Common ToolKit", "CTK");
+  settingsPanel.setSettings(&settings2);
+
+  return EXIT_SUCCESS;
+}
+

+ 37 - 0
Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest2Helper.cpp

@@ -0,0 +1,37 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#include "ctkSettingsPanelTest2Helper.h"
+
+// --------------------------------------------------------------------------
+QStringList ctkSettingsPanelTest2Helper::list()const
+{
+  return this->List;
+}
+
+// --------------------------------------------------------------------------
+void ctkSettingsPanelTest2Helper::setList(const QStringList& alist)
+{
+  if (alist != this->List)
+    {
+    this->List = alist;
+    emit this->listChanged();
+    }
+}

+ 44 - 0
Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest2Helper.h

@@ -0,0 +1,44 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkSettingsPanelTest2Helper_h
+#define __ctkSettingsPanelTest2Helper_h
+
+#include <QObject>
+#include <QStringList>
+
+// --------------------------------------------------------------------------
+class ctkSettingsPanelTest2Helper : public QObject
+{
+  Q_OBJECT
+  Q_PROPERTY(QStringList list READ list WRITE setList)
+public:
+  ctkSettingsPanelTest2Helper(QObject * parent = 0) : QObject(parent){}
+  QStringList list()const;
+public slots:
+  void setList(const QStringList& alist);
+signals:
+  void listChanged();
+private:
+  QStringList List;
+};
+    
+#endif
+