Flutter Engine
The Flutter Engine
Functions
OSPathTest.cpp File Reference
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/utils/SkOSPath.h"
#include "tests/Test.h"
#include <cstddef>

Go to the source code of this file.

Functions

static void test_dir_with_file (skiatest::Reporter *reporter, const SkString &dir, const SkString &filename)
 
 DEF_TEST (OSPath, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( OSPath  ,
reporter   
)

Definition at line 69 of file OSPathTest.cpp.

69 {
70 SkString dir("dir");
71 SkString filename("file");
73
74 // Now make sure this works with a path separator at the end of dir.
75 dir.appendUnichar(SkOSPath::SEPARATOR);
77
78 // Test using no filename.
80
81 // Testing using no directory.
83
84 // Test with a sub directory.
85 dir.append("subDir");
87
88 // Basename of a directory with a path separator at the end is empty.
89 dir.appendUnichar(SkOSPath::SEPARATOR);
90 SkString baseOfDir = SkOSPath::Basename(dir.c_str());
91 REPORTER_ASSERT(reporter, baseOfDir.size() == 0);
92
93 // Basename of nullptr is an empty string.
95 REPORTER_ASSERT(reporter, empty.size() == 0);
96
97 // File in root dir
98 dir.printf("%c", SkOSPath::SEPARATOR);
99 filename.set("file");
100 test_dir_with_file(reporter, dir, filename);
101
102 // Just the root dir
103 filename.reset();
104 test_dir_with_file(reporter, dir, filename);
105
106 // Test that nullptr can be used for the directory and filename.
107 SkString emptyPath = SkOSPath::Join(nullptr, nullptr);
108 REPORTER_ASSERT(reporter, emptyPath.isEmpty());
109}
reporter
Definition: FontMgrTest.cpp:39
static void test_dir_with_file(skiatest::Reporter *reporter, const SkString &dir, const SkString &filename)
Definition: OSPathTest.cpp:26
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static constexpr char SEPARATOR
Definition: SkOSPath.h:21
static SkString Join(const char *rootPath, const char *relativePath)
Definition: SkOSPath.cpp:14
static SkString Basename(const char *fullPath)
Definition: SkOSPath.cpp:23
size_t size() const
Definition: SkString.h:131
bool isEmpty() const
Definition: SkString.h:130
EMSCRIPTEN_KEEPALIVE void empty()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145

◆ test_dir_with_file()

static void test_dir_with_file ( skiatest::Reporter reporter,
const SkString dir,
const SkString filename 
)
static

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.

Parameters
reporterReporter for test conditions.
dirString representing the path to a folder. May or may not end with SkOSPath::SEPARATOR.
filenameString representing the basename of a file. Must NOT contain SkOSPath::SEPARATOR.

Definition at line 26 of file OSPathTest.cpp.

27 {
28 // If filename contains SkOSPath::SEPARATOR, the tests will fail.
30
31 // Tests for SkOSPath::Join and SkOSPath::Basename
32
33 // fullName should be "dir<SkOSPath::SEPARATOR>file"
34 SkString fullName = SkOSPath::Join(dir.c_str(), filename.c_str());
35
36 // fullName should be the combined size of dir and file, plus one if
37 // dir did not include the final path separator.
38 size_t expectedSize = dir.size() + filename.size();
39 if (!dir.endsWith(SkOSPath::SEPARATOR) && !dir.isEmpty()) {
40 expectedSize++;
41 }
42 REPORTER_ASSERT(reporter, fullName.size() == expectedSize);
43
45 SkString dirname = SkOSPath::Dirname(fullName.c_str());
46
47 // basename should be the same as filename
48 REPORTER_ASSERT(reporter, basename.equals(filename));
49
50 // dirname should be the same as dir with any trailing seperators removed.
51 // Except when the the string is just "/".
52 SkString strippedDir = dir;
53 while (strippedDir.size() > 2 && strippedDir[strippedDir.size() - 1] == SkOSPath::SEPARATOR) {
54 strippedDir.remove(strippedDir.size() - 1, 1);
55 }
56 if (!dirname.equals(strippedDir)) {
57 SkDebugf("OOUCH %s %s %s\n", dir.c_str(), strippedDir.c_str(), dirname.c_str());
58 }
59 REPORTER_ASSERT(reporter, dirname.equals(strippedDir));
60
61 // basename will not contain a path separator
63
64 // Now take the basename of filename, which should be the same as filename.
65 basename = SkOSPath::Basename(filename.c_str());
66 REPORTER_ASSERT(reporter, basename.equals(filename));
67}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkString Dirname(const char *fullPath)
Definition: SkOSPath.cpp:36
void void void void void void void remove(size_t offset, size_t length)
Definition: SkString.cpp:592
bool equals(const SkString &) const
Definition: SkString.cpp:324
bool contains(const char substring[]) const
Definition: SkString.h:152
const char * c_str() const
Definition: SkString.h:133
basename
Definition: malisc.py:23