116 lines
3.3 KiB
Vala
116 lines
3.3 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);
|
|
}
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-get-relative", () => {
|
|
try {
|
|
var tmp = new Owl.Path.tempdir ();
|
|
var c = tmp.child (@"a$(S)b$(S)c");
|
|
var a = c.parent ().parent ();
|
|
assert (a.get_relative(c) == @"b$(S)c");
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-copy-contents", () => {
|
|
try {
|
|
string char_list = "abcde";
|
|
var tmp = new Owl.Path.tempdir ();
|
|
var source = tmp.child ("source");
|
|
var dest = tmp.child ("dest");
|
|
for (long i = 0; i<char_list.length; i++) {
|
|
char character = char_list[i];
|
|
var char_path = source.child (character.to_string ());
|
|
char_path.mkpath ();
|
|
var plain_file = char_path.child (character.to_string ());
|
|
plain_file.spew ("hola mundo");
|
|
}
|
|
source.copy_contents (dest);
|
|
int i = 0;
|
|
dest.visit (true, (file) => {
|
|
if (!file.is_dir () && file.slurp () == "hola mundo") {
|
|
i++;
|
|
}
|
|
return true;
|
|
});
|
|
assert (i == 5);
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
GLib.Test.add_func ("/test/owl/path-cwd", () => {
|
|
try {
|
|
var cwd = Owl.Path.cwd ();
|
|
assert (cwd.child("owlpath.h").exists ());
|
|
} catch (GLib.Error error) {
|
|
GLib.Test.fail_printf ("%s\n", error.message);
|
|
}
|
|
});
|
|
|
|
return GLib.Test.run ();
|
|
}
|