1 /*
2 * Copyright (C) 2020 Damir Porobic <damir.porobic@gmx.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 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 "PathHelperTests.h"
21
22 #include "src/common/helper/PathHelper.h"
23
IsPathValid_Should_ReturnFalse_When_StringEmpty()24 void PathHelperTests::IsPathValid_Should_ReturnFalse_When_StringEmpty()
25 {
26 auto input = QStringLiteral("");
27 auto result = PathHelper::isPathValid(input);
28
29 QCOMPARE(result, false);
30 }
31
IsPathValid_Should_ReturnFalse_When_StringNull()32 void PathHelperTests::IsPathValid_Should_ReturnFalse_When_StringNull()
33 {
34 auto input = QString();
35 auto result = PathHelper::isPathValid(input);
36
37 QCOMPARE(result, false);
38 }
39
IsPathValid_Should_ReturnTrue_When_StringHasContent()40 void PathHelperTests::IsPathValid_Should_ReturnTrue_When_StringHasContent()
41 {
42 auto input = QStringLiteral("lala");
43 auto result = PathHelper::isPathValid(input);
44
45 QCOMPARE(result, true);
46 }
47
IsPipePath_Should_ReturnTrue_When_PathIsDash()48 void PathHelperTests::IsPipePath_Should_ReturnTrue_When_PathIsDash()
49 {
50 auto input = QStringLiteral("-");
51 auto result = PathHelper::isPipePath(input);
52
53 QCOMPARE(result, true);
54 }
55
IsPipePath_Should_ReturnFalse_When_PathIsNull()56 void PathHelperTests::IsPipePath_Should_ReturnFalse_When_PathIsNull()
57 {
58 auto input = QString();
59 auto result = PathHelper::isPipePath(input);
60
61 QCOMPARE(result, false);
62 }
63
IsPipePath_Should_ReturnFalse_When_PathIsEmpty()64 void PathHelperTests::IsPipePath_Should_ReturnFalse_When_PathIsEmpty()
65 {
66 auto input = QLatin1Literal("");
67 auto result = PathHelper::isPipePath(input);
68
69 QCOMPARE(result, false);
70 }
71
ExtractParentDirectory_Should_ReturnStringWithParentDirectoryPath()72 void PathHelperTests::ExtractParentDirectory_Should_ReturnStringWithParentDirectoryPath()
73 {
74 auto expected = QStringLiteral("/theRoot/theHome/myHome");
75 auto result = PathHelper::extractParentDirectory(expected + QStringLiteral("/theFile.me"));
76
77 QCOMPARE(result, expected);
78 }
79
ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_FormatExists()80 void PathHelperTests::ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_FormatExists()
81 {
82 auto expected = QStringLiteral("theFile");
83 auto result = PathHelper::extractFilename(QStringLiteral("/theRoot/theHome/myHome/") + expected + QStringLiteral(".me"));
84
85 QCOMPARE(result, expected);
86 }
87
ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_NoFormatExists()88 void PathHelperTests::ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_NoFormatExists()
89 {
90 auto expected = QStringLiteral("theFile");
91 auto result = PathHelper::extractFilename(QStringLiteral("/theRoot/theHome/myHome/") + expected);
92
93 QCOMPARE(result, expected);
94 }
95
ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_FormatExists()96 void PathHelperTests::ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_FormatExists()
97 {
98 auto expected = QStringLiteral("theFile.me");
99 auto result = PathHelper::extractFilenameWithFormat(QStringLiteral("/theRoot/theHome/myHome/") + expected);
100
101 QCOMPARE(result, expected);
102 }
103
ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_NoFormatExists()104 void PathHelperTests::ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_NoFormatExists()
105 {
106 auto expected = QStringLiteral("theFile");
107 auto result = PathHelper::extractFilenameWithFormat(QStringLiteral("/theRoot/theHome/myHome/") + expected);
108
109 QCOMPARE(result, expected);
110 }
111
ExtractFormat_Should_ReturnWithFormat_When_FormatExists()112 void PathHelperTests::ExtractFormat_Should_ReturnWithFormat_When_FormatExists()
113 {
114 auto expected = QStringLiteral("me");
115 auto result = PathHelper::extractFormat(QStringLiteral("/theRoot/theHome/myHome/theFile.") + expected);
116
117 QCOMPARE(result, expected);
118 }
119
ExtractFormat_Should_ReturnEmptyString_When_NoFormatExists()120 void PathHelperTests::ExtractFormat_Should_ReturnEmptyString_When_NoFormatExists()
121 {
122 auto result = PathHelper::extractFormat(QStringLiteral("/theRoot/theHome/myHome/theFile"));
123
124 QCOMPARE(result, QStringLiteral(""));
125 }
126
127 QTEST_MAIN(PathHelperTests)
128