File: path.h

package info (click to toggle)
scummvm 2.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 363,784 kB
  • sloc: cpp: 3,622,060; asm: 27,410; python: 10,528; sh: 10,241; xml: 6,752; java: 5,579; perl: 2,570; yacc: 1,635; javascript: 1,016; lex: 539; makefile: 398; ansic: 378; awk: 275; objc: 82; sed: 11; php: 1
file content (69 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cxxtest/TestSuite.h>

#include "common/path.h"

static const char *TEST_PATH = "parent/dir/file.txt";

class PathTestSuite : public CxxTest::TestSuite
{
	public:
	void test_Path() {
		Common::Path p;
		TS_ASSERT_EQUALS(p.toString(), Common::String());

		Common::Path p2(TEST_PATH);
		TS_ASSERT_EQUALS(p2.toString(), Common::String(TEST_PATH));
	}

	void test_getLastComponent() {
		Common::Path p(TEST_PATH);
		TS_ASSERT_EQUALS(p.getLastComponent().toString(), "file.txt");
	}

	void test_getParent() {
		Common::Path p(TEST_PATH);
		TS_ASSERT_EQUALS(p.getParent().toString(), "parent/dir/");
		// TODO: should this work?
		TS_ASSERT_EQUALS(p.getParent().getLastComponent().toString(), "dir/");
	}

	void test_join() {
		Common::Path p("dir");
		Common::Path p2 = p.join("file.txt");
		TS_ASSERT_EQUALS(p2.toString(), "dir/file.txt");

		Common::Path p3(TEST_PATH);
		Common::Path p4 = p3.getParent().join("other.txt");
		TS_ASSERT_EQUALS(p4.toString(), "parent/dir/other.txt");
	}

	// Ensure we can joinInPlace correctly with leading or trailing separators
	void test_joinInPlace() {
		Common::Path p("abc/def");
		p.joinInPlace("file.txt");
		TS_ASSERT_EQUALS(p.toString(), "abc/def/file.txt");

		Common::Path p2("xyz/def");
		p2.joinInPlace(Common::Path("file.txt"));
		TS_ASSERT_EQUALS(p2.toString(), "xyz/def/file.txt");

		Common::Path p3("ghi/def/");
		p3.joinInPlace(Common::Path("file.txt"));
		TS_ASSERT_EQUALS(p3.toString(), "ghi/def/file.txt");

		Common::Path p4("123/def");
		p4.joinInPlace(Common::Path("/file4.txt"));
		TS_ASSERT_EQUALS(p4.toString(), "123/def/file4.txt");
	}

	void test_separator() {
		Common::Path p(TEST_PATH, '\\');
		TS_ASSERT_EQUALS(p.getLastComponent().toString(), TEST_PATH);
		TS_ASSERT_EQUALS(p.getParent().toString(), "");

		Common::Path p2(TEST_PATH, 'e');
		TS_ASSERT_EQUALS(p2.getLastComponent().toString(), ".txt");
		TS_ASSERT_EQUALS(p2.getParent().toString('#'), "par#nt/dir/fil#");
		TS_ASSERT_EQUALS(p2.getParent().getParent().toString('#'), "par#");
	}
};