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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/* tests-basics.vala
*
* Copyright (C) 2011-2014 Matthias Klumpp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author:
* Matthias Klumpp <matthias@tenstral.net>
*/
using GLib;
using Gee;
using Listaller;
using Listaller.Utils;
private string datadir;
private string foobar_dir;
void msg (string s) {
stdout.printf (s + "\n");
}
void test_basics_message_cb (MessageItem item) {
msg ("Received message:");
msg (" " + item.to_string ());
assert (item.mtype != MessageEnum.CRITICAL);
}
void test_basics_error_code_cb (ErrorItem item) {
msg ("Received error:");
msg (" " + item.to_string ());
error (item.details);
}
void test_listaller_config () {
// Set up Listaller configuration
var conf = new Listaller.Config ();
// Set up setup-settings
var ssettings = new SetupSettings (IPK.InstallMode.TEST);
assert (ssettings.test_mode == true);
string tmp = ssettings.get_unique_install_tmp_dir ();
assert (tmp == ssettings.get_unique_install_tmp_dir ());
ssettings.invalidate_tmp_dir ();
assert (tmp != ssettings.get_unique_install_tmp_dir ());
}
void test_application_ids () {
bool ret = false;
msg ("Testing app-ids");
string foobar_mfile = Path.build_filename (foobar_dir, "foobar.appdata.xml", null);
AppItem dummy = new AppItem ();
ret = dummy.load_xml_file (foobar_mfile);
assert (ret == true);
msg ("Dummy application id: " + dummy.appid);
string expected_id = "foobar;1.0;" + fold_user_dir (foobar_mfile) + ";" + "unknown";
//! assert (dummy.appid == expected_id);
AppItem item1 = new AppItem.from_id (expected_id);
assert (item1.unique_name == "foobar");
assert (item1.metainfo.name == "Listaller FooBar");
assert (item1.version == "1.0");
assert (item1.metainfo.developer_name == "Listaller Project");
//! assert (item1.get_raw_cmd () == "%INST%/foo");
assert (item1.origin == "unknown");
var cpt = new AppStream.Component ();
cpt.name = "MyApp";
cpt.id = "myapp";
AppItem item2 = new AppItem ();
item2.metainfo = cpt;
item2.version = "0.1";
item2.origin = "http://example.com";
assert (item2.metainfo.name == "MyApp");
assert (item2.unique_name == "myapp");
item2.metadata_file = Path.build_filename (foobar_dir, "foobar.appdata.xml", null);
item2.update_with_metadata_file ();
assert (item2.desktop_file == "%APP%/foobar.desktop");
debug (item2.appid);
assert (item2.appid == "foobar;1.0;%s;http://example.com".printf (item2.metadata_file));
cpt.name = "Google Earth";
cpt.id = "";
AppItem item3 = new AppItem ();
item3.metainfo = cpt;
assert (item3.unique_name == "google_earth");
}
void test_utils () {
string xpath = fold_user_dir (datadir);
xpath = expand_user_dir (xpath);
assert (datadir == xpath);
string s;
s = real_path ("/usr/share/../bin/test");
assert (s == "/usr/bin/test");
s = real_path ("/usr/share/./listaller/data/../files");
assert (s == "/usr/share/listaller/files");
s = Utils.build_filename ("/usr/bin/", "..", "share", "listaller", ".", "test");
assert (s == "/usr/share/listaller/test");
}
void test_zfeeds () {
Dep.Feed feed = new Dep.Feed ();
feed.open (Path.build_filename (datadir, "libogg.xml", null));
var dep = new Dependency ();
feed.update_dependency_data (dep);
assert (dep.metainfo.name == "libogg");
assert (dep.metainfo.get_url (AppStream.UrlKind.HOMEPAGE) == "http://xiph.org/ogg/");
/* Info: It is "libogg-0", because the version is set through "search_matching_dependency ()",
* which we don't call here because the libogg feed does not provide implementations
* for every platform out there. (This is a default-test, which should not fail, usually.) */
assert (dep.metainfo.id == "libogg");
bool ret = feed.search_matching_dependency ();
assert (ret == true);
feed.update_dependency_data (dep);
assert (dep.get_version () == "1.1.4-1");
assert (feed.package_url != "");
}
int comp_ver (string a, string b) {
int i = compare_versions (a, b);
debug ("Comparing versions: %s and %s => [%i]", a, b, i);
return i;
}
void test_versions () {
assert (comp_ver ("6", "8") == -1);
assert (comp_ver ("0.6.12b-d", "0.6.12a") == 1);
assert (comp_ver ("7.4", "7.4") == 0);
assert (comp_ver ("ab.d", "ab.f") == -1);
assert (comp_ver ("0.6.16", "0.6.14") == 1);
assert (comp_ver ("3.0.rc2", "3.0.0") == -1);
}
void test_appstream_xml () {
AppStream.Component cpt;
var mdata = new AppStream.Metadata ();
string asd = load_file_to_string (Path.build_filename (datadir, "appstream.appdata.xml"));
try {
cpt = mdata.parse_data (asd);
} catch (Error e) {
error (e.message);
}
var item = new AppItem ();
item.metainfo = cpt;
item.fast_check ();
assert (item.unique_name == "foobar");
}
void test_metafile () {
var mf = new IPK.MetaFile ();
bool ret;
ret = mf.open_file (Path.build_filename (datadir, "test-requirements.list"));
assert (ret == true);
mf.open_block_by_value ("name", "vorbis");
string value = mf.get_value ("libraries");
assert (value == "libvorbis.so.*\nlibvorbisfile.so.*\nlibvorbisenc.so.*");
ret = mf.open_block_by_value ("id", "mesagl");
assert (ret == true);
mf.add_value ("Test", "Blahfvlshfikdj");
ret = mf.add_value ("Test2", "hgdufjhbudj\nhugdvh ushda743\nsuhfusdha7wdwe");
assert (ret == true);
var val = mf.get_value ("Test2");
assert (val == "hgdufjhbudj\nhugdvh ushda743\nsuhfusdha7wdwe");
}
void test_field () {
IPK.InstallMode flags = IPK.InstallMode.NONE;
assert (flags.is_all_set (IPK.InstallMode.SHARED) == false);
assert (flags.is_any_set (IPK.InstallMode.SHARED) == false);
flags = IPK.InstallMode.SHARED;
assert (flags.is_all_set (IPK.InstallMode.PRIVATE) == false);
assert (flags.is_all_set (IPK.InstallMode.SHARED) == true);
assert (flags.is_any_set (IPK.InstallMode.SHARED | IPK.InstallMode.PRIVATE) == true);
flags = flags.set (IPK.InstallMode.PRIVATE);
assert (flags.is_all_set (IPK.InstallMode.PRIVATE | IPK.InstallMode.SHARED) == true);
assert (flags.is_all_set (IPK.InstallMode.SHARED | IPK.InstallMode.TEST) == false);
flags = flags.unset (IPK.InstallMode.PRIVATE);
assert (flags.is_all_set (IPK.InstallMode.PRIVATE | IPK.InstallMode.SHARED) == false);
}
void test_components () {
bool ret;
var foo_dep = new Dependency ();
ret = foo_dep.load_from_file (Path.build_filename (datadir, "FooTest2.metainfo.xml", null));
assert (ret);
assert (foo_dep.metainfo.id == "FooTest2");
foo_dep.installed = true;
string version = foo_dep.get_version ();
assert (version == "1.0");
// --------------
// Test capabilities of resolving version names
var lilibv_dep = new Dependency ();
ret = lilibv_dep.load_from_file (Path.build_filename (datadir, "ListallerTest1.metainfo.xml", null));
assert (ret);
assert (lilibv_dep.metainfo.id == "ListallerTest1");
lilibv_dep.installed = true;
version = lilibv_dep.get_version ();
debug ("LiVersion: %s", version);
assert (version == PkgConfig.PACKAGE_VERSION);
}
void test_playground () {
var conf = new Listaller.Config ();
// Just try something!
}
int main (string[] args) {
msg ("=== Running Basic Tests ===");
datadir = args[1];
assert (datadir != null);
foobar_dir = Path.build_filename (datadir, "foobar", null);
datadir = Path.build_filename (datadir, "testdata", null);
assert (FileUtils.test (datadir, FileTest.EXISTS) != false);
var tenv = new TestEnvironment ("basic");
tenv.init (ref args);
tenv.create_environment ();
tenv.enforce_full_verbosity ();
test_utils ();
test_listaller_config ();
test_application_ids ();
test_versions ();
test_metafile ();
test_appstream_xml ();
test_components ();
test_zfeeds ();
test_field ();
test_playground ();
tenv.run ();
return 0;
}
|