Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: tests/OSPathUtilsTest.cpp

Issue 15747004: Add path utils, plus a test for it. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove unnecessary changes. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "Test.h"
11
12 /**
13 * Test SkPathJoin and SkBasename.
14 * Will use SkPathJoin to append filename to dir, test that it works correctly,
15 * and tests using SkBasename on the result.
16 * @param reporter Reporter for test conditions.
17 * @param dir String representing the path to a folder. May or may not
18 * end with SkPATH_SEPARATOR.
19 * @param filename String representing the basename of a file. Must NOT
20 * contain SkPATH_SEPARATOR.
21 */
22 static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir,
23 SkString filename) {
24 // If filename contains SkPATH_SEPARATOR, the tests will fail.
25 SkASSERT(!filename.contains(SkPATH_SEPARATOR));
26
27 // Tests for SkOSPathUtils::SkPathJoin and SkOSPathUtils::SkBasename
28
29 // fullName should be "dir<SkPATH_SEPARATOR>file"
30 SkString fullName = SkOSPathUtils::SkPathJoin(dir.c_str(), filename.c_str()) ;
31
32 // fullName should be the combined size of dir and file, plus one if
33 // dir did not include the final path separator.
34 size_t expectedSize = dir.size() + filename.size();
35 if (!dir.endsWith(SkPATH_SEPARATOR)) {
36 expectedSize++;
37 }
38 REPORTER_ASSERT(reporter, fullName.size() == expectedSize);
39
40 SkString basename = SkOSPathUtils::SkBasename(fullName.c_str());
41
42 // basename should be the same as filename
43 REPORTER_ASSERT(reporter, basename.equals(filename));
44
45 // basename will not contain a path separator
46 REPORTER_ASSERT(reporter, !basename.contains(SkPATH_SEPARATOR));
47
48 // Now take the basename of filename, which should be the same as filename.
49 basename = SkOSPathUtils::SkBasename(filename.c_str());
50 REPORTER_ASSERT(reporter, basename.equals(filename));
51 }
52
53 static void test_os_path_utils_tests(skiatest::Reporter* reporter) {
54 SkString dir("dir");
55 SkString filename("file");
56 test_dir_with_file(reporter, dir, filename);
57
58 // Now make sure this works with a path separator at the end of dir.
59 dir.appendUnichar(SkPATH_SEPARATOR);
60 test_dir_with_file(reporter, dir, filename);
61
62 // Test with a sub directory.
63 dir.append("subDir");
64 test_dir_with_file(reporter, dir, filename);
65
66 // Basename of a directory with a path separator at the end is empty.
67 dir.appendUnichar(SkPATH_SEPARATOR);
68 SkString baseOfDir = SkOSPathUtils::SkBasename(dir.c_str());
69 REPORTER_ASSERT(reporter, baseOfDir.size() == 0);
70
71 // Basename of NULL is an empty string.
72 SkString empty = SkOSPathUtils::SkBasename(NULL);
73 REPORTER_ASSERT(reporter, empty.size() == 0);
74 }
75
76 #include "TestClassDef.h"
77 DEFINE_TESTCLASS("OSPathUtils", OSPathUtilsTestClass, test_os_path_utils_tests)
OLDNEW
« src/utils/SkOSFile.cpp ('K') | « src/utils/SkOSFile.cpp ('k') | tools/skimage_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698