Expand package-system unit-tests.
More to come, but this covers the absolute basics now.
This commit is contained in:
@@ -23,15 +23,92 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include <simgear/package/Catalog.hxx>
|
#include <simgear/package/Catalog.hxx>
|
||||||
#include <simgear/package/Root.hxx>
|
#include <simgear/package/Root.hxx>
|
||||||
#include <simgear/package/Package.hxx>
|
#include <simgear/package/Package.hxx>
|
||||||
|
#include <simgear/package/Install.hxx>
|
||||||
|
|
||||||
|
#include <simgear/misc/test_macros.hxx>
|
||||||
#include <simgear/misc/sg_dir.hxx>
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
|
||||||
|
#include <simgear/io/test_HTTP.hxx>
|
||||||
|
#include <simgear/io/HTTPClient.hxx>
|
||||||
|
#include <simgear/io/sg_file.hxx>
|
||||||
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
|
|
||||||
|
std::string readFileIntoString(const SGPath& path)
|
||||||
|
{
|
||||||
|
std::string contents;
|
||||||
|
|
||||||
|
size_t readLen;
|
||||||
|
SGFile f(path.str());
|
||||||
|
if (!f.open(SG_IO_IN)) {
|
||||||
|
throw sg_io_exception("Couldn't open file", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[8192];
|
||||||
|
while ((readLen = f.read(buf, 8192)) > 0) {
|
||||||
|
contents += std::string(buf, readLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
SGPath global_serverFilesRoot;
|
||||||
|
|
||||||
|
class TestPackageChannel : public TestServerChannel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void processRequestHeaders()
|
||||||
|
{
|
||||||
|
state = STATE_IDLE;
|
||||||
|
|
||||||
|
SGPath localPath(global_serverFilesRoot);
|
||||||
|
localPath.append(path);
|
||||||
|
|
||||||
|
//SG_LOG(SG_IO, SG_INFO, "local path is:" << localPath.str());
|
||||||
|
|
||||||
|
if (localPath.exists()) {
|
||||||
|
std::string content = readFileIntoString(localPath);
|
||||||
|
std::stringstream d;
|
||||||
|
d << "HTTP/1.1 " << 200 << " " << reasonForCode(200) << "\r\n";
|
||||||
|
d << "Content-Length:" << content.size() << "\r\n";
|
||||||
|
d << "\r\n"; // final CRLF to terminate the headers
|
||||||
|
d << content;
|
||||||
|
|
||||||
|
std::string ds(d.str());
|
||||||
|
bufferSend(ds.data(), ds.size());
|
||||||
|
} else {
|
||||||
|
sendErrorResponse(404, false, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestServer<TestPackageChannel> testServer;
|
||||||
|
|
||||||
|
void waitForUpdateComplete(HTTP::Client* cl, pkg::Root* root)
|
||||||
|
{
|
||||||
|
SGTimeStamp start(SGTimeStamp::now());
|
||||||
|
while (start.elapsedMSec() < 10000) {
|
||||||
|
cl->update();
|
||||||
|
testServer.poll();
|
||||||
|
|
||||||
|
if (!cl->hasActiveRequests()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SGTimeStamp::sleepForMSec(15);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "timed out" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
int parseTest()
|
int parseTest()
|
||||||
{
|
{
|
||||||
SGPath rootPath = simgear::Dir::current().path();
|
SGPath rootPath = simgear::Dir::current().path();
|
||||||
@@ -55,7 +132,7 @@ int parseTest()
|
|||||||
COMPARE(p1->qualifiedId(), "org.flightgear.test.catalog1.alpha");
|
COMPARE(p1->qualifiedId(), "org.flightgear.test.catalog1.alpha");
|
||||||
COMPARE(p1->name(), "Alpha package");
|
COMPARE(p1->name(), "Alpha package");
|
||||||
COMPARE(p1->revision(), 8);
|
COMPARE(p1->revision(), 8);
|
||||||
COMPARE(p1->fileSizeBytes(), 1234567);
|
COMPARE(p1->fileSizeBytes(), 593);
|
||||||
|
|
||||||
|
|
||||||
pkg::PackageRef p2 = cat->getPackageById("c172p");
|
pkg::PackageRef p2 = cat->getPackageById("c172p");
|
||||||
@@ -99,9 +176,139 @@ int parseTest()
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testAddCatalog(HTTP::Client* cl)
|
||||||
|
{
|
||||||
|
// erase dir
|
||||||
|
SGPath rootPath(simgear::Dir::current().path());
|
||||||
|
rootPath.append("pkg_add_catalog");
|
||||||
|
simgear::Dir pd(rootPath);
|
||||||
|
pd.removeChildren();
|
||||||
|
|
||||||
|
|
||||||
|
pkg::RootRef root(new pkg::Root(rootPath, "8.1.2"));
|
||||||
|
// specify a test dir
|
||||||
|
root->setHTTPClient(cl);
|
||||||
|
|
||||||
|
pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml");
|
||||||
|
|
||||||
|
waitForUpdateComplete(cl, root);
|
||||||
|
|
||||||
|
// verify on disk state
|
||||||
|
SGPath p(rootPath);
|
||||||
|
p.append("org.flightgear.test.catalog1");
|
||||||
|
p.append("catalog.xml");
|
||||||
|
VERIFY(p.exists());
|
||||||
|
COMPARE(root->allPackages().size(), 3);
|
||||||
|
COMPARE(root->catalogs().size(), 1);
|
||||||
|
|
||||||
|
pkg::PackageRef p1 = root->getPackageById("alpha");
|
||||||
|
COMPARE(p1->id(), "alpha");
|
||||||
|
|
||||||
|
pkg::PackageRef p2 = root->getPackageById("org.flightgear.test.catalog1.c172p");
|
||||||
|
COMPARE(p2->id(), "c172p");
|
||||||
|
COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void testInstallPackage(HTTP::Client* cl)
|
||||||
|
{
|
||||||
|
SGPath rootPath(simgear::Dir::current().path());
|
||||||
|
rootPath.append("pkg_install_with_dep");
|
||||||
|
simgear::Dir pd(rootPath);
|
||||||
|
pd.removeChildren();
|
||||||
|
|
||||||
|
pkg::RootRef root(new pkg::Root(rootPath, "8.1.2"));
|
||||||
|
// specify a test dir
|
||||||
|
root->setHTTPClient(cl);
|
||||||
|
|
||||||
|
pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml");
|
||||||
|
waitForUpdateComplete(cl, root);
|
||||||
|
|
||||||
|
pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.c172p");
|
||||||
|
pkg::InstallRef ins = p1->install();
|
||||||
|
|
||||||
|
VERIFY(ins->isQueued());
|
||||||
|
|
||||||
|
waitForUpdateComplete(cl, root);
|
||||||
|
VERIFY(p1->isInstalled());
|
||||||
|
VERIFY(p1->existingInstall() == ins);
|
||||||
|
|
||||||
|
pkg::PackageRef commonDeps = root->getPackageById("common-sounds");
|
||||||
|
VERIFY(commonDeps->existingInstall());
|
||||||
|
|
||||||
|
// verify on disk state
|
||||||
|
SGPath p(rootPath);
|
||||||
|
p.append("org.flightgear.test.catalog1");
|
||||||
|
p.append("Aircraft");
|
||||||
|
p.append("c172p");
|
||||||
|
|
||||||
|
COMPARE(p, ins->path());
|
||||||
|
|
||||||
|
p.append("c172p-floats-set.xml");
|
||||||
|
VERIFY(p.exists());
|
||||||
|
|
||||||
|
SGPath p2(rootPath);
|
||||||
|
p2.append("org.flightgear.test.catalog1");
|
||||||
|
p2.append("Aircraft");
|
||||||
|
p2.append("sounds");
|
||||||
|
p2.append("sharedfile.txt");
|
||||||
|
VERIFY(p2.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
void testUninstall(HTTP::Client* cl)
|
||||||
|
{
|
||||||
|
SGPath rootPath(simgear::Dir::current().path());
|
||||||
|
rootPath.append("pkg_uninstall");
|
||||||
|
simgear::Dir pd(rootPath);
|
||||||
|
pd.removeChildren();
|
||||||
|
|
||||||
|
pkg::RootRef root(new pkg::Root(rootPath, "8.1.2"));
|
||||||
|
root->setHTTPClient(cl);
|
||||||
|
|
||||||
|
pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml");
|
||||||
|
waitForUpdateComplete(cl, root);
|
||||||
|
|
||||||
|
pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.c172p");
|
||||||
|
pkg::InstallRef ins = p1->install();
|
||||||
|
|
||||||
|
waitForUpdateComplete(cl, root);
|
||||||
|
|
||||||
|
VERIFY(p1->isInstalled());
|
||||||
|
|
||||||
|
ins->uninstall();
|
||||||
|
|
||||||
|
VERIFY(!ins->path().exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
void testRemoveCatalog()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void testRefreshCatalog()
|
||||||
|
{
|
||||||
|
|
||||||
|
// check for pending updates
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
sglog().setLogLevels( SG_ALL, SG_DEBUG );
|
||||||
|
|
||||||
|
HTTP::Client cl;
|
||||||
|
cl.setMaxConnections(1);
|
||||||
|
|
||||||
|
global_serverFilesRoot = SGPath(SRC_DIR);
|
||||||
|
|
||||||
|
testAddCatalog(&cl);
|
||||||
|
|
||||||
parseTest();
|
parseTest();
|
||||||
|
|
||||||
|
testInstallPackage(&cl);
|
||||||
|
|
||||||
|
testUninstall(&cl);
|
||||||
|
|
||||||
std::cout << "Successfully passed all tests!" << std::endl;
|
std::cout << "Successfully passed all tests!" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ PackageList Package::dependencies() const
|
|||||||
PackageList result;
|
PackageList result;
|
||||||
|
|
||||||
BOOST_FOREACH(SGPropertyNode* dep, m_props->getChildren("depends")) {
|
BOOST_FOREACH(SGPropertyNode* dep, m_props->getChildren("depends")) {
|
||||||
std::string depName = dep->getStringValue("package");
|
std::string depName = dep->getStringValue("id");
|
||||||
unsigned int rev = dep->getIntValue("revision", 0);
|
unsigned int rev = dep->getIntValue("revision", 0);
|
||||||
|
|
||||||
// prefer local hangar package if possible, in case someone does something
|
// prefer local hangar package if possible, in case someone does something
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<PropertyList>
|
||||||
|
<sim>
|
||||||
|
|
||||||
|
</sim>
|
||||||
|
</PropertyList>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
The quick brown fox jumps over a lazy dog.
|
||||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<PropertyList>
|
||||||
|
<sim>
|
||||||
|
|
||||||
|
</sim>
|
||||||
|
</PropertyList>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<PropertyList>
|
||||||
|
<sim>
|
||||||
|
|
||||||
|
</sim>
|
||||||
|
</PropertyList>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<PropertyList>
|
||||||
|
<sim>
|
||||||
|
|
||||||
|
</sim>
|
||||||
|
</PropertyList>
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
<id>org.flightgear.test.catalog1</id>
|
<id>org.flightgear.test.catalog1</id>
|
||||||
<description>First test catalog</description>
|
<description>First test catalog</description>
|
||||||
<url>http://download.flightgear.org/catalog1/catalog.xml</url>
|
<url>http://download.flightgear.org/catalog1/catalog.xml</url>
|
||||||
|
<catalog-version>4</catalog-version>
|
||||||
|
|
||||||
<version>8.1.*</version>
|
<version>8.1.*</version>
|
||||||
<version>8.0.0</version>
|
<version>8.0.0</version>
|
||||||
<version>8.2.0</version>
|
<version>8.2.0</version>
|
||||||
@@ -12,15 +14,21 @@
|
|||||||
<id>alpha</id>
|
<id>alpha</id>
|
||||||
<name>Alpha package</name>
|
<name>Alpha package</name>
|
||||||
<revision type="int">8</revision>
|
<revision type="int">8</revision>
|
||||||
<file-size-bytes type="int">1234567</file-size-bytes>
|
<file-size-bytes type="int">593</file-size-bytes>
|
||||||
|
|
||||||
|
<md5>a469c4b837f0521db48616cfe65ac1ea</md5>
|
||||||
|
<url>http://localhost:2000/catalogTest1/alpha.zip</url>
|
||||||
|
|
||||||
|
<dir>alpha</dir>
|
||||||
</package>
|
</package>
|
||||||
|
|
||||||
<package>
|
<package>
|
||||||
<id>c172p</id>
|
<id>c172p</id>
|
||||||
<name>Cessna 172-P</name>
|
<name>Cessna 172-P</name>
|
||||||
|
<dir>c172p</dir>
|
||||||
<description>A plane made by Cessna</description>
|
<description>A plane made by Cessna</description>
|
||||||
<revision type="int">42</revision>
|
<revision type="int">42</revision>
|
||||||
<file-size-bytes type="int">34567</file-size-bytes>
|
<file-size-bytes type="int">860</file-size-bytes>
|
||||||
|
|
||||||
<tag>cessna</tag>
|
<tag>cessna</tag>
|
||||||
<tag>ga</tag>
|
<tag>ga</tag>
|
||||||
@@ -54,11 +62,19 @@
|
|||||||
<id>c172p-skis</id>
|
<id>c172p-skis</id>
|
||||||
<name>C172 with skis</name>
|
<name>C172 with skis</name>
|
||||||
</variant>
|
</variant>
|
||||||
|
|
||||||
|
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
||||||
|
<url>http://localhost:2000/catalogTest1/c172p.zip</url>
|
||||||
|
|
||||||
</package>
|
</package>
|
||||||
|
|
||||||
<package>
|
<package>
|
||||||
<id>common-sounds</id>
|
<id>common-sounds</id>
|
||||||
<name>Common sound files for test catalog aircraft</name>
|
<name>Common sound files for test catalog aircraft</name>
|
||||||
<revision>10</revision>
|
<revision>10</revision>
|
||||||
|
<dir>sounds</dir>
|
||||||
|
<url>http://localhost:2000/catalogTest1/common-sounds.zip</url>
|
||||||
|
<file-size-bytes>360</file-size-bytes>
|
||||||
|
<md5>acf9eb89cf396eb42f8823d9cdf17584</md5>
|
||||||
</package>
|
</package>
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
Some arbitrary data here.
|
||||||
Reference in New Issue
Block a user