File: test_fs.cpp

package info (click to toggle)
libwibble 0.1.9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 500 kB
  • ctags: 1,183
  • sloc: cpp: 5,760; sh: 113; makefile: 71
file content (79 lines) | stat: -rw-r--r-- 1,914 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
70
71
72
73
74
75
76
77
78
79
#include <wibble/config.h>
#include <wibble/sys/fs.h>
#include <set>

using namespace std;
using namespace wibble::sys::fs;

#include <wibble/tests/tut-wibble.h>

namespace tut {

struct sys_fs_shar {};
TESTGRP( sys_fs );

// Test directory iteration
template<> template<>
void to::test< 1 >() {
	Directory dir("/");

	set<string> files;
	for (Directory::const_iterator i = dir.begin(); i != dir.end(); ++i)
		files.insert(*i);

	ensure(files.size() > 0);
	ensure(files.find(".") != files.end());
	ensure(files.find("..") != files.end());
	ensure(files.find("etc") != files.end());
	ensure(files.find("usr") != files.end());
	ensure(files.find("tmp") != files.end());
}

// Ensure that nonexisting directories and files are reported as not valid
template<> template<>
void to::test< 2 >() {
	Directory dir1("/antaniblindalasupercazzola123456");
	ensure(!dir1.valid());

	Directory dir2("/etc/passwd");
	ensure(!dir2.valid());
}

// Test mkpath and friends
template<> template<>
void to::test< 3 >() {
	// Mkpath should succeed on existing directory
	mkpath(".");

	// Mkpath should succeed on existing directory
	mkpath("./.");

	// Mkpath should succeed on existing directory
	mkpath("/");
}

template<> template<>
void to::test< 4 >() {
	// Try creating a path with mkpath
	system("rm -rf test-mkpath");
	mkpath("test-mkpath/test-mkpath");
	ensure(wibble::sys::fs::access("test-mkpath", F_OK));
	ensure(wibble::sys::fs::access("test-mkpath/test-mkpath", F_OK));
	system("rm -rf test-mkpath");
}

template<> template<>
void to::test< 5 >() {
	// Try creating a path with mkFilePath
	system("rm -rf test-mkpath");
	mkFilePath("test-mkpath/test-mkpath/file");
	ensure(wibble::sys::fs::access("test-mkpath", F_OK));
	ensure(wibble::sys::fs::access("test-mkpath/test-mkpath", F_OK));
	ensure(!wibble::sys::fs::access("test-mkpath/test-mkpath/file", F_OK));
	system("rm -rf test-mkpath");
}


}

// vim:set ts=4 sw=4: