1 // Copyright (C) 2015 James Turner - zakalawe@mac.com
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.
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.
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.
19 # include <simgear_config.h>
22 #include <simgear/misc/test_macros.hxx>
27 #include <simgear/package/Catalog.hxx>
28 #include <simgear/package/Root.hxx>
29 #include <simgear/package/Package.hxx>
31 #include <simgear/misc/sg_dir.hxx>
33 using namespace simgear;
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"));
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");
48 // check the packages too
49 COMPARE(cat->packages().size(), 3);
51 pkg::PackageRef p1 = cat->packages().front();
52 COMPARE(p1->catalog(), cat.ptr());
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);
61 pkg::PackageRef p2 = cat->getPackageById("c172p");
63 COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p");
64 COMPARE(p2->description(), "A plane made by Cessna");
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());
76 SGPropertyNode_ptr queryA(new SGPropertyNode);
77 queryA->setStringValue("tag", "ifr");
78 VERIFY(p2->matches(queryA.ptr()));
80 SGPropertyNode_ptr queryB(new SGPropertyNode);
81 queryB->setStringValue("name", "ces");
82 VERIFY(p2->matches(queryB.ptr()));
84 SGPropertyNode_ptr queryC(new SGPropertyNode);
85 queryC->setStringValue("name", "foo");
86 VERIFY(!p2->matches(queryC.ptr()));
88 SGPropertyNode_ptr queryD(new SGPropertyNode);
89 queryD->setIntValue("rating-FDM", 3);
90 VERIFY(p2->matches(queryD.ptr()));
92 SGPropertyNode_ptr queryE(new SGPropertyNode);
93 queryE->setIntValue("rating-model", 5);
94 queryE->setStringValue("description", "cessna");
95 VERIFY(p2->matches(queryE.ptr()));
102 int main(int argc, char* argv[])
105 std::cout << "Successfully passed all tests!" << std::endl;