|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <string>
- #include "ctx.h"
- #include "memory_Context.h"
- #include <iostream>
-
- std::string s(const char *str) {
- return std::string(str);
- }
-
- std::string test_ctx_Controller_executeFunctions_set() {
- auto c = memory_createContext();
- ctx_Controller<memory_Context> ctrl(c);
- // Disable automatic invocation of executeFunctions.
- ctrl.isProcessingQueue = true;
- ctrl.set("input", s("123"));
-
- auto processInput = [](memory_Context c) -> memory_Context {
- if (c.recentField == "input") {
- c.outputHelp = "Checked";
- c.recentField = "outputHelp";
- return c;
- }
- c.recentField = "none";
- return c;
- };
-
- ctrl.registerFunction(processInput);
- // Apply 'input'.
- ctrl.executeFunctions();
- // Apply 'outputHelp'.
- ctrl.executeFunctions();
- if (
- ctrl.context.input == "123" &&
- ctrl.context.outputHelp == "Checked"
- ) {
- return "OK: ctx_Controller_executeFunctions_set";
- }
- return "ERR: ctx_Controller_executeFunctions_set";
- }
-
- std::string test_ctx_Controller_processQueue() {
- auto c = memory_createContext();
- ctx_Controller<memory_Context> ctrl(c);
-
- auto processInput = [](memory_Context c) -> memory_Context {
- if (c.recentField == "input") {
- c.outputHelp = "Checked";
- c.recentField = "outputHelp";
- return c;
- }
- c.recentField = "none";
- return c;
- };
-
- ctrl.registerFunction(processInput);
- ctrl.set("input", s("abc"));
- if (
- ctrl.context.input == "abc" &&
- ctrl.context.outputHelp == "Checked"
- ) {
- return "OK: ctx_Controller_processQueue";
- }
- return "ERR: ctx_Controller_processQueue";
- }
-
|