Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkString.h" | |
| 9 #include "SkOSFile.h" | |
| 10 #include "SkOSPathUtils.h" | |
| 11 #include "Test.h" | |
| 12 | |
| 13 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.
| |
| 14 SkString filename) { | |
| 15 #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
| |
| 16 // If filename contains SkPATH_SEPARATOR, the tests will fail. | |
| 17 SkString pathSeparator; | |
| 18 pathSeparator.appendUnichar(SkPATH_SEPARATOR); | |
| 19 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.
| |
| 20 #endif | |
| 21 // Tests for SkPathJoin and SkBasename | |
| 22 // 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.
| |
| 23 SkString fullName = SkPathJoin(dir.c_str(), filename.c_str()); | |
| 24 // fullName should be the combined size of dir and file, plus one if | |
| 25 // dir did not include the final path separator. | |
| 26 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.
| |
| 27 || fullName.size() == dir.size() + filename.size() + 1); | |
| 28 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.
| |
| 29 // basename should be the same as filename | |
| 30 REPORTER_ASSERT(reporter, 0 == strcmp(basename, filename.c_str())); | |
| 31 // Now take the basename of filename, which should be the same as filename. | |
| 32 basename = SkBasename(filename.c_str()); | |
| 33 REPORTER_ASSERT(reporter, 0 == strcmp(basename, filename.c_str())); | |
| 34 } | |
| 35 | |
| 36 static void test_os_path_utils_tests(skiatest::Reporter* reporter) { | |
| 37 SkString dir("dir"); | |
| 38 SkString filename("file"); | |
| 39 test_dir_with_file(reporter, dir, filename); | |
| 40 // Now make sure this works with a path separator at the end of dir. | |
| 41 dir.appendUnichar(SkPATH_SEPARATOR); | |
| 42 test_dir_with_file(reporter, dir, filename); | |
| 43 // Test with a sub directory. | |
| 44 dir.append("subDir"); | |
| 45 test_dir_with_file(reporter, dir, filename); | |
| 46 } | |
| 47 | |
| 48 #include "TestClassDef.h" | |
| 49 DEFINE_TESTCLASS("OSPathUtils", OSPathUtilsTestClass, test_os_path_utils_tests) | |
| OLD | NEW |