Chromium Code Reviews| Index: tests/OSPathUtilsTest.cpp |
| diff --git a/tests/OSPathUtilsTest.cpp b/tests/OSPathUtilsTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4695638f0ec1046d09700aed38122c5f377930a0 |
| --- /dev/null |
| +++ b/tests/OSPathUtilsTest.cpp |
| @@ -0,0 +1,49 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkString.h" |
| +#include "SkOSFile.h" |
| +#include "SkOSPathUtils.h" |
| +#include "Test.h" |
| + |
| +static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir, |
|
epoger
2013/05/22 17:33:58
Please add documentation stating what this method
scroggo
2013/05/23 15:29:33
Done.
|
| + SkString filename) { |
| +#ifdef SK_DEBUG |
|
epoger
2013/05/22 17:33:58
Why the #ifdef here? Seems like this code can alw
scroggo
2013/05/23 15:29:33
Because it's only here for the SkASSERT. In releas
|
| + // If filename contains SkPATH_SEPARATOR, the tests will fail. |
| + SkString pathSeparator; |
| + pathSeparator.appendUnichar(SkPATH_SEPARATOR); |
| + SkASSERT(!filename.contains(pathSeparator.c_str())); |
|
epoger
2013/05/22 17:33:58
Why not just
SkASSERT(!filename.contains(SkPATH_
scroggo
2013/05/23 15:29:33
Done.
|
| +#endif |
| + // Tests for SkPathJoin and SkBasename |
| + // fullName should be "dir<SkPATH_SEPARATOR>file" |
|
epoger
2013/05/22 17:33:58
I think this code would be easier to read with som
scroggo
2013/05/23 15:29:33
Done.
|
| + SkString fullName = SkPathJoin(dir.c_str(), filename.c_str()); |
| + // fullName should be the combined size of dir and file, plus one if |
| + // dir did not include the final path separator. |
| + REPORTER_ASSERT(reporter, fullName.size() == dir.size() + filename.size() |
|
epoger
2013/05/22 17:33:58
Maybe this tighter test instead?
if (dir.endsWith
scroggo
2013/05/23 15:29:33
Done.
|
| + || fullName.size() == dir.size() + filename.size() + 1); |
| + const char* basename = SkBasename(fullName.c_str()); |
|
epoger
2013/05/22 17:33:58
I think the code would be easier to follow if you
scroggo
2013/05/23 15:29:33
Done.
|
| + // basename should be the same as filename |
| + REPORTER_ASSERT(reporter, 0 == strcmp(basename, filename.c_str())); |
| + // Now take the basename of filename, which should be the same as filename. |
| + basename = SkBasename(filename.c_str()); |
| + REPORTER_ASSERT(reporter, 0 == strcmp(basename, filename.c_str())); |
| +} |
| + |
| +static void test_os_path_utils_tests(skiatest::Reporter* reporter) { |
| + SkString dir("dir"); |
| + SkString filename("file"); |
| + test_dir_with_file(reporter, dir, filename); |
| + // Now make sure this works with a path separator at the end of dir. |
| + dir.appendUnichar(SkPATH_SEPARATOR); |
| + test_dir_with_file(reporter, dir, filename); |
| + // Test with a sub directory. |
| + dir.append("subDir"); |
| + test_dir_with_file(reporter, dir, filename); |
| +} |
| + |
| +#include "TestClassDef.h" |
| +DEFINE_TESTCLASS("OSPathUtils", OSPathUtilsTestClass, test_os_path_utils_tests) |