aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/OSPathTest.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-08-07 14:28:50 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-07 14:28:50 -0700
commit6eb03cc06d0bc60da5277a83aa0251a475794b04 (patch)
treef359945cb7d54f915bb91f28f44949fffd42e864 /tests/OSPathTest.cpp
parent72ebb9f1dc1ed4d64127b02fed93446b278069d1 (diff)
Add option to dump images from nanobench.
Add option to set the repeat count to any number, replacs the --runOnce flag. R=mtklein@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/450743002
Diffstat (limited to 'tests/OSPathTest.cpp')
-rw-r--r--tests/OSPathTest.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/OSPathTest.cpp b/tests/OSPathTest.cpp
index 1452c3852e..facc6ad3f7 100644
--- a/tests/OSPathTest.cpp
+++ b/tests/OSPathTest.cpp
@@ -10,7 +10,7 @@
#include "Test.h"
/**
- * Test SkOSPath::Join and SkOSPath::Basename.
+ * Test SkOSPath::Join, SkOSPath::Basename, and SkOSPath::Dirname.
* Will use SkOSPath::Join to append filename to dir, test that it works correctly,
* and tests using SkOSPath::Basename on the result.
* @param reporter Reporter for test conditions.
@@ -32,16 +32,28 @@ static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir,
// fullName should be the combined size of dir and file, plus one if
// dir did not include the final path separator.
size_t expectedSize = dir.size() + filename.size();
- if (!dir.endsWith(SkPATH_SEPARATOR)) {
+ if (!dir.endsWith(SkPATH_SEPARATOR) && !dir.isEmpty()) {
expectedSize++;
}
REPORTER_ASSERT(reporter, fullName.size() == expectedSize);
SkString basename = SkOSPath::Basename(fullName.c_str());
+ SkString dirname = SkOSPath::Dirname(fullName.c_str());
// basename should be the same as filename
REPORTER_ASSERT(reporter, basename.equals(filename));
+ // dirname should be the same as dir with any trailing seperators removed.
+ // Except when the the string is just "/".
+ SkString strippedDir = dir;
+ while (strippedDir.size() > 2 && strippedDir[strippedDir.size() - 1] == SkPATH_SEPARATOR) {
+ strippedDir.remove(strippedDir.size() - 1, 1);
+ }
+ if (!dirname.equals(strippedDir)) {
+ SkDebugf("OOUCH %s %s %s\n", dir.c_str(), strippedDir.c_str(), dirname.c_str());
+ }
+ REPORTER_ASSERT(reporter, dirname.equals(strippedDir));
+
// basename will not contain a path separator
REPORTER_ASSERT(reporter, !basename.contains(SkPATH_SEPARATOR));
@@ -78,8 +90,16 @@ DEF_TEST(OSPath, reporter) {
SkString empty = SkOSPath::Basename(NULL);
REPORTER_ASSERT(reporter, empty.size() == 0);
+ // File in root dir
+ dir.printf("%c", SkPATH_SEPARATOR);
+ filename.set("file");
+ test_dir_with_file(reporter, dir, filename);
+
+ // Just the root dir
+ filename.reset();
+ test_dir_with_file(reporter, dir, filename);
+
// Test that NULL can be used for the directory and filename.
SkString emptyPath = SkOSPath::Join(NULL, NULL);
- REPORTER_ASSERT(reporter, emptyPath.size() == 1);
- REPORTER_ASSERT(reporter, emptyPath.contains(SkPATH_SEPARATOR));
+ REPORTER_ASSERT(reporter, emptyPath.isEmpty());
}