|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Damir Porobic <[email protected]> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | + * Boston, MA 02110-1301, USA. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "PathHelperTest.h" |
| 21 | + |
| 22 | +void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasFormat() |
| 23 | +{ |
| 24 | + auto expected = QStringLiteral("myFile"); |
| 25 | + auto filename = PathHelper::extractFilename(QStringLiteral("/home/kimageannotator/") + expected + QStringLiteral(".png")); |
| 26 | + |
| 27 | + QCOMPARE(filename, expected); |
| 28 | +} |
| 29 | + |
| 30 | +void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameHasNoFormat() |
| 31 | +{ |
| 32 | + auto expected = QStringLiteral("myFile"); |
| 33 | + auto filename = PathHelper::extractFilename(QStringLiteral("/home/kimageannotator/") + expected); |
| 34 | + |
| 35 | + QCOMPARE(filename, expected); |
| 36 | +} |
| 37 | + |
| 38 | +void PathHelperTest::TestExtractFilename_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided() |
| 39 | +{ |
| 40 | + auto expected = QStringLiteral("myFile"); |
| 41 | + auto filename = PathHelper::extractFilename(expected); |
| 42 | + |
| 43 | + QCOMPARE(filename, expected); |
| 44 | +} |
| 45 | + |
| 46 | +void PathHelperTest::TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameHasFormat() |
| 47 | +{ |
| 48 | + auto expected = QStringLiteral("myFile.png"); |
| 49 | + auto filename = PathHelper::extractFilenameWithFormat(QStringLiteral("/home/kimageannotator/") + expected); |
| 50 | + |
| 51 | + QCOMPARE(filename, expected); |
| 52 | +} |
| 53 | + |
| 54 | +void PathHelperTest::TestExtractFilenameWithFormat_Should_ReturnOnlyFilename_When_FilenameWithoutPathWasProvided() |
| 55 | +{ |
| 56 | + auto expected = QStringLiteral("myFile.png"); |
| 57 | + auto filename = PathHelper::extractFilenameWithFormat(expected); |
| 58 | + |
| 59 | + QCOMPARE(filename, expected); |
| 60 | +} |
| 61 | + |
| 62 | +void PathHelperTest::TestPrettyFilename_Should_ReplaceUnderscoresWithSpacesAndCapitalizeFirstLetters() |
| 63 | +{ |
| 64 | + auto input = QStringLiteral("my_test_File.png"); |
| 65 | + auto expected = QStringLiteral("My Test File.png"); |
| 66 | + auto filename = PathHelper::prettyFilename(input); |
| 67 | + |
| 68 | + QCOMPARE(filename, expected); |
| 69 | +} |
| 70 | + |
| 71 | +QTEST_MAIN(PathHelperTest); |
0 commit comments