File indexing completed on 2025-01-05 03:58:01
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-08-01 0007 * Description : a test for the CameraNameHelper 0008 * 0009 * SPDX-FileCopyrightText: 2009 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "cameranamehelper_utest.h" 0016 0017 // Qt includes 0018 0019 #include <QTest> 0020 0021 // Local includes 0022 0023 #include "cameranamehelper.h" 0024 #include "digikam_config.h" 0025 #include "digikam_debug.h" 0026 0027 using namespace Digikam; 0028 0029 QTEST_GUILESS_MAIN(CameraNameHelperTest) 0030 0031 void CameraNameHelperTest::testCreateCameraName_data() 0032 { 0033 QTest::addColumn<QString>("vendor"); 0034 QTest::addColumn<QString>("product"); 0035 QTest::addColumn<QString>("mode"); 0036 QTest::addColumn<bool>("autoDetect"); 0037 QTest::addColumn<QString>("result"); 0038 0039 QString autoString = QLatin1String("auto-detected"); 0040 0041 QTest::newRow("01") << "Nikon" 0042 << "D50" 0043 << "PTP Mode" 0044 << true 0045 << QString::fromUtf8("Nikon D50 (PTP Mode, %1)").arg(autoString); 0046 0047 QTest::newRow("02") << " Canon " 0048 << "Powershot A80" 0049 << "" 0050 << false 0051 << QString::fromUtf8("Canon Powershot A80"); 0052 0053 QTest::newRow("03") << " Canon " 0054 << "Powershot A80" 0055 << "" 0056 << true 0057 << QString::fromUtf8("Canon Powershot A80 (%1)").arg(autoString); 0058 0059 QTest::newRow("04") << " Canon " 0060 << "" 0061 << "PTP" 0062 << true 0063 << QString::fromUtf8("Canon (PTP, auto-detected)"); 0064 0065 QTest::newRow("05") << "" 0066 << "D50" 0067 << "PTP Mode" 0068 << true 0069 << QString::fromUtf8(""); 0070 0071 QTest::newRow("06") << "Nikon" 0072 << "D50" 0073 << "(PTP Mode)" 0074 << true 0075 << QString::fromUtf8("Nikon D50 (PTP Mode, %1)").arg(autoString); 0076 } 0077 0078 void CameraNameHelperTest::testCreateCameraName() 0079 { 0080 QFETCH(QString, vendor); 0081 QFETCH(QString, product); 0082 QFETCH(QString, mode); 0083 QFETCH(bool, autoDetect); 0084 QFETCH(QString, result); 0085 0086 QCOMPARE(CameraNameHelper::createCameraName(vendor, product, mode, autoDetect), result); 0087 } 0088 0089 void CameraNameHelperTest::testSameDevices_data() 0090 { 0091 QTest::addColumn<QString>("deviceA"); 0092 QTest::addColumn<QString>("deviceB"); 0093 QTest::addColumn<bool>("result"); 0094 0095 QTest::newRow("01") << "Nikon D50 (ptp, auto-detected)" << "Nikon D50 (PTP Mode)" << true; 0096 QTest::newRow("02") << "Nikon D50 (ptp mode)" << "Nikon D50 (PTP)" << true; 0097 QTest::newRow("03") << "Nikon D50 (auto-detected)" << "Nikon D50" << true; 0098 QTest::newRow("04") << "Nikon D50 (ptp mode)" << "Nikon D50 (mtp mode)" << false; 0099 QTest::newRow("05") << "Nikon D50 (ptp mode)" << "Nikon D50" << false; 0100 } 0101 0102 void CameraNameHelperTest::testCameraName_data() 0103 { 0104 QTest::addColumn<QString>("device"); 0105 QTest::addColumn<QString>("result"); 0106 0107 QTest::newRow("01") << "Nikon D50 (ptp, auto-detected)" << "Nikon D50"; 0108 QTest::newRow("02") << "Nikon D50 (auto-detected)" << "Nikon D50"; 0109 QTest::newRow("03") << "Nikon D50 (ptp)" << "Nikon D50"; 0110 QTest::newRow("04") << "Nikon D50 (something else)" << "Nikon D50 (something else)"; 0111 QTest::newRow("05") << "Nikon D50 (huhu) blubber" << "Nikon D50 (huhu) blubber"; 0112 } 0113 0114 void CameraNameHelperTest::testCameraName() 0115 { 0116 QFETCH(QString, device); 0117 QFETCH(QString, result); 0118 0119 QCOMPARE(CameraNameHelper::cameraName(device), result); 0120 } 0121 0122 void CameraNameHelperTest::testCameraNameAutoDetected_data() 0123 { 0124 QTest::addColumn<QString>("device"); 0125 QTest::addColumn<QString>("result"); 0126 0127 QTest::newRow("01") << "Nikon D50 (ptp, auto-detected)" << "Nikon D50 (ptp, auto-detected)"; 0128 QTest::newRow("02") << "Nikon D50 (auto-detected)" << "Nikon D50 (auto-detected)"; 0129 QTest::newRow("03") << "Nikon D50 (ptp)" << "Nikon D50 (ptp, auto-detected)"; 0130 QTest::newRow("04") << "Nikon D50 (something else)" << "Nikon D50 (something else) (auto-detected)"; 0131 QTest::newRow("05") << "Nikon D50 (huhu) blubber" << "Nikon D50 (huhu) blubber (auto-detected)"; 0132 } 0133 0134 void CameraNameHelperTest::testCameraNameAutoDetected() 0135 { 0136 QFETCH(QString, device); 0137 QFETCH(QString, result); 0138 0139 QCOMPARE(CameraNameHelper::cameraNameAutoDetected(device), result); 0140 } 0141 0142 void CameraNameHelperTest::testSameDevices() 0143 { 0144 QFETCH(QString, deviceA); 0145 QFETCH(QString, deviceB); 0146 QFETCH(bool, result); 0147 0148 QCOMPARE(CameraNameHelper::sameDevices(deviceA, deviceB), result); 0149 } 0150 0151 #include "moc_cameranamehelper_utest.cpp"