]> git.mxchange.org Git - simgear.git/blob - simgear/package/CatalogTest.cxx
Packages: more unit-test coverage
[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(), 3);
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     string_set tags(p2->tags());
70     COMPARE(tags.size(), 4);
71     VERIFY(tags.find("ifr") != tags.end());
72     VERIFY(tags.find("cessna") != tags.end());
73     VERIFY(tags.find("jet") == tags.end());
74
75
76     SGPropertyNode_ptr queryA(new SGPropertyNode);
77     queryA->setStringValue("tag", "ifr");
78     VERIFY(p2->matches(queryA.ptr()));
79
80     SGPropertyNode_ptr queryB(new SGPropertyNode);
81     queryB->setStringValue("name", "ces");
82     VERIFY(p2->matches(queryB.ptr()));
83
84     SGPropertyNode_ptr queryC(new SGPropertyNode);
85     queryC->setStringValue("name", "foo");
86     VERIFY(!p2->matches(queryC.ptr()));
87
88     SGPropertyNode_ptr queryD(new SGPropertyNode);
89     queryD->setIntValue("rating-FDM", 3);
90     VERIFY(p2->matches(queryD.ptr()));
91
92     SGPropertyNode_ptr queryE(new SGPropertyNode);
93     queryE->setIntValue("rating-model", 5);
94     queryE->setStringValue("description", "cessna");
95     VERIFY(p2->matches(queryE.ptr()));
96
97
98     delete root;
99     return EXIT_SUCCESS;
100 }
101
102 int main(int argc, char* argv[])
103 {
104     parseTest();
105     std::cout << "Successfully passed all tests!" << std::endl;
106     return EXIT_SUCCESS;
107 }