BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, AuthorizedCommandFixture<LocalControlFixture>) { shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); BOOST_REQUIRE(dummy->isLocal()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); Block encodedParameters(parameters.wireEncode()); Name enable("/localhost/nfd/faces/enable-local-control"); enable.append(encodedParameters); shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); enableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*enableCommand); TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand, encodedParameters] (const Data& response) { this->validateControlResponse(response, enableCommand->getName(), 200, "Success", encodedParameters); }; onValidatedFaceRequest(enableCommand); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); TestFaceManagerCommon::m_face->onReceiveData.clear(); resetCallbackFired(); Name disable("/localhost/nfd/faces/disable-local-control"); disable.append(encodedParameters); shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); disableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*disableCommand); TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand, encodedParameters] (const Data& response) { this->validateControlResponse(response, disableCommand->getName(), 200, "Success", encodedParameters); }; onValidatedFaceRequest(disableCommand); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); }
void RenderThread::run() { // Check for any possible conditions, and emit errors for each one if(exe.isEmpty()) { emit renderError("Anime Studio executable not configured"); return; } if(project.first.isEmpty()||project.second.isEmpty()) { emit renderError("Project file not set properly"); return; } if(outputPath.isEmpty()) emit renderWarning("Output directory not configured; defaulting to project location"); // Get our separator now, to avoid multiple function calls QString sep = QDir::separator(); // Separate the filename from the extension QString filename = project.second.mid(0,project.second.lastIndexOf(".")); // Compile the final output directory, and create it if it doesn't exist QString outdir = (outputPath.isEmpty()?(project.first):(outputPath+sep))+ (isImageSequence(indexToFormat(format))?filename+sep:""); QDir dirpath; dirpath.mkpath(outdir); // This is just silly. // Set all of the arguments based on the configuration settings we now have QStringList args = generateCommand(project.first+project.second, indexToFormat(format), outdir+filename+extension(indexToFormat(format)), frameStart,frameEnd,switchAA,switchShapeFX,switchLayerFX, switchHalfSize,switchHalfFPS,switchFewParticles, switchExtraSmooth,switchNTSCSafe,switchPremultiply, switchVariableWidths); // Finally, emit the signal to begin the render emit cli(exe, args); }
BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) { shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setFaceId(dummy->getId()); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("destroy"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) .setFaceId(dummy->getId()) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFlags(0); getFace()->onReceiveData += bind(&FaceFixture::callbackDispatch, this, _1, command->getName(), 200, "Success", ref(encodedParameters), expectedFaceEvent); destroyFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, AuthorizedCommandFixture<LocalControlFixture>) { shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); BOOST_REQUIRE(!dummy->isLocal()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); Block encodedParameters(parameters.wireEncode()); Name enable("/localhost/nfd/faces/enable-local-control"); enable.append(encodedParameters); shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); enableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*enableCommand); TestFaceManagerCommon::m_face->onReceiveData += bind(&LocalControlFixture::validateControlResponse, this, _1, enableCommand->getName(), 412, "Face is non-local"); onValidatedFaceRequest(enableCommand); BOOST_REQUIRE(didCallbackFire()); TestFaceManagerCommon::m_face->onReceiveData.clear(); resetCallbackFired(); Name disable("/localhost/nfd/faces/disable-local-control"); disable.append(encodedParameters); shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); disableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*disableCommand); TestFaceManagerCommon::m_face->onReceiveData += bind(&LocalControlFixture::validateControlResponse, this, _1, disableCommand->getName(), 412, "Face is non-local"); onValidatedFaceRequest(disableCommand); BOOST_REQUIRE(didCallbackFire()); }
bool Eddie::accelerate(parallax_eddie_robot::Accelerate::Request &req, parallax_eddie_robot::Accelerate::Response &res) { //this feature does not need to validate the parameters due the limited range of parameter data type std::string cmd; cmd = generateCommand(SET_RAMPING_VALUE_STRING, req.rate); std::string cmd_response = command(cmd); if (cmd_response == "\r") return true; else return false; }
bool Eddie::driveWithDistance(parallax_eddie_robot::DriveWithDistance::Request &req, parallax_eddie_robot::DriveWithDistance::Response &res) { //this feature does not need to validate the parameters due the limited range of parameter data type std::string cmd; cmd = generateCommand(SET_DRIVE_DISTANCE_STRING, req.distance, req.speed); std::string cmd_response = command(cmd); if (cmd_response == "\r") return true; else return false; }
char *convert (char* originalFilename, user_agent UserAgent, int Quality, char* Extensions) { char* imageSpecs= (char*) malloc (200); char* targetFilename= (char*) malloc (200); char* midFilename= (char*) malloc (200); char* command = (char*) malloc (1000); imageSpecs = generatePrefix( originalFilename, UserAgent, Quality); midFilename = createNewFilename( originalFilename, UserAgent.format, Extensions); targetFilename = strcat(imageSpecs,midFilename); command = generateCommand(originalFilename, targetFilename, UserAgent, Quality); return convertImage(targetFilename, command); }
bool Eddie::driveWithSpeed(parallax_eddie_robot::DriveWithSpeed::Request &req, parallax_eddie_robot::DriveWithSpeed::Response &res) { if (req.left > TRAVEL_SPEED_MAX_FORWARD || req.right > TRAVEL_SPEED_MAX_FORWARD || req.left < TRAVEL_SPEED_MAX_REVERSE || req.right < TRAVEL_SPEED_MAX_REVERSE) { return false; } std::string cmd; cmd = generateCommand(SET_DRIVE_SPEED_STRING, req.left, req.right); std::string cmd_response = command(cmd); if (cmd_response == "\r") return true; else return false; }
bool Eddie::driveWithPower(parallax_eddie_robot::DriveWithPower::Request &req, parallax_eddie_robot::DriveWithPower::Response &res) { if (req.left > MOTOR_POWER_MAX_FORWARD || req.right > MOTOR_POWER_MAX_FORWARD || req.left < MOTOR_POWER_MAX_REVERSE || req.right < MOTOR_POWER_MAX_REVERSE) { return false; } std::string cmd; cmd = generateCommand(SET_DRIVE_POWER_STRING, req.left, req.right); std::string cmd_response = command(cmd); if (cmd_response == "\r") return true; else{ ROS_ERROR("%s",cmd_response.data()); return false; } }
BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, AuthorizedCommandFixture<ValidatedFaceRequestFixture>) { Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append("NotReallyParameters"); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1, command->getName(), 400, "Malformed command"); onValidatedFaceRequest(command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace, AuthorizedCommandFixture<ValidatedFaceRequestFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("destroy"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); onValidatedFaceRequest(command); BOOST_CHECK(didDestroyFaceFire()); }
// Note: it seems that Samsung AC remotes do not repeat commands! I'd love // to find verification of this, I've only one source for it... void SamsungACProtocol::startSendingCommand( unsigned int threadableID, PIRKeyName command) { // First, check if we are meant to be the recipient of this command: if (threadableID != id) return; KeycodeCollection::const_iterator i = keycodes.find(command); // Do we even have this key defined? if (i == keycodes.end()) { QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; emit errorMessage("Key not defined in this keyset."); return; } // construct the device: PIRInfraredLED led(carrierFrequency, dutyCycle); connect( &led, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); if (command == ACSetTimer_Key) { generateTimerCommand(led); } else { generateCommand(led); } // Now, tell the device to send the whole command: led.sendCommandToDevice(); QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; }
BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ControlParameters resultParameters; resultParameters.setUri("dummy://"); resultParameters.setFaceId(FACEID_RESERVED_MAX + 1); shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) .setFaceId(FACEID_RESERVED_MAX + 1) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); Block encodedResultParameters(resultParameters.wireEncode()); getFace()->onReceiveData += [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) { this->callbackDispatch(response,command->getName(), 200, "Success", encodedResultParameters, expectedFaceEvent); }; onCreated(command->getName(), parameters, dummy); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 400, "Malformed command"); createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>) { ControlParameters parameters; Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("unsupported"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceManagerFixture::validateControlResponse, this, _1, command->getName(), 501, "Unsupported command"); getManager().onFaceRequest(*command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp:/127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += [this, command] (const Data& response) { this->validateControlResponse(response, command->getName(), 400, "Malformed command"); }; createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ControlParameters resultParameters; resultParameters.setUri("tcp://127.0.0.1"); resultParameters.setFaceId(1); shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) .setFaceId(1) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFlags(0); Block encodedResultParameters(resultParameters.wireEncode()); getFace()->onReceiveData += bind(&FaceFixture::callbackDispatch, this, _1, command->getName(), 200, "Success", encodedResultParameters, expectedFaceEvent); onCreated(command->getName(), parameters, dummy); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 408, "unit-test-reason"); onConnectFailed(command->getName(), "unit-test-reason"); BOOST_REQUIRE(didCallbackFire()); BOOST_CHECK_EQUAL(didReceiveNotication(), false); }
BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) { shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setFaceId(dummy->getId()); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("destroy"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) .setFaceId(dummy->getId()) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); getFace()->onReceiveData += [this, command, encodedParameters, expectedFaceEvent] (const Data& response) { this->callbackDispatch(response,command->getName(), 200, "Success", encodedParameters, expectedFaceEvent); }; destroyFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<StrategyChoiceManagerFixture>) { ControlParameters parameters; parameters.setName("/test"); parameters.setStrategy("/localhost/nfd/strategy/best-route"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/strategy-choice"); commandName.append("set"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, command->getName(), 403, "Unauthorized command"); getManager().onStrategyChoiceRequest(*command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; // this will be an unsupported protocol because no factories have been // added to the face manager parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 501, "Unsupported protocol"); createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
void AirtechProtocol::startSendingCommand( unsigned int threadableID, PIRKeyName command) { // First, check if we are meant to be the recipient of this command: if (threadableID != id) return; clearRepeatFlag(); KeycodeCollection::const_iterator i = keycodes.find(command); // Do we even have this key defined? if (i == keycodes.end()) { QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; emit errorMessage("Key not defined in this keyset."); return; } // construct the device: PIRInfraredLED led(carrierFrequency, dutyCycle); connect( &led, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); int repeatCount = 0; int commandDuration = 0; while (repeatCount < MAX_REPEAT_COUNT) { commandDuration = generateCommand((*i).second, led); // Now, tell the device to send the whole command: if (!led.sendCommandToDevice()) { // Something didn't work right, get out: break; } // sleep until the next repetition of command: sleepUntilRepeat(commandDuration); // Check whether we've reached the minimum required number of repetitons: if (repeatCount >= minimumRepetitions) { // Check whether we've been asked to stop: if (checkRepeatFlag()) { break; } } ++repeatCount; } QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; }
void DenonProtocol::startSendingCommand( unsigned int threadableID, PIRKeyName command) { // Exceptions here are problematic; I'll try to weed them out by putting the // whole thing in a try/catch block: try { // First, check if we are meant to be the recipient of this command: if (threadableID != id) return; clearRepeatFlag(); KeycodeCollection::const_iterator i = keycodes.find(command); // Do we even have this key defined? if (i == keycodes.end()) { QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; return; // std::string s = "Tried to send a non-existent command.\n"; // throw PIRException(s); } // construct the device: PIRInfraredLED led(carrierFrequency, dutyCycle); int repeatCount = 0; int commandDuration = 0; while (repeatCount < MAX_REPEAT_COUNT) { // If the repeat count is an even number, generate a normal block. // Otherwise, generate a repeat block. if (repeatCount % 2) { commandDuration = generateCommand((*i).second, led); } else { commandDuration = generateRepeatCommand((*i).second, led); } // Now, tell the device to send the whole command: led.sendCommandToDevice(); // sleep until the next repetition of command: sleepUntilRepeat(commandDuration); // Check whether we've reached the minimum required number of repetitons: if (repeatCount >= minimumRepetitions) { // Check whether we've been asked to stop: if (checkRepeatFlag()) { break; /* QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; return; */ } } ++repeatCount; } QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; } catch (PIRException e) { // inform the gui: emit commandFailed(e.getError().c_str()); } }