Explorar el Código

Add ctkLanguageComboBoxTest

Julien Finet hace 12 años
padre
commit
b44840fd67

+ 3 - 0
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -117,6 +117,7 @@ if(CTK_USE_QTTESTING)
     ctkExpandButtonEventTranslatorPlayerTest1.cpp
     ctkFileDialogEventTranslatorPlayerTest1.cpp
     ctkFontButtonEventTranslatorPlayerTest1.cpp
+    ctkLanguageComboBoxTest.cpp
     ctkMaterialPropertyWidgetEventTranslatorPlayerTest1.cpp
     ctkMatrixWidgetEventTranslatorPlayerTest1.cpp
     ctkMenuButtonEventTranslatorPlayerTest1.cpp
@@ -177,6 +178,7 @@ QT4_GENERATE_MOCS(
   ctkCoordinatesWidgetTest.cpp
   ctkFlatProxyModelTest.cpp
   ctkFontButtonTest.cpp
+  ctkLanguageComboBoxTest.cpp
   ctkMessageBoxDontShowAgainTest.cpp
   ctkPathListWidgetTest.cpp
   ctkPathListWidgetWithButtonsTest.cpp
@@ -238,6 +240,7 @@ SIMPLE_TEST( ctkFileDialogTest1 )
 SIMPLE_TEST( ctkFittedTextBrowserTest1 )
 SIMPLE_TEST( ctkFlowLayoutTest1 )
 SIMPLE_TEST( ctkFontButtonTest )
+SIMPLE_TEST( ctkLanguageComboBoxTest )
 SIMPLE_TEST( ctkLayoutManagerTest1 )
 SIMPLE_TEST( ctkMaterialPropertyPreviewLabelTest1 )
 SIMPLE_TEST( ctkMaterialPropertyWidgetTest1 )

+ 104 - 0
Libs/Widgets/Testing/Cpp/ctkLanguageComboBoxTest.cpp

@@ -0,0 +1,104 @@
+/*=========================================================================
+
+  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.apache.org/licenses/LICENSE-2.0.txt
+
+  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 <QSignalSpy>
+#include <QTimer>
+#include <QVBoxLayout>
+
+// CTK includes
+#include "ctkLanguageComboBox.h"
+#include "ctkTest.h"
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+// ----------------------------------------------------------------------------
+class ctkLanguageComboBoxTester: public QObject
+{
+  Q_OBJECT
+private slots:
+
+  void testDefaults();
+
+  void testSetDefaultLanguage();
+  void testSetDefaultLanguage_data();
+};
+
+// ----------------------------------------------------------------------------
+void ctkLanguageComboBoxTester::testDefaults()
+{
+  ctkLanguageComboBox languageComboBox;
+  QCOMPARE(languageComboBox.currentLanguage(), languageComboBox.defaultLanguage());
+  QCOMPARE(languageComboBox.defaultLanguage(), QString());
+  QCOMPARE(languageComboBox.directory(), QString());
+}
+
+// ----------------------------------------------------------------------------
+void ctkLanguageComboBoxTester::testSetDefaultLanguage()
+{
+  ctkLanguageComboBox languageComboBox;
+  QFETCH(QString, defaultLanguage);
+  languageComboBox.setDefaultLanguage(defaultLanguage);
+
+  // Default language
+  QFETCH(QString, expectedDefaultLanguage);
+  QCOMPARE(languageComboBox.defaultLanguage(), expectedDefaultLanguage);
+  if (!expectedDefaultLanguage.isEmpty())
+    {
+    QCOMPARE(languageComboBox.count(), 1);
+    QCOMPARE(languageComboBox.itemData(0).toString(), expectedDefaultLanguage);
+    QCOMPARE(languageComboBox.itemText(0),
+             QLocale::languageToString(QLocale(expectedDefaultLanguage).language()));
+    }
+
+  // Current language
+  QFETCH(QString, expectedCurrentLanguage);
+  QCOMPARE(languageComboBox.currentLanguage(), expectedCurrentLanguage);
+  QCOMPARE(languageComboBox.currentIndex(), expectedCurrentLanguage.isEmpty() ? -1 : 0);
+}
+
+// ----------------------------------------------------------------------------
+void ctkLanguageComboBoxTester::testSetDefaultLanguage_data()
+{
+  QTest::addColumn<QString>("defaultLanguage");
+  QTest::addColumn<QString>("expectedDefaultLanguage");
+  QTest::addColumn<QString>("expectedCurrentLanguage");
+
+  QTest::newRow("invalid") << QString() << QString() << QString();
+  QTest::newRow("empty") << QString("") << QString("") << QString("");
+  QTest::newRow("en") << QString("en") << QString("en_US") << QString("en_US");
+  // ISO_3166 says that The United Kingdom is GB not UK
+  QTest::newRow("en_UK") << QString("en_UK") << QString("en_US") << QString("en_US");
+  QTest::newRow("en_GB") << QString("en_GB") << QString("en_GB") << QString("en_GB");
+  QTest::newRow("fr") << QString("fr") << QString("fr_FR") << QString("fr_FR");
+  QTest::newRow("de_CH") << QString("de_CH") << QString("de_CH") << QString("de_CH");
+  QTest::newRow("de_ch") << QString("de_ch") << QString("de_DE") << QString("de_DE");
+  QTest::newRow("xx") << QString("xx") << QString() << QString();
+  QTest::newRow("xx_yy") << QString("xx_yy") << QString() << QString();
+  QTest::newRow("_en") << QString("_en") << QString() << QString();
+  QTest::newRow("fr_") << QString("fr_") << QString("fr_FR") << QString("fr_FR");
+}
+
+// ----------------------------------------------------------------------------
+CTK_TEST_MAIN(ctkLanguageComboBoxTest)
+#include "moc_ctkLanguageComboBoxTest.cpp"