void testInfo() { // Help. // ===== { StartsWith output("Show description "); testCommand("info -h", EXIT_SUCCESS, output); testCommand("info -help", EXIT_SUCCESS, output); } // Error messages. // =============== testCommand("info x", EXIT_FAILURE, "No registered class with name 'x'. " "Did you intend to load a plugin?\n"); testCommand("info x y", EXIT_FAILURE, "No registered class with name 'x'. " "Did you intend to load a plugin?\n"); testCommand("info Body y", EXIT_FAILURE, "No property with name 'y' found in class 'Body'.\n"); // Successful input. // ================= testCommand("info", EXIT_SUCCESS, StartsWith("REGISTERED CLASSES ")); testCommand("info PathSpring", EXIT_SUCCESS, StartsWith("\nPROPERTIES FOR PathSpring")); testCommand("info Body mass", EXIT_SUCCESS, "\nBody.mass\nThe mass of the body (kg)\n"); // Library option. // =============== testLoadPluginLibraries("info"); }
int main (void) { // print infos printf("Raspberry Pi I2C Arduino Sample\n"); printf("========================================\n"); // initialize buffer buffer[0] = 0x00; // address of i2c Arduino device int deviceI2CAddress = 0x2A; // (0x2A = 42) // open device on /dev/i2c-0 if ((deviceHandle = open("/dev/i2c-0", O_RDWR)) < 0) { printf("Error: Couldn't open device! %d\n", deviceHandle); return 1; } // connect to arduino as i2c slave if (ioctl(deviceHandle, I2C_SLAVE, deviceI2CAddress) < 0) { printf("Error: Couldn't find arduino on address!\n"); return 1; } // begin transmission and request acknowledgement readBytes = write(deviceHandle, buffer, 1); if (readBytes != 1) { printf("Error: Received no ACK-Bit, couldn't established connection!"); } else { // drive some tests testCommand("L11", "LED1 on"); usleep(2000000); // 2s testCommand("L10", "LED1 off"); usleep(2000000); // 2s testCommand("L21", "LED2 on"); usleep(2000000); // 2s testCommand("L20", "LED2 off"); usleep(2000000); // 2s testCommand("L31", "LED3 on"); usleep(2000000); // 2s testCommand("L30", "LED3 off"); usleep(2000000); // 2s testCommand("R11", "Relay on"); usleep(2000000); // 2s testCommand("R10", "Relay off"); } // close connection and return close(deviceHandle); return 0; }
void testRunTool() { // Help. // ===== { StartsWith output("Run a tool "); testCommand("run-tool -h", EXIT_SUCCESS, output); testCommand("run-tool -help", EXIT_SUCCESS, output); } // Error messages. // =============== testCommand("run-tool", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("run-tool putes.xml", EXIT_FAILURE, StartsWith("SimTK Exception thrown at")); // We use print-xml to create a setup file that we can try to run. // (We are not really trying to test print-xml right now.) testCommand("print-xml cmc testruntool_cmc_setup.xml", EXIT_SUCCESS, "Printing 'testruntool_cmc_setup.xml'.\n"); // This fails because this setup file doesn't have much in it. testCommand("run-tool testruntool_cmc_setup.xml", EXIT_FAILURE, std::regex(RE_ANY + "(No model file was specified)" + RE_ANY)); // Similar to the previous two commands, except for scaling // (since ScaleTool goes through a different branch of the code). testCommand("print-xml scale testruntool_scale_setup.xml", EXIT_SUCCESS, "Printing 'testruntool_scale_setup.xml'.\n"); // This fails because this setup file doesn't have much in it. testCommand("run-tool testruntool_scale_setup.xml", EXIT_FAILURE, std::regex("(Preparing to run ScaleTool.)" + RE_ANY + "(Processing subject default)" + RE_ANY)); // Now we'll try loading a valid OpenSim XML file that is *not* a Tool // setup file, and we get a helpful error. // (We are not really trying to test print-xml right now.) testCommand("print-xml Model testruntool_Model.xml", EXIT_SUCCESS, "Printing 'testruntool_Model.xml'.\n"); testCommand("run-tool testruntool_Model.xml", EXIT_FAILURE, "The provided file 'testruntool_Model.xml' does not define " "an OpenSim Tool. Did you intend to load a plugin?\n"); // Library option. // =============== testLoadPluginLibraries("run-tool"); }
void Application::initQML() { /** A QML-Cpp kommunikációhoz használt QMLData obejktumokat létre kell * hozni a QML felület számára.*/ QMap<QString,QMLData>::iterator iter; for(iter = qmlDataMap.begin(); iter != qmlDataMap.end(); ++iter) { engine.rootContext()->setContextProperty(iter.key(), &iter.value()); } engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qWarning() << "HIBA: Nem sikerült létrehozni a QML környezetet."; } rootObject = rootObjects.first(); customPlotPtr = (QCustomPlot*)rootObject->findChild<QObject*>("customPlot"); auto mainWindowPtr = rootObject->findChild<QObject*>("MainWindow"); eventhandler.setMainWindowPtr(mainWindowPtr); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), &eventhandler, SLOT(connectCommand())); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), this, SLOT(connectToServer())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), &eventhandler, SLOT(hvEnableCommand())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), this, SLOT(hvenCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), &eventhandler, SLOT(driveEnableCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), this, SLOT(drenCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &eventhandler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), this, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), this, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(vdemandSliderChanged(QVariant )), this, SLOT(vdemandChanged(QVariant ))); }
MainApplication::MainApplication(int argc, char *argv[]) : QApplication(argc, argv), simulator(12345), engine(), history(), communication(), robot(history, communication), handler(robot, *engine.rootContext(), history) { // Szimulátor indítása simulator.start(0.3F); // Csatlakozás a szimulátorhoz. communication.connect(QStringLiteral("localhost"),12345); // Szimulálunk egy history változást, mert attól kezdve léteznek a QML oldalon // a C++ oldalról származó változók. (Különben referencia hibákat kapnánk a QML oldalon // egészen addig, amíg az első üzenet meg nem jönne a szimulátortól. //handler.historyChanged(); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // A QML gyökérelemre szükségünk van ahhoz, hogy tudjunk hivatkozni a QML-es elemekre. auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qDebug() << "HIBA: Nem sikerült létrehozni a QML környezetet."; return; } // A QML környezet is felállt, bekötjük a signalokat a QML és C++ oldal között. QObject *rootObject = rootObjects[0]; // A handler beköti a saját signaljait. handler.ConnectQmlSignals(rootObject); // Bekötjük a nyomógombok signaljait. QObject::connect(rootObject, SIGNAL(resetCommandCpp()), &handler, SLOT(resetCommand())); QObject::connect(rootObject, SIGNAL(accelerateXCommandCpp()), &handler, SLOT(accelerateXCommand())); QObject::connect(rootObject, SIGNAL(accelerateYCommandCpp()), &handler, SLOT(accelerateYCommand())); QObject::connect(rootObject, SIGNAL(slowDownXCommandCpp()), &handler, SLOT(slowDownXCommand())); QObject::connect(rootObject, SIGNAL(slowDownYCommandCpp()), &handler, SLOT(slowDownYCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &handler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), &handler, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(defaultCommandCpp()), &handler, SLOT(defaultCommand())); }
int main(int argc, const char **argv) { printf("Running all tests...\n\n"); //**** core tests testTree(); testParse(); testDef(); testWord(); testFlow(); testVM(); testStack(); testInit(); testCommand(); testConversation(); testScape(); // testThreads(); //**** builtins tests testNoun(); testPattern(); //testArray(); // testStream(); testInt(); testStr255(); testCfunc(); testReceptorUtil(); // testReceptor(); //testVmHost(); //**** examples test testPoint(); // testLine(); report_tests(); return 0; }
void testUpdateFile() { // Help. // ===== { StartsWith output("Update an .osim, .xml "); testCommand("update-file -h", EXIT_SUCCESS, output); testCommand("update-file -help", EXIT_SUCCESS, output); } // Error messages. // =============== // Syntax errors. testCommand("update-file", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("update-file x", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("update-file x.doc", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("update-file x.xml", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("update-file x y", EXIT_FAILURE, "Input file 'x' does not have an extension.\n"); testCommand("update-file x.doc y", EXIT_FAILURE, "Input file 'x.doc' has an unrecognized extension.\n"); // File does not exist. testCommand("update-file x.xml y", EXIT_FAILURE, std::regex("(?:Loading input file 'x.xml')" + RE_ANY + "(?:Could not make object from file 'x.xml'.\n" + "Did you intend to load a plugin (with --library)?)" + RE_ANY)); testCommand("update-file x.osim y", EXIT_FAILURE, std::regex("(?:Loading input file 'x.osim')" + RE_ANY + "(?:Could not make object from file 'x.osim'.\n" + "Did you intend to load a plugin (with --library)?)" + RE_ANY)); testCommand("update-file x.sto y", EXIT_FAILURE, std::regex("(Loading input file 'x.sto')" + RE_ANY + "(Storage: Failed to open file 'x.sto')" + RE_ANY)); // Successful input. // ================= // We use print-xml to create a file that we can try to update. // (We are not really trying to test print-xml right now.) testCommand("print-xml Model testupdatefile_Model.osim", EXIT_SUCCESS, "Printing 'testupdatefile_Model.osim'.\n"); testCommand("update-file testupdatefile_Model.osim " "testupdatefile_Model_updated.osim", EXIT_SUCCESS, "Loading input file 'testupdatefile_Model.osim'.\n" "Printing updated file to 'testupdatefile_Model_updated.osim'.\n"); // Library option. // =============== testLoadPluginLibraries("update-file"); }
void testPrintXML() { // Help. // ===== { StartsWith output("Print a template XML file "); testCommand("print-xml -h", EXIT_SUCCESS, output); testCommand("print-xml -help", EXIT_SUCCESS, output); } // Error messages. // =============== testCommand("print-xml", EXIT_FAILURE, StartsWith("Arguments did not match expected patterns")); testCommand("print-xml x y z", EXIT_FAILURE, StartsWith("Unexpected argument: print-xml, x, y, z")); testCommand("print-xml bleepbloop", EXIT_FAILURE, "There is no tool or registered concrete class named 'bleepbloop'.\n" "Did you intend to load a plugin (with --library)?\n"); testCommand("print-xml bleepbloop y", EXIT_FAILURE, "There is no tool or registered concrete class named 'bleepbloop'.\n" "Did you intend to load a plugin (with --library)?\n"); // Successful input. // ================= testCommand("print-xml cmc", EXIT_SUCCESS, "Printing 'default_Setup_CMCTool.xml'.\n"); testCommand("print-xml Millard2012EquilibriumMuscle", EXIT_SUCCESS, "Printing 'default_Millard2012EquilibriumMuscle.xml'.\n"); testCommand("print-xml cmc default_cmc_setup.xml", EXIT_SUCCESS, "Printing 'default_cmc_setup.xml'.\n"); // Tool names are case-insensitive. // ================================ testCommand("print-xml CmC", EXIT_SUCCESS, "Printing 'default_Setup_CMCTool.xml'.\n"); testCommand("print-xml FORwarD", EXIT_SUCCESS, "Printing 'default_Setup_ForwardTool.xml'.\n"); testCommand("print-xml Analyze default_analyze_setup.xml", EXIT_SUCCESS, "Printing 'default_analyze_setup.xml'.\n"); // Library option. // =============== testLoadPluginLibraries("print-xml"); }
void testLoadPluginLibraries(const std::string& subcommand) { const auto cmd = subcommand + " -h"; // Nonexistent file. // ================= { std::regex output(RE_ANY + "(Failed to load library x)\n"); // These are all valid ways of specifying libraries. testCommand("-L x " + cmd, EXIT_FAILURE, output); testCommand("-Lx " + cmd, EXIT_FAILURE, output); testCommand("--library x " + cmd, EXIT_FAILURE, output); testCommand("--library=x " + cmd, EXIT_FAILURE, output); testCommand("-L x --library y " + cmd, EXIT_FAILURE, output); testCommand("-Lx --library=y -L z " + cmd, EXIT_FAILURE, output); } // Load an actual library, including the file extension. // ===================================================== // OSIM_ACTUATORS_LIB_PATH is a preprocessor definition that is defined // when compiling this executable. std::string lib = MAKE_STRING(OSIM_ACTUATORS_LIB_PATH); // Get rid of the quotes surrounding `lib`. std::string expectLib = lib.substr(1, lib.size() - 2); #ifdef _WIN32 // When the library name gets printed back to us, the // forward slashes are converted to backslashes. We have to // escape backslash for the C++ parser, so '\\' is actually '\'. expectLib = replaceString(expectLib, "/", "\\"); #endif { StartsWith output("Loaded library " + expectLib); testCommand("-L " + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("-L" + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("--library " + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("--library=" + lib + " " + cmd, EXIT_SUCCESS, output); } // Load multiple libraries. // ======================== { // Well, in this case, we just load the same library multiple times. testCommand("-L " + lib + " --library " + lib + " " + cmd, EXIT_SUCCESS, StartsWith("Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n")); testCommand("-L" + lib + " --library=" + lib + " -L " + lib + " " + cmd, EXIT_SUCCESS, StartsWith("Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n")); } }
void testNoCommand() { // Help. // ===== { std::regex output("OpenSim: musculoskeletal" + RE_ANY + "Pass -h or --help" + RE_ANY); testCommand("", EXIT_SUCCESS, output); testCommand("-h", EXIT_SUCCESS, output); testCommand("-help", EXIT_SUCCESS, output); } // Version. // ======== { std::regex output("OpenSim version (?:.*), build date (?:.*)\n"); testCommand("-V", EXIT_SUCCESS, output); testCommand("--version", EXIT_SUCCESS, output); } // Library option. // =============== // Syntax errors. testCommand("-L", EXIT_FAILURE, StartsWith("-L requires an argument")); testCommand("--library", EXIT_FAILURE, StartsWith("--library requires an argument")); // Must specify a command; can't only list a library to load. { StartsWith output("Arguments did not match expected patterns"); // All of these are otherwise valid options for specify libraries to // load. testCommand("-L x", EXIT_FAILURE, output); testCommand("--library x", EXIT_FAILURE, output); testCommand("-L=x", EXIT_FAILURE, output); testCommand("--library=y", EXIT_FAILURE, output); testCommand("-L x --library y -L z", EXIT_FAILURE, output); testCommand("-L=x --library=y -L=z", EXIT_FAILURE, output); } // Unrecognized command. // ===================== testCommand("bleepbloop", EXIT_FAILURE, "'bleepbloop' is not an opensim-cmd command. " "See 'opensim-cmd --help'.\n"); }