if (tmp.failure) throw *tmp.failure;
}
+namespace std
+{
+ template <> struct hash<std::pair<EvaluationValue::Kind, std::string>> {
+ size_t operator()(const std::pair<EvaluationValue::Kind, std::string> &p) const
+ {
+ return std::hash<std::string>()(p.second) ^ (unsigned char)p.first;
+ }
+ };
+}
+
struct TestExecutor : ExecutorInterface {
NavigationInterface::CallbackHandle contextChangedHandle;
std::shared_ptr<UIElement> root;
std::shared_ptr<NavigationElement> navigationContext;
std::unordered_map<std::string, EvaluationValue> variables;
+ std::unordered_map<std::pair<EvaluationValue::Kind, std::string>, std::function<EvaluationValue(const EvaluationValue &, EvaluationValue)>> setters;
+ std::unordered_map<std::pair<EvaluationValue::Kind, std::string>, std::function<EvaluationValue(const EvaluationValue &)>> getters;
std::mutex mt;
std::ostream &output;
return it->second;
throw EvaluationFailure{} << "unknown variable '" << name << "'";
}
+
+ EvaluationValue setAttribute(const EvaluationValue &self, const std::string &name, EvaluationValue value)
+ {
+ auto it = setters.find({ self.kind(), name });
+ if (it != setters.end()) {
+ return it->second(self, std::move(value));
+ }
+ return ExecutorInterface::setAttribute(self, name, std::move(value));
+ }
+
+ EvaluationValue getAttribute(const EvaluationValue &self, const std::string &name)
+ {
+ auto it = getters.find({ self.kind(), name });
+ if (it != getters.end()) {
+ return it->second(self);
+ }
+ return ExecutorInterface::getAttribute(self, name);
+ }
+
std::shared_ptr<UIElement> getVisibleRoot() override
{
std::lock_guard<std::mutex> lock(mt);