71 lines
2.0 KiB
Vala
71 lines
2.0 KiB
Vala
delegate void ContextLambda ();
|
|
const string S = Config.WS;
|
|
int main (string[] args) {
|
|
GLib.Test.init (ref args);
|
|
GLib.Test.add_func ("/test/owl/path-tempdir", () => {
|
|
Owl.Path file = null;
|
|
ContextLambda inner_context = () => {
|
|
Owl.Path tmp;
|
|
try {
|
|
tmp = new Owl.Path.tempdir ();
|
|
assert (tmp.exists ());
|
|
file = new Owl.Path (GLib.File.new_for_path (tmp.get_path ()));
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
};
|
|
inner_context ();
|
|
assert (!file.exists ());
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-mkpath", () => {
|
|
try {
|
|
var tmp = new Owl.Path.tempdir ();
|
|
var child = tmp.child (@"a$(S)b$(S)c");
|
|
child.mkpath();
|
|
assert (child.exists ());
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-spew-slurp", () => {
|
|
try {
|
|
var tmp = new Owl.Path.tempdir ();
|
|
var child = tmp.child (@"a$(S)b$(S)c");
|
|
child.mkpath();
|
|
var file_txt = child.child ("file.txt");
|
|
string contents = "hola mundo\nadios hola\nadios mundo";
|
|
file_txt.spew (contents);
|
|
assert (contents == file_txt.slurp ());
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-visit", () => {
|
|
try {
|
|
var hashmap = new GLib.HashTable<string, bool> (str_hash, str_equal);
|
|
var tmp = new Owl.Path.tempdir ();
|
|
var file1 = tmp.child(@"a$(S)b$(S)c$(S)/file1.txt");
|
|
var file2 = tmp.child(@"a$(S)c$(S)b$(S)/file2.txt");
|
|
file1.parent ().mkpath ();
|
|
file2.parent ().mkpath ();
|
|
file1.spew ("hola");
|
|
file2.spew ("hola");
|
|
tmp.visit (true, (file) => {
|
|
if (file.basename () == "a") {
|
|
hashmap.@set(file.basename (), true);
|
|
}
|
|
if (!file.is_dir ()) {
|
|
hashmap.@set(file.basename (), true);
|
|
}
|
|
return true;
|
|
});
|
|
assert (hashmap.@get("file1.txt"));
|
|
assert (hashmap.@get("file2.txt"));
|
|
assert (hashmap.@get("a"));
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
return GLib.Test.run ();
|
|
}
|