mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 05:19:18 -06:00
Move profile information from ProfileData into Profile class
Temporarily comment out unit tests
This commit is contained in:
@@ -44,23 +44,19 @@ namespace openspace {
|
||||
namespace documentation { struct Documentation; }
|
||||
namespace scripting { struct LuaLibrary; }
|
||||
|
||||
struct ProfileData {
|
||||
class Profile {
|
||||
public:
|
||||
// Version
|
||||
struct Version {
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
};
|
||||
static constexpr const Version CurrentVersion = Version{ 1, 0, 0 };
|
||||
Version version = CurrentVersion;
|
||||
|
||||
struct Module {
|
||||
std::string name;
|
||||
std::string loadedInstruction;
|
||||
std::string notLoadedInstruction;
|
||||
};
|
||||
std::vector<Module> modules;
|
||||
|
||||
struct Asset {
|
||||
enum class Type {
|
||||
Require,
|
||||
@@ -71,8 +67,6 @@ struct ProfileData {
|
||||
Type type;
|
||||
std::string name;
|
||||
};
|
||||
std::vector<Asset> assets;
|
||||
|
||||
struct Property {
|
||||
enum class SetType {
|
||||
SetPropertyValue,
|
||||
@@ -83,8 +77,6 @@ struct ProfileData {
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
std::vector<Property> properties;
|
||||
|
||||
struct Keybinding {
|
||||
std::string key; // @TODO (abock, 2020-06-16) change to key+action
|
||||
std::string documentation;
|
||||
@@ -93,8 +85,6 @@ struct ProfileData {
|
||||
bool isLocal;
|
||||
std::string script;
|
||||
};
|
||||
std::vector<Keybinding> keybindings;
|
||||
|
||||
struct Time {
|
||||
enum class Type {
|
||||
Absolute,
|
||||
@@ -105,8 +95,6 @@ struct ProfileData {
|
||||
Type type = Type::None;
|
||||
std::string time;
|
||||
};
|
||||
Time time;
|
||||
|
||||
struct CameraNavState {
|
||||
static constexpr const char* Type = "setNavigationState";
|
||||
|
||||
@@ -127,13 +115,7 @@ struct ProfileData {
|
||||
std::optional<double> altitude;
|
||||
};
|
||||
using CameraType = std::variant<CameraNavState, CameraGoToGeo>;
|
||||
CameraType camera;
|
||||
|
||||
std::vector<std::string> markNodes;
|
||||
};
|
||||
|
||||
class Profile {
|
||||
public:
|
||||
enum class AssetEventType {
|
||||
Add,
|
||||
Require,
|
||||
@@ -176,9 +158,18 @@ public:
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
ProfileData profile;
|
||||
|
||||
private:
|
||||
static constexpr const Version CurrentVersion = Version{ 1, 0, 0 };
|
||||
Version version = CurrentVersion;
|
||||
std::vector<Module> modules;
|
||||
std::vector<Asset> assets;
|
||||
std::vector<Property> properties;
|
||||
std::vector<Keybinding> keybindings;
|
||||
Time time;
|
||||
CameraType camera;
|
||||
std::vector<std::string> markNodes;
|
||||
|
||||
|
||||
bool _ignoreUpdates = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Version parseVersion(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Version parseVersion(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> parts = ghoul::tokenizeString(line, '.');
|
||||
if (parts.empty() || parts.size() > 3) {
|
||||
throw ProfileParsingError(
|
||||
@@ -198,7 +198,7 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
ProfileData::Version version;
|
||||
Profile::Version version;
|
||||
version.major = std::stoi(parts[0]);
|
||||
if (parts.size() > 1) {
|
||||
version.minor = std::stoi(parts[1]);
|
||||
@@ -209,7 +209,7 @@ namespace {
|
||||
return version;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Module parseModule(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Module parseModule(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.size() != 3) {
|
||||
throw ProfileParsingError(
|
||||
@@ -217,14 +217,14 @@ namespace {
|
||||
fmt::format("Expected 3 fields in a Module entry, got {}", fields.size())
|
||||
);
|
||||
}
|
||||
ProfileData::Module m;
|
||||
Profile::Module m;
|
||||
m.name = fields[0];
|
||||
m.loadedInstruction = fields[1];
|
||||
m.notLoadedInstruction = fields[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Asset parseAsset(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Asset parseAsset(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.size() != 3) {
|
||||
throw ProfileParsingError(
|
||||
@@ -233,14 +233,14 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
ProfileData::Asset a;
|
||||
Profile::Asset a;
|
||||
a.path = fields[0];
|
||||
a.type = [&](const std::string& type) -> ProfileData::Asset::Type {
|
||||
a.type = [&](const std::string& type) -> Profile::Asset::Type {
|
||||
if (type == "require") {
|
||||
return ProfileData::Asset::Type::Require;
|
||||
return Profile::Asset::Type::Require;
|
||||
}
|
||||
if (type == "request") {
|
||||
return ProfileData::Asset::Type::Request;
|
||||
return Profile::Asset::Type::Request;
|
||||
}
|
||||
throw ProfileParsingError(
|
||||
lineNumber,
|
||||
@@ -251,7 +251,7 @@ namespace {
|
||||
return a;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Property parseProperty(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Property parseProperty(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.size() != 3) {
|
||||
throw ProfileParsingError(
|
||||
@@ -259,13 +259,13 @@ namespace {
|
||||
fmt::format("Expected 3 fields in Property entry, got {}", fields.size())
|
||||
);
|
||||
}
|
||||
ProfileData::Property p;
|
||||
p.setType = [&](const std::string& type) -> ProfileData::Property::SetType {
|
||||
Profile::Property p;
|
||||
p.setType = [&](const std::string& type) -> Profile::Property::SetType {
|
||||
if (type == "setPropertyValue") {
|
||||
return ProfileData::Property::SetType::SetPropertyValue;
|
||||
return Profile::Property::SetType::SetPropertyValue;
|
||||
}
|
||||
if (type == "setPropertyValueSingle") {
|
||||
return ProfileData::Property::SetType::SetPropertyValueSingle;
|
||||
return Profile::Property::SetType::SetPropertyValueSingle;
|
||||
}
|
||||
throw ProfileParsingError(
|
||||
lineNumber,
|
||||
@@ -281,7 +281,7 @@ namespace {
|
||||
return p;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Keybinding parseKeybinding(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Keybinding parseKeybinding(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.size() != 6) {
|
||||
throw ProfileParsingError(
|
||||
@@ -289,7 +289,7 @@ namespace {
|
||||
fmt::format("Expected 6 fields in Keybinding entry, got {}", fields.size())
|
||||
);
|
||||
}
|
||||
ProfileData::Keybinding kb;
|
||||
Profile::Keybinding kb;
|
||||
kb.key = fields[0];
|
||||
kb.documentation = fields[1];
|
||||
kb.name = fields[2];
|
||||
@@ -310,7 +310,7 @@ namespace {
|
||||
return kb;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::Time parseTime(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::Time parseTime(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.size() != 2) {
|
||||
throw ProfileParsingError(
|
||||
@@ -318,13 +318,13 @@ namespace {
|
||||
fmt::format("Expected 2 fields in Time entry, got {}", fields.size())
|
||||
);
|
||||
}
|
||||
ProfileData::Time time;
|
||||
time.type = [&](const std::string& type) -> ProfileData::Time::Type {
|
||||
Profile::Time time;
|
||||
time.type = [&](const std::string& type) -> Profile::Time::Type {
|
||||
if (type == "absolute") {
|
||||
return ProfileData::Time::Type::Absolute;
|
||||
return Profile::Time::Type::Absolute;
|
||||
}
|
||||
if (type == "relative") {
|
||||
return ProfileData::Time::Type::Relative;
|
||||
return Profile::Time::Type::Relative;
|
||||
}
|
||||
throw ProfileParsingError(
|
||||
lineNumber,
|
||||
@@ -335,15 +335,15 @@ namespace {
|
||||
return time;
|
||||
}
|
||||
|
||||
[[ nodiscard ]] ProfileData::CameraType parseCamera(const std::string& line, int lineNumber) {
|
||||
[[ nodiscard ]] Profile::CameraType parseCamera(const std::string& line, int lineNumber) {
|
||||
std::vector<std::string> fields = ghoul::tokenizeString(line, '\t');
|
||||
if (fields.empty()) {
|
||||
throw ProfileParsingError(lineNumber, "No values specified for Camera location");
|
||||
}
|
||||
ProfileData::CameraType camera = [&](const std::string& type) ->
|
||||
std::variant<ProfileData::CameraNavState, ProfileData::CameraGoToGeo>
|
||||
Profile::CameraType camera = [&](const std::string& type) ->
|
||||
std::variant<Profile::CameraNavState, Profile::CameraGoToGeo>
|
||||
{
|
||||
if (type == ProfileData::CameraNavState::Type) {
|
||||
if (type == Profile::CameraNavState::Type) {
|
||||
if (fields.size() != 8) {
|
||||
throw ProfileParsingError(
|
||||
lineNumber,
|
||||
@@ -353,7 +353,7 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
ProfileData::CameraNavState camera;
|
||||
Profile::CameraNavState camera;
|
||||
camera.anchor = fields[1];
|
||||
camera.aim = fields[2];
|
||||
camera.referenceFrame = fields[3];
|
||||
@@ -363,7 +363,7 @@ namespace {
|
||||
camera.pitch = fields[7];
|
||||
return camera;
|
||||
}
|
||||
if (type == ProfileData::CameraGoToGeo::Type) {
|
||||
if (type == Profile::CameraGoToGeo::Type) {
|
||||
if (fields.size() != 5) {
|
||||
throw ProfileParsingError(
|
||||
lineNumber,
|
||||
@@ -373,7 +373,7 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
ProfileData::CameraGoToGeo camera;
|
||||
Profile::CameraGoToGeo camera;
|
||||
camera.anchor = fields[1];
|
||||
camera.latitude = std::stod(fields[2]);
|
||||
camera.longitude = std::stod(fields[3]);
|
||||
@@ -400,7 +400,7 @@ namespace {
|
||||
} // namespace
|
||||
|
||||
void Profile::saveCurrentSettingsToProfile() {
|
||||
profile.version = ProfileData::CurrentVersion;
|
||||
version = Profile::CurrentVersion;
|
||||
|
||||
//
|
||||
// Update properties
|
||||
@@ -415,42 +415,42 @@ void Profile::saveCurrentSettingsToProfile() {
|
||||
std::vector<std::string> formattedLines;
|
||||
|
||||
for (properties::Property* prop : changedProps) {
|
||||
ProfileData::Property p;
|
||||
p.setType = ProfileData::Property::SetType::SetPropertyValueSingle;
|
||||
Property p;
|
||||
p.setType = Property::SetType::SetPropertyValueSingle;
|
||||
p.name = recurseForFullName(prop->owner()) + prop->identifier();
|
||||
p.value = prop->getStringValue();
|
||||
profile.properties.push_back(std::move(p));
|
||||
properties.push_back(std::move(p));
|
||||
}
|
||||
|
||||
//
|
||||
// add current time to profile file
|
||||
//
|
||||
ProfileData::Time time;
|
||||
time.time = global::timeManager.time().ISO8601();
|
||||
time.type = ProfileData::Time::Type::Absolute;
|
||||
profile.time = std::move(time);
|
||||
Time t;
|
||||
t.time = global::timeManager.time().ISO8601();
|
||||
t.type = Time::Type::Absolute;
|
||||
time = std::move(t);
|
||||
|
||||
// Camera
|
||||
interaction::NavigationHandler::NavigationState nav =
|
||||
global::navigationHandler.navigationState();
|
||||
|
||||
ProfileData::CameraNavState camera;
|
||||
camera.anchor = nav.anchor;
|
||||
camera.aim = nav.aim;
|
||||
camera.referenceFrame = nav.referenceFrame;
|
||||
camera.position = fmt::format(
|
||||
CameraNavState c;
|
||||
c.anchor = nav.anchor;
|
||||
c.aim = nav.aim;
|
||||
c.referenceFrame = nav.referenceFrame;
|
||||
c.position = fmt::format(
|
||||
"{},{},{}",
|
||||
nav.position.x, nav.position.y, nav.position.z
|
||||
);
|
||||
if (nav.up.has_value()) {
|
||||
camera.up = fmt::format(
|
||||
c.up = fmt::format(
|
||||
"{},{},{}",
|
||||
nav.up->x, nav.up->y, nav.up->z
|
||||
);
|
||||
}
|
||||
camera.yaw = std::to_string(nav.yaw);
|
||||
camera.pitch = std::to_string(nav.pitch);
|
||||
profile.camera = std::move(camera);
|
||||
c.yaw = std::to_string(nav.yaw);
|
||||
c.pitch = std::to_string(nav.pitch);
|
||||
camera = std::move(c);
|
||||
}
|
||||
|
||||
void Profile::setIgnoreUpdates(bool ignoreUpdates) {
|
||||
@@ -463,20 +463,20 @@ void Profile::addAsset(const std::string& path) {
|
||||
}
|
||||
|
||||
const auto it = std::find_if(
|
||||
profile.assets.begin(),
|
||||
profile.assets.end(),
|
||||
[path](const ProfileData::Asset& a) { return a.path == path; }
|
||||
assets.begin(),
|
||||
assets.end(),
|
||||
[path](const Asset& a) { return a.path == path; }
|
||||
);
|
||||
|
||||
if (it != profile.assets.end()) {
|
||||
if (it != assets.end()) {
|
||||
// Asset already existed, so nothing to do here
|
||||
return;
|
||||
}
|
||||
|
||||
ProfileData::Asset a;
|
||||
Asset a;
|
||||
a.path = path;
|
||||
a.type = ProfileData::Asset::Type::Require;
|
||||
profile.assets.push_back(std::move(a));
|
||||
a.type = Asset::Type::Require;
|
||||
assets.push_back(std::move(a));
|
||||
}
|
||||
|
||||
void Profile::removeAsset(const std::string& path) {
|
||||
@@ -485,18 +485,18 @@ void Profile::removeAsset(const std::string& path) {
|
||||
}
|
||||
|
||||
const auto it = std::find_if(
|
||||
profile.assets.begin(),
|
||||
profile.assets.end(),
|
||||
[path](const ProfileData::Asset& a) { return a.path == path; }
|
||||
assets.begin(),
|
||||
assets.end(),
|
||||
[path](const Asset& a) { return a.path == path; }
|
||||
);
|
||||
|
||||
if (it == profile.assets.end()) {
|
||||
if (it == assets.end()) {
|
||||
throw ghoul::RuntimeError(fmt::format(
|
||||
"Tried to remove non-existing asset '{}'", path
|
||||
));
|
||||
}
|
||||
|
||||
profile.assets.erase(it);
|
||||
assets.erase(it);
|
||||
}
|
||||
|
||||
scripting::LuaLibrary Profile::luaLibrary() {
|
||||
@@ -526,13 +526,12 @@ std::string Profile::serialize() const {
|
||||
std::string output;
|
||||
output += fmt::format("{}\n", headerVersion);
|
||||
output += fmt::format(
|
||||
"{}.{}.{}\n",
|
||||
profile.version.major, profile.version.minor, profile.version.patch
|
||||
"{}.{}.{}\n", version.major, version.minor, version.patch
|
||||
);
|
||||
|
||||
if (!profile.modules.empty()) {
|
||||
if (!modules.empty()) {
|
||||
output += fmt::format("\n{}\n", headerModule);
|
||||
for (const ProfileData::Module& m : profile.modules) {
|
||||
for (const Module& m : modules) {
|
||||
output += fmt::format(
|
||||
"{}\t{}\t{}\n",
|
||||
m.name, m.loadedInstruction, m.notLoadedInstruction
|
||||
@@ -540,40 +539,40 @@ std::string Profile::serialize() const {
|
||||
}
|
||||
}
|
||||
|
||||
if (!profile.assets.empty()) {
|
||||
if (!assets.empty()) {
|
||||
output += fmt::format("\n{}\n", headerAsset);
|
||||
for (const ProfileData::Asset& a : profile.assets) {
|
||||
const std::string type = [](ProfileData::Asset::Type t) {
|
||||
for (const Asset& a : assets) {
|
||||
const std::string type = [](Asset::Type t) {
|
||||
switch (t) {
|
||||
case ProfileData::Asset::Type::Require: return "require";
|
||||
case ProfileData::Asset::Type::Request: return "request";
|
||||
default: throw ghoul::MissingCaseException();
|
||||
case Asset::Type::Require: return "require";
|
||||
case Asset::Type::Request: return "request";
|
||||
default: throw ghoul::MissingCaseException();
|
||||
}
|
||||
}(a.type);
|
||||
output += fmt::format("{}\t{}\t{}\n", a.path, type, a.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!profile.properties.empty()) {
|
||||
if (!properties.empty()) {
|
||||
output += fmt::format("\n{}\n", headerProperty);
|
||||
for (const ProfileData::Property& p : profile.properties) {
|
||||
const std::string type = [](ProfileData::Property::SetType t) {
|
||||
for (const Property& p : properties) {
|
||||
const std::string type = [](Property::SetType t) {
|
||||
switch (t) {
|
||||
case ProfileData::Property::SetType::SetPropertyValue:
|
||||
return "setPropertyValue";
|
||||
case ProfileData::Property::SetType::SetPropertyValueSingle:
|
||||
return "setPropertyValueSingle";
|
||||
default:
|
||||
throw ghoul::MissingCaseException();
|
||||
case Property::SetType::SetPropertyValue:
|
||||
return "setPropertyValue";
|
||||
case Property::SetType::SetPropertyValueSingle:
|
||||
return "setPropertyValueSingle";
|
||||
default:
|
||||
throw ghoul::MissingCaseException();
|
||||
}
|
||||
}(p.setType);
|
||||
output += fmt::format("{}\t{}\t{}\n", type, p.name, p.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!profile.keybindings.empty()) {
|
||||
if (!keybindings.empty()) {
|
||||
output += fmt::format("\n{}\n", headerKeybinding);
|
||||
for (const ProfileData::Keybinding& k : profile.keybindings) {
|
||||
for (const Keybinding& k : keybindings) {
|
||||
const std::string local = k.isLocal ? "true" : "false";
|
||||
output += fmt::format(
|
||||
"{}\t{}\t{}\t{}\t{}\t{}\n",
|
||||
@@ -584,28 +583,28 @@ std::string Profile::serialize() const {
|
||||
|
||||
output += fmt::format("\n{}\n", headerTime);
|
||||
{
|
||||
const std::string type = [](ProfileData::Time::Type t) {
|
||||
const std::string type = [](Time::Type t) {
|
||||
switch (t) {
|
||||
case ProfileData::Time::Type::Absolute: return "absolute";
|
||||
case ProfileData::Time::Type::Relative: return "relative";
|
||||
default: throw ghoul::MissingCaseException();
|
||||
case Time::Type::Absolute: return "absolute";
|
||||
case Time::Type::Relative: return "relative";
|
||||
default: throw ghoul::MissingCaseException();
|
||||
}
|
||||
}(profile.time.type);
|
||||
output += fmt::format("{}\t{}\n", type, profile.time.time);
|
||||
}(time.type);
|
||||
output += fmt::format("{}\t{}\n", type, time.time);
|
||||
}
|
||||
|
||||
output += fmt::format("\n{}\n", headerCamera);
|
||||
output += std::visit(
|
||||
overloaded{
|
||||
[](const ProfileData::CameraNavState& camera) {
|
||||
[](const CameraNavState& camera) {
|
||||
return fmt::format(
|
||||
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
|
||||
ProfileData::CameraNavState::Type,
|
||||
CameraNavState::Type,
|
||||
camera.anchor, camera.aim, camera.referenceFrame, camera.position,
|
||||
camera.up, camera.yaw, camera.pitch
|
||||
);
|
||||
},
|
||||
[](const ProfileData::CameraGoToGeo& camera) {
|
||||
[](const Profile::CameraGoToGeo& camera) {
|
||||
std::string altitude;
|
||||
if (camera.altitude.has_value()) {
|
||||
altitude = std::to_string(*camera.altitude);
|
||||
@@ -613,17 +612,17 @@ std::string Profile::serialize() const {
|
||||
|
||||
return fmt::format(
|
||||
"{}\t{}\t{}\t{}\t{}\n",
|
||||
ProfileData::CameraGoToGeo::Type,
|
||||
CameraGoToGeo::Type,
|
||||
camera.anchor, camera.latitude, camera.longitude, altitude
|
||||
);
|
||||
}
|
||||
},
|
||||
profile.camera
|
||||
camera
|
||||
);
|
||||
|
||||
if (!profile.markNodes.empty()) {
|
||||
if (!markNodes.empty()) {
|
||||
output += fmt::format("\n{}\n", headerMarkNodes);
|
||||
for (const std::string& n : profile.markNodes) {
|
||||
for (const std::string& n : markNodes) {
|
||||
output += fmt::format("{}\n", n);
|
||||
}
|
||||
}
|
||||
@@ -648,44 +647,44 @@ Profile::Profile(const std::vector<std::string>& content) {
|
||||
currentSection = parseSection(line, lineNum);
|
||||
break;
|
||||
case Section::Version:
|
||||
profile.version = parseVersion(line, lineNum);
|
||||
version = parseVersion(line, lineNum);
|
||||
foundVersion = true;
|
||||
break;
|
||||
case Section::Module:
|
||||
{
|
||||
ProfileData::Module m = parseModule(line, lineNum);
|
||||
profile.modules.push_back(std::move(m));
|
||||
Module m = parseModule(line, lineNum);
|
||||
modules.push_back(std::move(m));
|
||||
break;
|
||||
}
|
||||
case Section::Asset:
|
||||
{
|
||||
ProfileData::Asset a = parseAsset(line, lineNum);
|
||||
profile.assets.push_back(std::move(a));
|
||||
Asset a = parseAsset(line, lineNum);
|
||||
assets.push_back(std::move(a));
|
||||
break;
|
||||
}
|
||||
case Section::Property:
|
||||
{
|
||||
ProfileData::Property p = parseProperty(line, lineNum);
|
||||
profile.properties.push_back(std::move(p));
|
||||
Property p = parseProperty(line, lineNum);
|
||||
properties.push_back(std::move(p));
|
||||
break;
|
||||
}
|
||||
case Section::Keybinding:
|
||||
{
|
||||
ProfileData::Keybinding kb = parseKeybinding(line, lineNum);
|
||||
profile.keybindings.push_back(std::move(kb));
|
||||
Keybinding kb = parseKeybinding(line, lineNum);
|
||||
keybindings.push_back(std::move(kb));
|
||||
break;
|
||||
}
|
||||
case Section::Time:
|
||||
profile.time = parseTime(line, lineNum);
|
||||
time = parseTime(line, lineNum);
|
||||
break;
|
||||
case Section::Camera:
|
||||
profile.camera = parseCamera(line, lineNum);
|
||||
camera = parseCamera(line, lineNum);
|
||||
foundCamera = true;
|
||||
break;
|
||||
case Section::MarkNodes:
|
||||
{
|
||||
std::string m = parseMarkNodes(line, lineNum);
|
||||
profile.markNodes.push_back(std::move(m));
|
||||
markNodes.push_back(std::move(m));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -712,7 +711,7 @@ std::string Profile::convertToScene() const {
|
||||
std::string output;
|
||||
|
||||
// Modules
|
||||
for (const ProfileData::Module& m : profile.modules) {
|
||||
for (const Module& m : modules) {
|
||||
output += fmt::format(
|
||||
"if openspace.modules.isLoaded(\"{}\") then {} else {} end\n",
|
||||
m.name, m.loadedInstruction, m.notLoadedInstruction
|
||||
@@ -720,14 +719,14 @@ std::string Profile::convertToScene() const {
|
||||
}
|
||||
|
||||
// Assets
|
||||
for (const ProfileData::Asset& a : profile.assets) {
|
||||
for (const Asset& a : assets) {
|
||||
if (!a.name.empty()) {
|
||||
output += fmt::format("local {} = ", a.name);
|
||||
}
|
||||
std::string type = [](ProfileData::Asset::Type t) {
|
||||
std::string type = [](Asset::Type t) {
|
||||
switch (t) {
|
||||
case ProfileData::Asset::Type::Request: return "request";
|
||||
case ProfileData::Asset::Type::Require: return "require";
|
||||
case Asset::Type::Request: return "request";
|
||||
case Asset::Type::Require: return "require";
|
||||
default: throw ghoul::MissingCaseException();
|
||||
}
|
||||
}(a.type);
|
||||
@@ -737,7 +736,7 @@ std::string Profile::convertToScene() const {
|
||||
|
||||
output += "asset.onInitialize(function()\n";
|
||||
// Keybindings
|
||||
for (const ProfileData::Keybinding& k : profile.keybindings) {
|
||||
for (const Keybinding& k : keybindings) {
|
||||
const std::string name = k.name.empty() ? k.key : k.name;
|
||||
output += fmt::format(
|
||||
k.isLocal ?
|
||||
@@ -748,19 +747,19 @@ std::string Profile::convertToScene() const {
|
||||
}
|
||||
|
||||
// Time
|
||||
switch (profile.time.type) {
|
||||
case ProfileData::Time::Type::Absolute:
|
||||
output += fmt::format("openspace.time.setTime(\"{}\")\n", profile.time.time);
|
||||
switch (time.type) {
|
||||
case Time::Type::Absolute:
|
||||
output += fmt::format("openspace.time.setTime(\"{}\")\n", time.time);
|
||||
break;
|
||||
case ProfileData::Time::Type::Relative:
|
||||
case Time::Type::Relative:
|
||||
output += "local now = openspace.time.currentWallTime();\n";
|
||||
output += fmt::format(
|
||||
"local prev = openspace.time.advancedTime(now, \"{}\");\n",
|
||||
profile.time.time
|
||||
time.time
|
||||
);
|
||||
output += "openspace.time.setTime(prev);\n";
|
||||
break;
|
||||
case ProfileData::Time::Type::None:
|
||||
case Time::Type::None:
|
||||
output += "openspace.time.setTime(openspace.time.currentWallTime());\n";
|
||||
break;
|
||||
default:
|
||||
@@ -770,22 +769,22 @@ std::string Profile::convertToScene() const {
|
||||
// Mark Nodes
|
||||
{
|
||||
std::string nodes;
|
||||
for (const std::string& n : profile.markNodes) {
|
||||
for (const std::string& n : markNodes) {
|
||||
nodes += fmt::format("[[ {} ]],", n);
|
||||
}
|
||||
output += fmt::format("openspace.markInterestingNodes({{ {} }});\n", nodes);
|
||||
}
|
||||
|
||||
// Properties
|
||||
for (const ProfileData::Property& p : profile.properties) {
|
||||
for (const Property& p : properties) {
|
||||
switch (p.setType) {
|
||||
case ProfileData::Property::SetType::SetPropertyValue:
|
||||
case Property::SetType::SetPropertyValue:
|
||||
output += fmt::format(
|
||||
"openspace.setPropertyValue(\"{}\", {});\n",
|
||||
p.name, p.value
|
||||
);
|
||||
break;
|
||||
case ProfileData::Property::SetType::SetPropertyValueSingle:
|
||||
case Property::SetType::SetPropertyValueSingle:
|
||||
output += fmt::format(
|
||||
"openspace.setPropertyValueSingle(\"{}\", {});\n",
|
||||
p.name, p.value
|
||||
@@ -799,7 +798,7 @@ std::string Profile::convertToScene() const {
|
||||
// Camera
|
||||
output += std::visit(
|
||||
overloaded{
|
||||
[](const ProfileData::CameraNavState& camera) {
|
||||
[](const CameraNavState& camera) {
|
||||
std::string result;
|
||||
result += "openspace.navigation.setNavigationState({";
|
||||
result += fmt::format("Anchor = {}, ", camera.anchor);
|
||||
@@ -822,7 +821,7 @@ std::string Profile::convertToScene() const {
|
||||
result += "})\n";
|
||||
return result;
|
||||
},
|
||||
[](const ProfileData::CameraGoToGeo& camera) {
|
||||
[](const CameraGoToGeo& camera) {
|
||||
if (camera.altitude.has_value()) {
|
||||
return fmt::format(
|
||||
"openspace.globebrowsing.goToGeo({}, {}, {}, {});\n",
|
||||
@@ -837,7 +836,7 @@ std::string Profile::convertToScene() const {
|
||||
}
|
||||
}
|
||||
},
|
||||
profile.camera
|
||||
camera
|
||||
);
|
||||
output += "end)\n";
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "test_common.h"
|
||||
|
||||
#include "openspace/scene/profile.h"
|
||||
#include "openspace/scene/profilefile.h"
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <iostream>
|
||||
@@ -35,77 +34,112 @@
|
||||
|
||||
using namespace openspace;
|
||||
|
||||
namespace {
|
||||
}
|
||||
constexpr const char* TestProfile1Text = ""
|
||||
"#Version\n"
|
||||
"123.4\n"
|
||||
"\n"
|
||||
"#Module\n"
|
||||
"globebrowsing\t\t\n"
|
||||
"gaia\tprint(\"success.\")\t\n"
|
||||
"volume\t\tquit\n"
|
||||
"\n"
|
||||
"#Asset"
|
||||
"scene/solarsystem/planets/earth/moon/moon\trequire\t\n"
|
||||
"scene/solarsystem/missions/apollo/apollo8\trequest\t\n"
|
||||
"scene/solarsystem/planets/earth/earth\trequire\t\n"
|
||||
"\n"
|
||||
"#Property\n"
|
||||
"setPropertyValue\tNavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance\t20.000000\n"
|
||||
"setPropertyValueSingle\tScene.Pluto.Renderable.Enabled\tfalse\n"
|
||||
"setPropertyValue\tScene.Charon.Renderable.Enabled\tfalse\n"
|
||||
"setPropertyValueSingle\tScene.PlutoBarycenterTrail.Renderable.Enabled\tfalse\n"
|
||||
"\n"
|
||||
"#Keybinding\n"
|
||||
"F8\tSets the time to the approach at Bennu.\tSet Bennu approach time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Approach'); openspace.time.setTime('2018-SEP-11 21:31:01.183')\"\n"
|
||||
"F9\tSets the time to the preliminary survey of Bennu.\tSet Bennu survey time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Preliminary Survey'); openspace.time.setTime('2018-NOV-20 01:13:12.183')\"\n"
|
||||
"F10\tSets the time to the orbital B event.\tSet orbital B event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Orbital B'); openspace.time.setTime('2019-APR-08 10:35:27.186')\"\n"
|
||||
"F11\tSets the time to the recon event.\tSet recon event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Recon'); openspace.time.setTime('2019-MAY-25 03:50:31.195')\"\n"
|
||||
"\n"
|
||||
"#Time\n"
|
||||
"absolute\t1977-12-21T12:51:51.0\n"
|
||||
"\n"
|
||||
"#Camera\n"
|
||||
"setNavigationState\t\"NewHorizons\"\t\t\"Root\"\t-6.572656E1, -7.239404E1, -2.111890E1\t0.102164, -0.362945, 0.926193\t\t\n"
|
||||
"\n"
|
||||
"#MarkNodes\n"
|
||||
"Pluto\n"
|
||||
"NewHorizons\n"
|
||||
"Charon\n";
|
||||
|
||||
testProfileFormat buildTestProfile1() {
|
||||
testProfileFormat tp1;
|
||||
tp1.tsv.push_back("#Version");
|
||||
tp1.tsv.push_back("123.4");
|
||||
tp1.tsm.push_back("#Module");
|
||||
tp1.tsm.push_back("globebrowsing\t\t");
|
||||
tp1.tsm.push_back("gaia\tprint(\"success.\")\t");
|
||||
tp1.tsm.push_back("volume\t\tquit");
|
||||
tp1.tsa.push_back("#Asset");
|
||||
tp1.tsa.push_back("scene/solarsystem/planets/earth/moon/moon\trequired");
|
||||
tp1.tsa.push_back("scene/solarsystem/missions/apollo/apollo8\trequested");
|
||||
tp1.tsa.push_back("scene/solarsystem/planets/earth/earth\t");
|
||||
tp1.tsp.push_back("#Property");
|
||||
tp1.tsp.push_back("setPropertyValue\tNavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance\t20.000000");
|
||||
tp1.tsp.push_back("setPropertyValueSingle\tScene.Pluto.Renderable.Enabled\tfalse");
|
||||
tp1.tsp.push_back("setPropertyValue\tScene.Charon.Renderable.Enabled\tfalse");
|
||||
tp1.tsp.push_back("setPropertyValueSingle\tScene.PlutoBarycenterTrail.Renderable.Enabled\tfalse");
|
||||
tp1.tsk.push_back("#Keybinding");
|
||||
tp1.tsk.push_back("F8\tSets the time to the approach at Bennu.\tSet Bennu approach time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Approach'); openspace.time.setTime('2018-SEP-11 21:31:01.183')\"");
|
||||
tp1.tsk.push_back("F9\tSets the time to the preliminary survey of Bennu.\tSet Bennu survey time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Preliminary Survey'); openspace.time.setTime('2018-NOV-20 01:13:12.183')\"");
|
||||
tp1.tsk.push_back("F10\tSets the time to the orbital B event.\tSet orbital B event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Orbital B'); openspace.time.setTime('2019-APR-08 10:35:27.186')\"");
|
||||
tp1.tsk.push_back("F11\tSets the time to the recon event.\tSet recon event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Recon'); openspace.time.setTime('2019-MAY-25 03:50:31.195')\"");
|
||||
tp1.tst.push_back("#Time");
|
||||
tp1.tst.push_back("absolute\t1977-12-21T12:51:51.0");
|
||||
tp1.tsc.push_back("#Camera");
|
||||
tp1.tsc.push_back("setNavigationState\t\"NewHorizons\"\t\t\"Root\"\t-6.572656E1, -7.239404E1, -2.111890E1\t0.102164, -0.362945, 0.926193\t\t");
|
||||
tp1.tsn.push_back("#MarkNodes");
|
||||
tp1.tsn.push_back("Pluto");
|
||||
tp1.tsn.push_back("NewHorizons");
|
||||
tp1.tsn.push_back("Charon");
|
||||
|
||||
return tp1;
|
||||
}
|
||||
|
||||
std::string stringFromSingleProfileSection(std::vector<std::string>& section,
|
||||
bool blankLineSeparator)
|
||||
{
|
||||
std::string result;
|
||||
for (std::string s : section) {
|
||||
result += s + "\n";
|
||||
}
|
||||
if (blankLineSeparator) {
|
||||
result += "\n";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string stringFromTestProfileFormat(testProfileFormat& tpf) {
|
||||
std::string fullProfile;
|
||||
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsv, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsm, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsa, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsp, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsk, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tst, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsc, true);
|
||||
fullProfile += stringFromSingleProfileSection(tpf.tsn, false);
|
||||
|
||||
return fullProfile;
|
||||
}
|
||||
|
||||
StringPerLineReader::StringPerLineReader(std::string s) : _iss(s) {
|
||||
}
|
||||
|
||||
bool StringPerLineReader::getNextLine(std::string& line) {
|
||||
if (getline(_iss, line))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
//
|
||||
//testProfileFormat buildTestProfile1() {
|
||||
// testProfileFormat tp1;
|
||||
// tp1.tsv.push_back("#Version");
|
||||
// tp1.tsv.push_back("123.4");
|
||||
// tp1.tsm.push_back("#Module");
|
||||
// tp1.tsm.push_back("globebrowsing\t\t");
|
||||
// tp1.tsm.push_back("gaia\tprint(\"success.\")\t");
|
||||
// tp1.tsm.push_back("volume\t\tquit");
|
||||
// tp1.tsa.push_back("#Asset");
|
||||
// tp1.tsa.push_back("scene/solarsystem/planets/earth/moon/moon\trequired");
|
||||
// tp1.tsa.push_back("scene/solarsystem/missions/apollo/apollo8\trequested");
|
||||
// tp1.tsa.push_back("scene/solarsystem/planets/earth/earth\t");
|
||||
// tp1.tsp.push_back("#Property");
|
||||
// tp1.tsp.push_back("setPropertyValue\tNavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance\t20.000000");
|
||||
// tp1.tsp.push_back("setPropertyValueSingle\tScene.Pluto.Renderable.Enabled\tfalse");
|
||||
// tp1.tsp.push_back("setPropertyValue\tScene.Charon.Renderable.Enabled\tfalse");
|
||||
// tp1.tsp.push_back("setPropertyValueSingle\tScene.PlutoBarycenterTrail.Renderable.Enabled\tfalse");
|
||||
// tp1.tsk.push_back("#Keybinding");
|
||||
// tp1.tsk.push_back("F8\tSets the time to the approach at Bennu.\tSet Bennu approach time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Approach'); openspace.time.setTime('2018-SEP-11 21:31:01.183')\"");
|
||||
// tp1.tsk.push_back("F9\tSets the time to the preliminary survey of Bennu.\tSet Bennu survey time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Preliminary Survey'); openspace.time.setTime('2018-NOV-20 01:13:12.183')\"");
|
||||
// tp1.tsk.push_back("F10\tSets the time to the orbital B event.\tSet orbital B event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Orbital B'); openspace.time.setTime('2019-APR-08 10:35:27.186')\"");
|
||||
// tp1.tsk.push_back("F11\tSets the time to the recon event.\tSet recon event time\t/Missions/Osiris Rex\tfalse\t\"openspace.printInfo('Set time: Recon'); openspace.time.setTime('2019-MAY-25 03:50:31.195')\"");
|
||||
// tp1.tst.push_back("#Time");
|
||||
// tp1.tst.push_back("absolute\t1977-12-21T12:51:51.0");
|
||||
// tp1.tsc.push_back("#Camera");
|
||||
// tp1.tsc.push_back("setNavigationState\t\"NewHorizons\"\t\t\"Root\"\t-6.572656E1, -7.239404E1, -2.111890E1\t0.102164, -0.362945, 0.926193\t\t");
|
||||
// tp1.tsn.push_back("#MarkNodes");
|
||||
// tp1.tsn.push_back("Pluto");
|
||||
// tp1.tsn.push_back("NewHorizons");
|
||||
// tp1.tsn.push_back("Charon");
|
||||
//
|
||||
// return tp1;
|
||||
//}
|
||||
//
|
||||
//std::string stringFromSingleProfileSection(std::vector<std::string>& section,
|
||||
// bool blankLineSeparator)
|
||||
//{
|
||||
// std::string result;
|
||||
// for (std::string s : section) {
|
||||
// result += s + "\n";
|
||||
// }
|
||||
// if (blankLineSeparator) {
|
||||
// result += "\n";
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
//
|
||||
//std::string stringFromTestProfileFormat(testProfileFormat& tpf) {
|
||||
// std::string fullProfile;
|
||||
//
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsv, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsm, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsa, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsp, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsk, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tst, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsc, true);
|
||||
// fullProfile += stringFromSingleProfileSection(tpf.tsn, false);
|
||||
//
|
||||
// return fullProfile;
|
||||
//}
|
||||
//
|
||||
//StringPerLineReader::StringPerLineReader(std::string s) : _iss(s) {
|
||||
//}
|
||||
//
|
||||
//bool StringPerLineReader::getNextLine(std::string& line) {
|
||||
// if (getline(_iss, line))
|
||||
// return true;
|
||||
// else
|
||||
// return false;
|
||||
//}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,308 +45,308 @@
|
||||
|
||||
using namespace openspace;
|
||||
|
||||
namespace {
|
||||
int passTest(lua_State* state) {
|
||||
bool* test = reinterpret_cast<bool*>(lua_touserdata(state, lua_upvalueindex(1)));
|
||||
*test = true;
|
||||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class Profile2 : public Profile {
|
||||
public:
|
||||
Profile2(AssetLoader& refAssetLoader) : _assLoader(refAssetLoader) {}
|
||||
std::string currentTimeUTC() const override {
|
||||
return "2020-02-29T01:23:45.00";
|
||||
}
|
||||
interaction::NavigationHandler::NavigationState currentCameraState() const override {
|
||||
interaction::NavigationHandler::NavigationState n;
|
||||
n.anchor = "Earth";
|
||||
n.aim = "Sun";
|
||||
n.referenceFrame = "root";
|
||||
n.position = {-1.0, -2.0, -3.0};
|
||||
n.up = {0.0, 0.0, 1.0};
|
||||
n.pitch = 0.0;
|
||||
n.yaw = 0.0;
|
||||
return n;
|
||||
}
|
||||
void addPropertiesMarkedAsChanged(std::string formattedLine) {
|
||||
_scenegraphProps.push_back(formattedLine);
|
||||
}
|
||||
std::vector<std::string> changedPropertiesFormatted() override {
|
||||
std::vector<std::string> formattedLines;
|
||||
for (std::string s : _scenegraphProps) {
|
||||
formattedLines.push_back(s);
|
||||
}
|
||||
return formattedLines;
|
||||
}
|
||||
bool usingProfile() const override {
|
||||
return true;
|
||||
}
|
||||
std::string initialProfile() const override {
|
||||
return _initProfile;
|
||||
}
|
||||
void setInitialProfile(std::string file) {
|
||||
_initProfile = file;
|
||||
}
|
||||
std::vector<Profile::AssetEvent> assetEvents() const override {
|
||||
return _assLoader.assetEvents();
|
||||
}
|
||||
void setProfileBaseDirectory(std::string dir) {
|
||||
_profileBaseDirectory = dir;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> _scenegraphProps;
|
||||
std::string _initProfile;
|
||||
AssetLoader& _assLoader;
|
||||
};
|
||||
|
||||
static void addLineHeaderForFailureMessage(std::string& s, size_t lineNumber) {
|
||||
s = "@line " + std::to_string(lineNumber) + ": '" + s + "'";
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Convert profileFile to asset", "[profile]") {
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
std::string testFilePath = absPath("${TEMPORARY}/test-profile-convert.profile");
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
|
||||
ProfileFile pf(testFilePath);
|
||||
Profile p;
|
||||
REQUIRE_NOTHROW(
|
||||
p.convertToScene(pf)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Verify conversion to scene", "[profile]") {
|
||||
std::istringstream iss(newHorizonsProfileInput);
|
||||
ProfileFile pf(newHorizonsProfileInput);
|
||||
Profile p;
|
||||
std::string result;
|
||||
REQUIRE_NOTHROW(
|
||||
result = p.convertToScene(pf)
|
||||
);
|
||||
|
||||
if (result != newHorizonsExpectedSceneOutput) {
|
||||
std::string testing, comparing;
|
||||
StringPerLineReader sr_result(result);
|
||||
StringPerLineReader sr_standard(newHorizonsExpectedSceneOutput);
|
||||
|
||||
size_t lineN = 1;
|
||||
while (sr_result.getNextLine(testing)) {
|
||||
sr_standard.getNextLine(comparing);
|
||||
addLineHeaderForFailureMessage(testing, lineN);
|
||||
addLineHeaderForFailureMessage(comparing, lineN);
|
||||
REQUIRE(testing == comparing);
|
||||
lineN++;
|
||||
}
|
||||
//If this fails there are extra lines in the comparison string that weren't in result
|
||||
REQUIRE(sr_standard.getNextLine(comparing) == false);
|
||||
}
|
||||
//REQUIRE(result == newHorizonsExpectedSceneOutput);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect new properties", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
p.addPropertiesMarkedAsChanged("initialized 1st\t123");
|
||||
p.addPropertiesMarkedAsChanged("initialized 2nd\t3.14159");
|
||||
p.addPropertiesMarkedAsChanged("initialized 3rd\ttested.");
|
||||
p.addPropertiesMarkedAsChanged("initialized fourth\tfalse.");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedPropsResult_1);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect new added assets", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("initialization");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test2");
|
||||
asset2->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test3");
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_1);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect new added assets after reset", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("initialization");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test2");
|
||||
asset2->initialize();
|
||||
assetLoader.resetAssetEvents();
|
||||
std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test3");
|
||||
asset3->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset4 = assetLoader.add("test4");
|
||||
asset4->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_2);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect repeat added assets from new", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
asset2->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test2");
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_3);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect repeat added assets from base", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
asset2->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("scene/solarsystem/planets/earth/earth");
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_4);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect removed assets not already loaded", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
asset2->initialize();
|
||||
assetLoader.remove("test5");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_5);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect removed assets from already loaded", "[profile]") {
|
||||
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
openspace::SynchronizationWatcher syncWatcher;
|
||||
AssetLoader assetLoader(
|
||||
state,
|
||||
&syncWatcher,
|
||||
FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
);
|
||||
|
||||
bool passed;
|
||||
lua_pushlightuserdata(*state, &passed);
|
||||
lua_pushcclosure(*state, &passTest, 1);
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
asset->initialize();
|
||||
std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
asset2->initialize();
|
||||
assetLoader.remove("scene/solarsystem/planets/earth/earth");
|
||||
assetLoader.remove("scene/solarsystem/planets/earth/satellites/satellites");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_6);
|
||||
}
|
||||
//namespace {
|
||||
// int passTest(lua_State* state) {
|
||||
// bool* test = reinterpret_cast<bool*>(lua_touserdata(state, lua_upvalueindex(1)));
|
||||
// *test = true;
|
||||
// return 0;
|
||||
// }
|
||||
//} // namespace
|
||||
//
|
||||
//class Profile2 : public Profile {
|
||||
//public:
|
||||
// Profile2(AssetLoader& refAssetLoader) : _assLoader(refAssetLoader) {}
|
||||
// std::string currentTimeUTC() const override {
|
||||
// return "2020-02-29T01:23:45.00";
|
||||
// }
|
||||
// interaction::NavigationHandler::NavigationState currentCameraState() const override {
|
||||
// interaction::NavigationHandler::NavigationState n;
|
||||
// n.anchor = "Earth";
|
||||
// n.aim = "Sun";
|
||||
// n.referenceFrame = "root";
|
||||
// n.position = {-1.0, -2.0, -3.0};
|
||||
// n.up = {0.0, 0.0, 1.0};
|
||||
// n.pitch = 0.0;
|
||||
// n.yaw = 0.0;
|
||||
// return n;
|
||||
// }
|
||||
// void addPropertiesMarkedAsChanged(std::string formattedLine) {
|
||||
// _scenegraphProps.push_back(formattedLine);
|
||||
// }
|
||||
// std::vector<std::string> changedPropertiesFormatted() override {
|
||||
// std::vector<std::string> formattedLines;
|
||||
// for (std::string s : _scenegraphProps) {
|
||||
// formattedLines.push_back(s);
|
||||
// }
|
||||
// return formattedLines;
|
||||
// }
|
||||
// bool usingProfile() const override {
|
||||
// return true;
|
||||
// }
|
||||
// std::string initialProfile() const override {
|
||||
// return _initProfile;
|
||||
// }
|
||||
// void setInitialProfile(std::string file) {
|
||||
// _initProfile = file;
|
||||
// }
|
||||
// std::vector<Profile::AssetEvent> assetEvents() const override {
|
||||
// return _assLoader.assetEvents();
|
||||
// }
|
||||
// void setProfileBaseDirectory(std::string dir) {
|
||||
// _profileBaseDirectory = dir;
|
||||
// }
|
||||
//private:
|
||||
// std::vector<std::string> _scenegraphProps;
|
||||
// std::string _initProfile;
|
||||
// AssetLoader& _assLoader;
|
||||
//};
|
||||
//
|
||||
//static void addLineHeaderForFailureMessage(std::string& s, size_t lineNumber) {
|
||||
// s = "@line " + std::to_string(lineNumber) + ": '" + s + "'";
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Convert profileFile to asset", "[profile]") {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// std::string testFilePath = absPath("${TEMPORARY}/test-profile-convert.profile");
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
//
|
||||
// ProfileFile pf(testFilePath);
|
||||
// Profile p;
|
||||
// REQUIRE_NOTHROW(
|
||||
// p.convertToScene(pf)
|
||||
// );
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Verify conversion to scene", "[profile]") {
|
||||
// std::istringstream iss(newHorizonsProfileInput);
|
||||
// ProfileFile pf(newHorizonsProfileInput);
|
||||
// Profile p;
|
||||
// std::string result;
|
||||
// REQUIRE_NOTHROW(
|
||||
// result = p.convertToScene(pf)
|
||||
// );
|
||||
//
|
||||
// if (result != newHorizonsExpectedSceneOutput) {
|
||||
// std::string testing, comparing;
|
||||
// StringPerLineReader sr_result(result);
|
||||
// StringPerLineReader sr_standard(newHorizonsExpectedSceneOutput);
|
||||
//
|
||||
// size_t lineN = 1;
|
||||
// while (sr_result.getNextLine(testing)) {
|
||||
// sr_standard.getNextLine(comparing);
|
||||
// addLineHeaderForFailureMessage(testing, lineN);
|
||||
// addLineHeaderForFailureMessage(comparing, lineN);
|
||||
// REQUIRE(testing == comparing);
|
||||
// lineN++;
|
||||
// }
|
||||
// //If this fails there are extra lines in the comparison string that weren't in result
|
||||
// REQUIRE(sr_standard.getNextLine(comparing) == false);
|
||||
// }
|
||||
// //REQUIRE(result == newHorizonsExpectedSceneOutput);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect new properties", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// p.addPropertiesMarkedAsChanged("initialized 1st\t123");
|
||||
// p.addPropertiesMarkedAsChanged("initialized 2nd\t3.14159");
|
||||
// p.addPropertiesMarkedAsChanged("initialized 3rd\ttested.");
|
||||
// p.addPropertiesMarkedAsChanged("initialized fourth\tfalse.");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedPropsResult_1);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect new added assets", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("initialization");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test2");
|
||||
// asset2->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test3");
|
||||
// asset3->initialize();
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_1);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect new added assets after reset", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("initialization");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test2");
|
||||
// asset2->initialize();
|
||||
// assetLoader.resetAssetEvents();
|
||||
// std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test3");
|
||||
// asset3->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset4 = assetLoader.add("test4");
|
||||
// asset4->initialize();
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_2);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect repeat added assets from new", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
// asset2->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("test2");
|
||||
// asset3->initialize();
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_3);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect repeat added assets from base", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
// asset2->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset3 = assetLoader.add("scene/solarsystem/planets/earth/earth");
|
||||
// asset3->initialize();
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_4);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect removed assets not already loaded", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
// asset2->initialize();
|
||||
// assetLoader.remove("test5");
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_5);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profile: Detect removed assets from already loaded", "[profile]") {
|
||||
// openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
|
||||
// ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
|
||||
// openspace::SynchronizationWatcher syncWatcher;
|
||||
// AssetLoader assetLoader(
|
||||
// state,
|
||||
// &syncWatcher,
|
||||
// FileSys.absolutePath("${TESTDIR}/profile/")
|
||||
// );
|
||||
//
|
||||
// bool passed;
|
||||
// lua_pushlightuserdata(*state, &passed);
|
||||
// lua_pushcclosure(*state, &passTest, 1);
|
||||
// lua_setglobal(*state, "passTest");
|
||||
//
|
||||
// std::shared_ptr<openspace::Asset> asset = assetLoader.add("test2");
|
||||
// asset->initialize();
|
||||
// std::shared_ptr<openspace::Asset> asset2 = assetLoader.add("test4");
|
||||
// asset2->initialize();
|
||||
// assetLoader.remove("scene/solarsystem/planets/earth/earth");
|
||||
// assetLoader.remove("scene/solarsystem/planets/earth/satellites/satellites");
|
||||
//
|
||||
// Profile2 p(assetLoader);
|
||||
// p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
// p.setInitialProfile("test2");
|
||||
// std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
// REQUIRE(output == detectChangedAssetsResult_6);
|
||||
//}
|
||||
|
||||
@@ -24,188 +24,184 @@
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include "openspace/scene/profilefile.h"
|
||||
#include "test_common.h"
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace openspace;
|
||||
//using namespace openspace;
|
||||
|
||||
namespace {
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Simple read and verify", "[profileFile]") {
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
std::string testFile = absPath("${TEMPORARY}/profile-test-simple");
|
||||
{
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
std::ofstream f(testFile);
|
||||
f << testFull_string;
|
||||
}
|
||||
|
||||
ProfileFile pf(testFile);
|
||||
|
||||
std::vector<std::string> tVect;
|
||||
|
||||
REQUIRE(pf.version() == test.tsv[1]);
|
||||
REQUIRE(pf.time() == test.tst[1]);
|
||||
REQUIRE(pf.camera() == test.tsc[1]);
|
||||
tVect = pf.modules();
|
||||
REQUIRE(tVect[0] == test.tsm[1]);
|
||||
REQUIRE(tVect[1] == test.tsm[2]);
|
||||
REQUIRE(tVect[2] == test.tsm[3]);
|
||||
tVect = pf.assets();
|
||||
REQUIRE(tVect[0] == test.tsa[1]);
|
||||
REQUIRE(tVect[1] == test.tsa[2]);
|
||||
REQUIRE(tVect[2] == test.tsa[3]);
|
||||
tVect = pf.properties();
|
||||
REQUIRE(tVect[0] == test.tsp[1]);
|
||||
REQUIRE(tVect[1] == test.tsp[2]);
|
||||
REQUIRE(tVect[2] == test.tsp[3]);
|
||||
REQUIRE(tVect[3] == test.tsp[4]);
|
||||
tVect = pf.keybindings();
|
||||
REQUIRE(tVect[0] == test.tsk[1]);
|
||||
REQUIRE(tVect[1] == test.tsk[2]);
|
||||
REQUIRE(tVect[2] == test.tsk[3]);
|
||||
REQUIRE(tVect[3] == test.tsk[4]);
|
||||
tVect = pf.markNodes();
|
||||
REQUIRE(tVect[0] == test.tsn[1]);
|
||||
REQUIRE(tVect[1] == test.tsn[2]);
|
||||
REQUIRE(tVect[2] == test.tsn[3]);
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Unrecognized header", "[profileFile]") {
|
||||
std::string testFilePath = absPath("${TEMPORARY}/test-profile-unrec-header.profile");
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tsa[0] = "#Azzet";
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("Invalid section header") &&
|
||||
Catch::Matchers::Contains("#Azzet")
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Bad number of fields", "[profileFile]") {
|
||||
{
|
||||
std::string testFilePath = absPath(
|
||||
"${TEMPORARY}/test-profile-bad-n-fields-1.profile"
|
||||
);
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tsm[1] = "globebrowsing\t\t\t";
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("fields required in a Module entry")
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
std::string testFilePath = absPath(
|
||||
"${TEMPORARY}/test-profile-bad-n-fields-2.profile"
|
||||
);
|
||||
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tsm[1] = "globebrowsing\t\t";
|
||||
test.tsc[1] = "setNavigationState\t\"NewHorizons\"\t\"Root\"\t-6.572656E1, -7.239404E1, -2.111890E1\t0.102164, -0.362945, 0.926193\t\t";
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("fields required in Camera entry")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Too many lines in time entry", "[profileFile]") {
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tst.push_back("relative\t\"-1 day\"");
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
std::string testFilePath = absPath(
|
||||
"${TEMPORARY}/test-profile-too-many-lines-time.profile"
|
||||
);
|
||||
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
{
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("Too many lines in time section")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Required field missing", "[profileFile]") {
|
||||
{
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tsc[1] = "setNavigationState\t\"NewHorizons\"\ttest\t\"Root\"\t\t0.102164, -0.362945, 0.926193\t\t";
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
std::string testFilePath = absPath(
|
||||
"${TEMPORARY}/test-profile-required-field-missing-1.profile"
|
||||
);
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
|
||||
{
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("Camera navigation setNavigationState position vector(arg 4/8) is required")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
test.tsc[1] = "setNavigationState\t\"NewHorizons\"\t\t\"Root\"\t1, 2, 3\t0.102164, -0.362945, 0.926193\t\t";
|
||||
test.tsk[3] = "F10\tSets the time to the orbital B event.\tSet orbital B event time\t/Missions/Osiris Rex\t\t\"openspace.printInfo('Set time: Orbital B'); openspace.time.setTime('2019-APR-08 10:35:27.186')\"";
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
std::string testFilePath = absPath(
|
||||
"${TEMPORARY}/test-profile-required-field-missing-2.profile"
|
||||
);
|
||||
{
|
||||
std::ofstream testFile(testFilePath);
|
||||
testFile << testFull_string;
|
||||
}
|
||||
{
|
||||
ProfileFile pf("default.profile");
|
||||
REQUIRE_THROWS_WITH(
|
||||
ProfileFile(testFilePath),
|
||||
Catch::Matchers::Contains("Keybinding local(T/F)(arg 4/6) is required")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("profileFile: Write test", "[profileFile]") {
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
std::string testFile = absPath("${TEMPORARY}/profile-test-write-test");
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
{
|
||||
std::ofstream f(testFile);
|
||||
f << testFull_string;
|
||||
}
|
||||
|
||||
ProfileFile pf(testFile);
|
||||
|
||||
std::string result = serialize(pf.profile);
|
||||
REQUIRE(testFull_string == result);
|
||||
}
|
||||
//TEST_CASE("profileFile: Simple read and verify", "[profileFile]") {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// std::string testFile = absPath("${TEMPORARY}/profile-test-simple");
|
||||
// {
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// std::ofstream f(testFile);
|
||||
// f << testFull_string;
|
||||
// }
|
||||
//
|
||||
// ProfileFile pf(testFile);
|
||||
//
|
||||
// std::vector<std::string> tVect;
|
||||
//
|
||||
// REQUIRE(pf.version() == test.tsv[1]);
|
||||
// REQUIRE(pf.time() == test.tst[1]);
|
||||
// REQUIRE(pf.camera() == test.tsc[1]);
|
||||
// tVect = pf.modules();
|
||||
// REQUIRE(tVect[0] == test.tsm[1]);
|
||||
// REQUIRE(tVect[1] == test.tsm[2]);
|
||||
// REQUIRE(tVect[2] == test.tsm[3]);
|
||||
// tVect = pf.assets();
|
||||
// REQUIRE(tVect[0] == test.tsa[1]);
|
||||
// REQUIRE(tVect[1] == test.tsa[2]);
|
||||
// REQUIRE(tVect[2] == test.tsa[3]);
|
||||
// tVect = pf.properties();
|
||||
// REQUIRE(tVect[0] == test.tsp[1]);
|
||||
// REQUIRE(tVect[1] == test.tsp[2]);
|
||||
// REQUIRE(tVect[2] == test.tsp[3]);
|
||||
// REQUIRE(tVect[3] == test.tsp[4]);
|
||||
// tVect = pf.keybindings();
|
||||
// REQUIRE(tVect[0] == test.tsk[1]);
|
||||
// REQUIRE(tVect[1] == test.tsk[2]);
|
||||
// REQUIRE(tVect[2] == test.tsk[3]);
|
||||
// REQUIRE(tVect[3] == test.tsk[4]);
|
||||
// tVect = pf.markNodes();
|
||||
// REQUIRE(tVect[0] == test.tsn[1]);
|
||||
// REQUIRE(tVect[1] == test.tsn[2]);
|
||||
// REQUIRE(tVect[2] == test.tsn[3]);
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profileFile: Unrecognized header", "[profileFile]") {
|
||||
// std::string testFilePath = absPath("${TEMPORARY}/test-profile-unrec-header.profile");
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tsa[0] = "#Azzet";
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
//
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("Invalid section header") &&
|
||||
// Catch::Matchers::Contains("#Azzet")
|
||||
// );
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profileFile: Bad number of fields", "[profileFile]") {
|
||||
// {
|
||||
// std::string testFilePath = absPath(
|
||||
// "${TEMPORARY}/test-profile-bad-n-fields-1.profile"
|
||||
// );
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tsm[1] = "globebrowsing\t\t\t";
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("fields required in a Module entry")
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// std::string testFilePath = absPath(
|
||||
// "${TEMPORARY}/test-profile-bad-n-fields-2.profile"
|
||||
// );
|
||||
//
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tsm[1] = "globebrowsing\t\t";
|
||||
// test.tsc[1] = "setNavigationState\t\"NewHorizons\"\t\"Root\"\t-6.572656E1, -7.239404E1, -2.111890E1\t0.102164, -0.362945, 0.926193\t\t";
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
//
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("fields required in Camera entry")
|
||||
// );
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profileFile: Too many lines in time entry", "[profileFile]") {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tst.push_back("relative\t\"-1 day\"");
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// std::string testFilePath = absPath(
|
||||
// "${TEMPORARY}/test-profile-too-many-lines-time.profile"
|
||||
// );
|
||||
//
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
// {
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("Too many lines in time section")
|
||||
// );
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profileFile: Required field missing", "[profileFile]") {
|
||||
// {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tsc[1] = "setNavigationState\t\"NewHorizons\"\ttest\t\"Root\"\t\t0.102164, -0.362945, 0.926193\t\t";
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// std::string testFilePath = absPath(
|
||||
// "${TEMPORARY}/test-profile-required-field-missing-1.profile"
|
||||
// );
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("Camera navigation setNavigationState position vector(arg 4/8) is required")
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// test.tsc[1] = "setNavigationState\t\"NewHorizons\"\t\t\"Root\"\t1, 2, 3\t0.102164, -0.362945, 0.926193\t\t";
|
||||
// test.tsk[3] = "F10\tSets the time to the orbital B event.\tSet orbital B event time\t/Missions/Osiris Rex\t\t\"openspace.printInfo('Set time: Orbital B'); openspace.time.setTime('2019-APR-08 10:35:27.186')\"";
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// std::string testFilePath = absPath(
|
||||
// "${TEMPORARY}/test-profile-required-field-missing-2.profile"
|
||||
// );
|
||||
// {
|
||||
// std::ofstream testFile(testFilePath);
|
||||
// testFile << testFull_string;
|
||||
// }
|
||||
// {
|
||||
// ProfileFile pf("default.profile");
|
||||
// REQUIRE_THROWS_WITH(
|
||||
// ProfileFile(testFilePath),
|
||||
// Catch::Matchers::Contains("Keybinding local(T/F)(arg 4/6) is required")
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//TEST_CASE("profileFile: Write test", "[profileFile]") {
|
||||
// testProfileFormat test = buildTestProfile1();
|
||||
// std::string testFile = absPath("${TEMPORARY}/profile-test-write-test");
|
||||
// std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
// {
|
||||
// std::ofstream f(testFile);
|
||||
// f << testFull_string;
|
||||
// }
|
||||
//
|
||||
// ProfileFile pf(testFile);
|
||||
//
|
||||
// std::string result = serialize(pf.profile);
|
||||
// REQUIRE(testFull_string == result);
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user