Debian Codegraph @

tests/common/helper/PathHelperTests.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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 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
24 #include "tests/utils/TestRunner.h"
25
26 void PathHelperTests::IsPathValid_Should_ReturnFalse_When_StringEmpty()
27 {
28 // arrange
29 auto input = QStringLiteral("");
30
31 // act
32 auto result = PathHelper::isPathValid(input);
33
34 // assert
35 QCOMPARE(result, false);
36 }
37
38 void PathHelperTests::IsPathValid_Should_ReturnFalse_When_StringNull()
39 {
40 // arrange
41 auto input = QString();
42
43 // act
44 auto result = PathHelper::isPathValid(input);
45
46 // assert
47 QCOMPARE(result, false);
48 }
49
50 void PathHelperTests::IsPathValid_Should_ReturnTrue_When_StringHasContent()
51 {
52 // arrange
53 auto input = QStringLiteral("lala");
54
55 // act
56 auto result = PathHelper::isPathValid(input);
57
58 // assert
59 QCOMPARE(result, true);
60 }
61
62 void PathHelperTests::IsPipePath_Should_ReturnTrue_When_PathIsDash()
63 {
64 // arrange
65 auto input = QStringLiteral("-");
66
67 // act
68 auto result = PathHelper::isPipePath(input);
69
70 // assert
71 QCOMPARE(result, true);
72 }
73
74 void PathHelperTests::IsPipePath_Should_ReturnFalse_When_PathIsNull()
75 {
76 // arrange
77 auto input = QString();
78
79 // act
80 auto result = PathHelper::isPipePath(input);
81
82 // assert
83 QCOMPARE(result, false);
84 }
85
86 void PathHelperTests::IsPipePath_Should_ReturnFalse_When_PathIsEmpty()
87 {
88 // arrange
89 auto input = QStringLiteral("");
90
91 // act
92 auto result = PathHelper::isPipePath(input);
93
94 // assert
95 QCOMPARE(result, false);
96 }
97
98 void PathHelperTests::ExtractParentDirectory_Should_ReturnStringWithParentDirectoryPath()
99 {
100 // arrange
101 auto expected = QStringLiteral("/theRoot/theHome/myHome");
102
103 // act
104 auto result = PathHelper::extractParentDirectory(expected + QStringLiteral("/theFile.me"));
105
106 // assert
107 QCOMPARE(result, expected);
108 }
109
110 void PathHelperTests::ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_FormatExists()
111 {
112 // arrange
113 auto expected = QStringLiteral("theFile");
114
115 // act
116 auto result = PathHelper::extractFilename(QStringLiteral("/theRoot/theHome/myHome/") + expected + QStringLiteral(".me"));
117
118 // assert
119 QCOMPARE(result, expected);
120 }
121
122 void PathHelperTests::ExtractFilename_Should_ReturnStringWithFilenameWithoutFormat_When_NoFormatExists()
123 {
124 // arrange
125 auto expected = QStringLiteral("theFile");
126
127 // act
128 auto result = PathHelper::extractFilename(QStringLiteral("/theRoot/theHome/myHome/") + expected);
129
130 // assert
131 QCOMPARE(result, expected);
132 }
133
134 void PathHelperTests::ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_FormatExists()
135 {
136 // arrange
137 auto expected = QStringLiteral("theFile.me");
138
139 // act
140 auto result = PathHelper::extractFilenameWithFormat(QStringLiteral("/theRoot/theHome/myHome/") + expected);
141
142 // assert
143 QCOMPARE(result, expected);
144 }
145
146 void PathHelperTests::ExtractFilenameWithFormat_Should_ReturnStringWithFilenameWithFormat_When_NoFormatExists()
147 {
148 // arrange
149 auto expected = QStringLiteral("theFile");
150
151 // act
152 auto result = PathHelper::extractFilenameWithFormat(QStringLiteral("/theRoot/theHome/myHome/") + expected);
153
154 // assert
155 QCOMPARE(result, expected);
156 }
157
158 void PathHelperTests::ExtractFormat_Should_ReturnWithFormat_When_FormatExists()
159 {
160 // arrange
161 auto expected = QStringLiteral("me");
162
163 // act
164 auto result = PathHelper::extractFormat(QStringLiteral("/theRoot/theHome/myHome/theFile.") + expected);
165
166 // assert
167 QCOMPARE(result, expected);
168 }
169
170 void PathHelperTests::ExtractFormat_Should_ReturnEmptyString_When_NoFormatExists()
171 {
172 // arrange
173 auto path = QStringLiteral("/theRoot/theHome/myHome/theFile");
174
175 // act
176 auto result = PathHelper::extractFormat(path);
177
178 // assert
179 QCOMPARE(result, QStringLiteral(""));
180 }
181
182 TEST_MAIN(PathHelperTests)