@@ -36,6 +36,62 @@ TEST_TEAR_DOWN(TestFileUtils) {
3636 }
3737}
3838
39+ //==============================
40+ // IsPathNormalized(...)
41+ //==============================
42+
43+ TEST (TestFileUtils , test_IsPathNormalized_ReturnsFalseIfPathIsNull ) {
44+ TEST_ASSERT_FALSE (IsPathNormalized (NULL ));
45+ }
46+
47+ TEST (TestFileUtils , test_IsPathNormalized_ReturnsTrueIfPathIsEmpty ) {
48+ TEST_ASSERT_TRUE (IsPathNormalized ("" ));
49+ }
50+
51+ TEST (TestFileUtils , test_IsPathNormalized_ReturnsFalseIfPathIsNotNormalized ) {
52+ TEST_ASSERT_FALSE (IsPathNormalized ("a\\b/c\\d" ));
53+ }
54+
55+ TEST (TestFileUtils , test_IsPathNormalized_ReturnsTrueIfPathIsNormalized ) {
56+ TEST_ASSERT_TRUE (IsPathNormalized ("a/b/c/d" ));
57+ }
58+
59+ //==============================
60+ // NormailizePathSeparatorsInPlace(...)
61+ //==============================
62+
63+ TEST (TestFileUtils ,
64+ test_NormailizePathSeparatorsInPlace_ReturnsFalseIfPathIsNull ) {
65+ TEST_ASSERT_NULL (NormailizePathSeparatorsInPlace (NULL ));
66+ }
67+
68+ TEST (TestFileUtils ,
69+ test_NormailizePathSeparatorsInPlace_NormalizesPathSeparators ) {
70+ RAII_STRING path = RaiiStringCreateFromCString ("a\\b/c\\d" );
71+
72+ char * pNormalizedPath = NormailizePathSeparatorsInPlace (path .pString );
73+ TEST_ASSERT_EQUAL (pNormalizedPath , path .pString );
74+ TEST_ASSERT_EQUAL_STRING ("a/b/c/d" , path .pString );
75+ }
76+
77+ TEST (TestFileUtils ,
78+ test_NormailizePathSeparatorsInPlace_DoesNotChangeAlreadyNormalized ) {
79+ RAII_STRING path = RaiiStringCreateFromCString ("a/b/c/d" );
80+
81+ char * pNormalizedPath = NormailizePathSeparatorsInPlace (path .pString );
82+ TEST_ASSERT_EQUAL (pNormalizedPath , path .pString );
83+ TEST_ASSERT_EQUAL_STRING ("a/b/c/d" , path .pString );
84+ }
85+
86+ TEST (TestFileUtils ,
87+ test_NormailizePathSeparatorsInPlace_NormalizesWithWindowsStylePrefix ) {
88+ RAII_STRING path = RaiiStringCreateFromCString ("C:\\a\\b\\" );
89+
90+ char * pNormalizedPath = NormailizePathSeparatorsInPlace (path .pString );
91+ TEST_ASSERT_EQUAL (pNormalizedPath , path .pString );
92+ TEST_ASSERT_EQUAL_STRING ("C:/a/b/" , path .pString );
93+ }
94+
3995//==============================
4096// IsAbsolutePath(...)
4197//==============================
@@ -213,39 +269,21 @@ TEST(TestFileUtils,
213269 TEST_ASSERT_TRUE (success );
214270}
215271
216- TEST (
217- TestFileUtils ,
218- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_TrailingSlash_WindowsStyle ) {
219- char localBuffer [MAX_PATH_LENGTH_WTH_TERMINATOR ];
220- char * pPath = "C:\\a\\b\\" ;
221-
222- bool success =
223- GetAbsolutePath (pPath , localBuffer , MAX_PATH_LENGTH_WTH_TERMINATOR );
224-
225- TEST_ASSERT_TRUE (success );
226- TEST_ASSERT_NOT_EQUAL (pPath , & localBuffer [0 ]);
227- TEST_ASSERT_EQUAL_STRING (pPath , localBuffer );
228- }
229-
230- TEST (
231- TestFileUtils ,
232- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_NoTrailingSlash_WindowsStyle ) {
272+ TEST (TestFileUtils , test_GetAbsolutePath_ReturnsFalseIfIfIsNotNormalized ) {
233273 char localBuffer [MAX_PATH_LENGTH_WTH_TERMINATOR ];
234- char * pPath = "C:\\a\\b " ;
274+ char * pPath = "C:\\a/b\\ " ;
235275
236276 bool success =
237277 GetAbsolutePath (pPath , localBuffer , MAX_PATH_LENGTH_WTH_TERMINATOR );
238278
239- TEST_ASSERT_TRUE (success );
240- TEST_ASSERT_NOT_EQUAL (pPath , & localBuffer [0 ]);
241- TEST_ASSERT_EQUAL_STRING (pPath , localBuffer );
279+ TEST_ASSERT_FALSE (success );
242280}
243281
244282TEST (
245283 TestFileUtils ,
246- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_FileExtention_WindowsStyle ) {
284+ test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_TrailingSlash_PosixStyleWindowsPrefix ) {
247285 char localBuffer [MAX_PATH_LENGTH_WTH_TERMINATOR ];
248- char * pPath = "C:\\a\\b.txt " ;
286+ char * pPath = "C:/a/b/ " ;
249287
250288 bool success =
251289 GetAbsolutePath (pPath , localBuffer , MAX_PATH_LENGTH_WTH_TERMINATOR );
@@ -297,28 +335,6 @@ TEST(
297335 TEST_ASSERT_EQUAL_STRING (pPath , localBuffer );
298336}
299337
300- TEST (
301- TestFileUtils ,
302- test_GetAbsolutePath_ReturnsTrueIfPathIsRelativeAndCopiesItToBuffer_TrailingSlash_WindowsStyle ) {
303- char expectedAbsolutePathBuffer [MAX_PATH_LENGTH_WTH_TERMINATOR ];
304- GetCurrentWorkingDirectory (expectedAbsolutePathBuffer ,
305- MAX_PATH_LENGTH_WTH_TERMINATOR );
306- RAII_STRING expectedAbsolutePath =
307- RaiiStringCreateFromCString (expectedAbsolutePathBuffer );
308-
309- char localBuffer [MAX_PATH_LENGTH_WTH_TERMINATOR ];
310- char * pPath = "b\\" ;
311-
312- RaiiStringAppend_cString (& expectedAbsolutePath , pPath );
313-
314- bool success =
315- GetAbsolutePath (pPath , localBuffer , MAX_PATH_LENGTH_WTH_TERMINATOR );
316-
317- TEST_ASSERT_TRUE (success );
318- TEST_ASSERT_GREATER_THAN (strlen (pPath ), strlen (& localBuffer [0 ]));
319- TEST_ASSERT_EQUAL_STRING (expectedAbsolutePath .pString , localBuffer );
320- }
321-
322338TEST (
323339 TestFileUtils ,
324340 test_GetAbsolutePath_ReturnsTrueIfPathIsRelativeAndCopiesItToBuffer_TrailingSlash_PosixStyle ) {
@@ -1204,6 +1220,30 @@ TEST(TestFileUtils,
12041220//==============================
12051221
12061222TEST_GROUP_RUNNER (TestFileUtils ) {
1223+ // IsPathNormalized(...)
1224+ RUN_TEST_CASE (TestFileUtils ,
1225+ test_IsPathNormalized_ReturnsFalseIfPathIsNull );
1226+ RUN_TEST_CASE (TestFileUtils ,
1227+ test_IsPathNormalized_ReturnsTrueIfPathIsEmpty );
1228+ RUN_TEST_CASE (TestFileUtils ,
1229+ test_IsPathNormalized_ReturnsFalseIfPathIsNotNormalized );
1230+ RUN_TEST_CASE (TestFileUtils ,
1231+ test_IsPathNormalized_ReturnsTrueIfPathIsNormalized );
1232+
1233+ // NormalizePathSeparator(...)
1234+ RUN_TEST_CASE (
1235+ TestFileUtils ,
1236+ test_NormailizePathSeparatorsInPlace_ReturnsFalseIfPathIsNull );
1237+ RUN_TEST_CASE (
1238+ TestFileUtils ,
1239+ test_NormailizePathSeparatorsInPlace_NormalizesPathSeparators );
1240+ RUN_TEST_CASE (
1241+ TestFileUtils ,
1242+ test_NormailizePathSeparatorsInPlace_DoesNotChangeAlreadyNormalized );
1243+ RUN_TEST_CASE (
1244+ TestFileUtils ,
1245+ test_NormailizePathSeparatorsInPlace_NormalizesWithWindowsStylePrefix );
1246+
12071247 // IsAbsolutePath(...)
12081248 RUN_TEST_CASE (TestFileUtils , test_IsAbsolutePath_ReturnsFalseIfPathIsNull );
12091249 RUN_TEST_CASE (TestFileUtils , test_IsAbsolutePath_ReturnsFalseIfPathIsEmpty );
@@ -1257,15 +1297,11 @@ TEST_GROUP_RUNNER(TestFileUtils) {
12571297 RUN_TEST_CASE (
12581298 TestFileUtils ,
12591299 test_GetAbsolutePath_AllowsBuffersToBeBiggerThanMaxPathLength );
1300+ RUN_TEST_CASE (TestFileUtils ,
1301+ test_GetAbsolutePath_ReturnsFalseIfIfIsNotNormalized );
12601302 RUN_TEST_CASE (
12611303 TestFileUtils ,
1262- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_TrailingSlash_WindowsStyle );
1263- RUN_TEST_CASE (
1264- TestFileUtils ,
1265- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_NoTrailingSlash_WindowsStyle );
1266- RUN_TEST_CASE (
1267- TestFileUtils ,
1268- test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_FileExtention_WindowsStyle );
1304+ test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_TrailingSlash_PosixStyleWindowsPrefix );
12691305 RUN_TEST_CASE (
12701306 TestFileUtils ,
12711307 test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_TrailingSlash_PosixStyle );
@@ -1275,9 +1311,6 @@ TEST_GROUP_RUNNER(TestFileUtils) {
12751311 RUN_TEST_CASE (
12761312 TestFileUtils ,
12771313 test_GetAbsolutePath_ReturnsTrueIfPathIsAlreadyAbsoluteAndCopiesItToBuffer_FileExtentions_PosixStyle );
1278- RUN_TEST_CASE (
1279- TestFileUtils ,
1280- test_GetAbsolutePath_ReturnsTrueIfPathIsRelativeAndCopiesItToBuffer_TrailingSlash_WindowsStyle );
12811314 RUN_TEST_CASE (
12821315 TestFileUtils ,
12831316 test_GetAbsolutePath_ReturnsTrueIfPathIsRelativeAndCopiesItToBuffer_TrailingSlash_PosixStyle );
0 commit comments