]> git.mxchange.org Git - simgear.git/blob - simgear/package/CatalogTest.cxx
e2b98aca74557fa254ce480795169f5d6f2ca7de
[simgear.git] / simgear / package / CatalogTest.cxx
1 // Copyright (C) 2015  James Turner - zakalawe@mac.com
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include <simgear/misc/test_macros.hxx>
23
24 #include <cstdlib>
25 #include <iostream>
26
27 #include <simgear/package/Catalog.hxx>
28 #include <simgear/package/Root.hxx>
29 #include <simgear/package/Package.hxx>
30
31 #include <simgear/misc/sg_dir.hxx>
32
33 using namespace simgear;
34
35 int parseTest()
36 {
37     SGPath rootPath = simgear::Dir::current().path();
38     rootPath.append("testRoot");
39     pkg::Root* root = new pkg::Root(rootPath, "8.1.12");
40     pkg::CatalogRef cat = pkg::Catalog::createFromPath(root, SGPath(SRC_DIR "/catalogTest1"));
41
42     VERIFY(cat.valid());
43
44     COMPARE(cat->id(), "org.flightgear.test.catalog1");
45     COMPARE(cat->url(), "http://download.flightgear.org/catalog1/catalog.xml");
46     COMPARE(cat->description(), "First test catalog");
47
48 // check the packages too
49     COMPARE(cat->packages().size(), 2);
50
51     pkg::PackageRef p1 = cat->packages().front();
52     COMPARE(p1->catalog(), cat.ptr());
53
54     COMPARE(p1->id(), "alpha");
55     COMPARE(p1->qualifiedId(), "org.flightgear.test.catalog1.alpha");
56     COMPARE(p1->name(), "Alpha package");
57     COMPARE(p1->revision(), 8);
58     COMPARE(p1->fileSizeBytes(), 1234567);
59
60
61     pkg::PackageRef p2 = cat->getPackageById("c172p");
62     VERIFY(p2.valid());
63     COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p");
64     COMPARE(p2->description(), "A plane made by Cessna");
65
66
67
68 // test filtering / searching too
69
70     delete root;
71     return EXIT_SUCCESS;
72 }
73
74 int main(int argc, char* argv[])
75 {
76     parseTest();
77     std::cout << "Successfully passed all tests!" << std::endl;
78     return EXIT_SUCCESS;
79 }