/** * Sets any parameter in a user configuration file. Also creates a configuration file if it is missing. * * @param paramName name of parameter that needs to be changed or created. * @param value value for changing or adding to a given parameter. If value is an empty string, the walue for a given parameter will be erased. * @throws IOException exception is thrown if reading, writing or creating of a user configuration file fails. */ void digidoc::XmlConf::setUserConf(const std::string ¶mName, const std::string &value) throw(IOException) { Param newParam(value, paramName); std::auto_ptr< ::Configuration > conf; Configuration::ParamSequence paramSeq; try { if(util::File::fileExists(USER_CONF_LOC)) { //open user conf file conf = configuration (USER_CONF_LOC, xml_schema::Flags::dont_initialize); paramSeq = conf->param(); Configuration::ParamSequence::iterator it; for( it = paramSeq.begin(); it != paramSeq.end(); it++) { if (paramName.compare(it->name()) == 0) { paramSeq.erase(it); break; } } if (value.size()) //if it's a new parameter paramSeq.push_back(newParam); } else { //Check if directory exists if (!util::File::directoryExists(getUserConfDir())) util::File::createDirectory(getUserConfDir()); //create a new file //copy global conf and erase data conf = configuration (DEFAULT_CONF_LOC, xml_schema::Flags::dont_initialize); Configuration::OcspSequence ocspSeq; paramSeq.push_back(newParam); conf->ocsp(ocspSeq); //replace all ocsp data with empty ocsp sequence } conf->param(paramSeq); //replace all param data with new modified param sequence } catch (const xml_schema::Exception& e) { std::ostringstream oss; oss << e; THROW_IOEXCEPTION("(in set %s) Failed to parse configuration: %s", paramName.c_str(), oss.str().c_str()); } serializeUserConf(*conf); }
int HoughTransformCircle::findBestParamsAB( const int treshold ) { for( uint i = 0; i < this->HoughSpace.rows; i++ ) for( uint j = 0; j < this->HoughSpace.cols; j++ ) if( this->HoughSpace.mat[ i ][ j ] >= treshold ) { int3 newParam( this->HoughSpace.mat[ i ][ j ], ( i - ceil( this->radius ) ), ( j - ceil( this->radius ) ) ); this->bestParams.push_back( newParam ); } std::sort( this->bestParams.begin(), this->bestParams.end() ); return (int) ( this->bestParams.size() ); }
void TestNntpServerManager::test_add_remove_server(){ NntpProxy::log("[TestNntpServerManager] ", "test_add_remove_server"); QVERIFY(iSrvMgr->size() == 1); NntpServerParameters * currentParam = iServParams[0]; QVERIFY(iSrvMgr->getMaxNumberOfConnections()== currentParam->maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable()== currentParam->maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 0); QVERIFY(iSrvMgr->getMaxNumberOfConnections(0)== currentParam->maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(0)== currentParam->maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(0) == 0); NntpServerParameters newParam(cTestNntpServParamSSL()); QVERIFY(iSrvMgr->addNntpServer(newParam) != -1); QVERIFY(iSrvMgr->size() == 2); QVERIFY(iSrvMgr->getMaxNumberOfConnections(1)== newParam.maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(1)== newParam.maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(1) == 0); ushort maxCons = currentParam->maxConnections + newParam.maxConnections; QVERIFY(iSrvMgr->getMaxNumberOfConnections() == maxCons); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 0); // try removing non existing serv QVERIFY(!iSrvMgr->removeNntpServer(666)); // Remove first server QVERIFY(iSrvMgr->removeNntpServer(0)); QVERIFY(iSrvMgr->size() == 1); QVERIFY(iSrvMgr->getMaxNumberOfConnections() == newParam.maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == newParam.maxConnections); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 0); }
void TestNntpServerManager::createUserUsingAllConnections(User *aUser){ NntpProxy::log("[TestNntpServerManager] ", "test_getAllCons2serv1user"); NntpServerParameters newParam(cTestNntpServParamSSL()); short idServ2 = iSrvMgr->addNntpServer(newParam); short idServ1 = idServ2 -1; QVERIFY(idServ2 != -1); QVERIFY(iSrvMgr->size() == 2); ushort maxCons = iSrvMgr->getMaxNumberOfConnections(); // Static settings in constants_test.h short nb = iSrvMgr->getMaxNumberOfConnections(idServ1); QVERIFY(iSrvMgr->getMaxNumberOfConnections(idServ1) == 2); QVERIFY(iSrvMgr->getMaxNumberOfConnections(idServ2) == 3); QVERIFY(maxCons == 5); NntpConnection * con1 = iSrvMgr->getNntpConnection(1, aUser); QVERIFY(con1->getServerId() == idServ2); // serv2 has more connections aUser->newNntpConnection(idServ2); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(idServ2) == 2); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(idServ2) == 1); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons - 1); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 1); NntpConnection * con2 = iSrvMgr->getNntpConnection(2, aUser); QVERIFY(con2->getServerId() == idServ1); // we don't have any connection from serv1 aUser->newNntpConnection(idServ1); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(idServ1) == 1); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(idServ1) == 1); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons - 2); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 2); NntpConnection * con3 = iSrvMgr->getNntpConnection(3, aUser); QVERIFY(con3->getServerId() == idServ1); // serv1 has still some connections aUser->newNntpConnection(idServ1); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(idServ1) == 0); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(idServ1) == 2); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons - 3); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 3); NntpConnection * con4 = iSrvMgr->getNntpConnection(4, aUser); QVERIFY(con4->getServerId() == idServ2); // less connection from serv2 aUser->newNntpConnection(idServ2); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(idServ2) == 1); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(idServ2) == 2); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons - 4); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 4); NntpConnection * con5 = iSrvMgr->getNntpConnection(5, aUser); QVERIFY(con5->getServerId() == idServ2); // serv2 has still some connections aUser->newNntpConnection(idServ2); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable(idServ2) == 0); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse(idServ2) == 3); QVERIFY(iSrvMgr->getNumberOfConnectionsAvailable() == maxCons - 5); QVERIFY(iSrvMgr->getNumberOfConnectionsInUse() == 5); NntpProxy::log("[TestNntpServerManager] ", aUser->str()); QCOMPARE(aUser->str(), QString("User #0: [email protected] (in: 1, out: 5) {serv: %1. cons: 2} {serv: %2. cons: 3} ").arg( QString::number(idServ1), QString::number(idServ2))); iNntpCons.append(con1); iNntpCons.append(con2); iNntpCons.append(con3); iNntpCons.append(con4); iNntpCons.append(con5); }
int main(int argc, char* argv[]) { std::shared_ptr<Empty> blank; std::shared_ptr<Program> prg(new Program()); std::shared_ptr<SharedDecl> shDecl1(new SharedDecl("y", blank)); prg->Add(shDecl1); std::shared_ptr<Node> initX(new Atom("2")); std::shared_ptr<SharedDecl> shDecl2(new SharedDecl("x", initX)); prg->Add(shDecl2); std::shared_ptr<Sub> sub1(new Sub("Main")); sub1->AddParam("a"); sub1->AddParam("b"); prg->Add(sub1); std::shared_ptr<Atom> atomA(new Atom("a")); std::shared_ptr<Atom> atomB(new Atom("b")); std::shared_ptr<BinaryOp> initRes(new BinaryOp("add", atomA, atomB)); std::shared_ptr<VarDecl> resDecl(new VarDecl("res", initRes)); sub1->Add(resDecl); std::shared_ptr<Atom> atom3i(new Atom("3")); std::shared_ptr<Atom> atom5i(new Atom("5")); std::shared_ptr<BinaryOp> newParam(new BinaryOp("add", atom3i, atom5i)); std::shared_ptr<Allocation> allocat(new Allocation(newParam)); std::shared_ptr<Atom> atomArr(new Atom("arr")); std::shared_ptr<Assignation> asignNew3(new Assignation(atomArr, allocat)); sub1->Add(asignNew3); std::shared_ptr<Atom> atomArrBis(new Atom("arr")); std::shared_ptr<Deallocation> deallocat(new Deallocation(atomArrBis)); sub1->Add(deallocat); std::shared_ptr<Atom> atomC(new Atom("res")); std::shared_ptr<BinaryOp> subCsumAB(new BinaryOp("substract", atomC, initRes)); std::shared_ptr<Assignation> incC(new Assignation(atomC, subCsumAB)); sub1->Add(incC); std::shared_ptr<Atom> atom0(new Atom("0")); std::shared_ptr<BinaryOp> cond1cond(new BinaryOp("equals", atomC, atom0)); std::shared_ptr<If> cond1(new If(cond1cond, "10", "20")); sub1->Add(cond1); std::shared_ptr<Atom> atom1(new Atom("1")); std::shared_ptr<Atom> atom10(new Atom("10")); std::shared_ptr<For> for1(new For("i", atom1, atom10, atom1)); sub1->Add(for1); std::shared_ptr<BinaryOp> addC1(new BinaryOp("add", atomC, atom1)); std::shared_ptr<Assignation> incResActually(new Assignation(atomC, addC1)); for1->Add(incResActually); std::shared_ptr<Loop> loop1(new Loop(cond1cond)); loop1->Add(for1); // don't double reference ever in practice... loop1->Add(addC1); sub1->Add(loop1); std::shared_ptr<Call> call1(new Call("testFun", "")); call1->AddParam(atomA); call1->AddParam(addC1); sub1->Add(call1); std::shared_ptr<Return> ret1(new Return(atom0)); sub1->Add(ret1); XMLDumpVisitor v; prg->Accept(&v); return 0; }