void DigManager::shortDigAnswer(const QStringList hostname, QByteArray bufferData, QByteArray bufferError) { Q_UNUSED(hostname); /* * TODO: remove this check with QT5 QStandardPaths::findExecutable. * */ if (!bufferData.size() && bufferError.size()) { qWarning() << "Error: Dig is not installed."; return; } QString buff1(bufferData); QTextStream stream1(&buff1); QString line; m_elemObjUtil->setHostName(m_hostNameLocal); while (!stream1.atEnd()) { line = stream1.readLine(); m_elemObjUtil->setInfoLookup(line); } // clear thread bufferData.clear(); bufferError.clear(); }
void Parser::serializeToString() { std::string nb = ""; nb = this->_rawString.substr(0, this->_rawString.find("\t")); std::istringstream buff1(nb); buff1 >> this->mob->id; nb.clear(); this->_rawString.erase(0, this->_rawString.find("\t") + 1); nb = this->_rawString.substr(0, this->_rawString.find("\t")); std::istringstream buff2(nb); buff2 >> this->mob->x; nb.clear(); this->_rawString.erase(0, this->_rawString.find("\t") + 1); nb = this->_rawString.substr(0, this->_rawString.find("\t")); std::istringstream buff3(nb); buff3 >> this->mob->y; nb.clear(); this->_rawString.erase(0, this->_rawString.find("\t") + 1); nb = this->_rawString.substr(0, this->_rawString.find("\t")); std::istringstream buff4(nb); buff4 >> this->mob->path; nb.clear(); this->_rawString.erase(0, this->_rawString.find("\t") + 1); this->_rawString.clear(); }
void test2() { geryon::server::GUniformMemoryPool pool(BUF_SZ, 1, 0); std::vector<geryon::server::GBufferHandler> buffers; geryon::server::GIstreambuff buff1(buffers, 0, 0); std::istream iss1(&buff1); }
static int main_(int /* argc */, char** /*argv*/) { stlsoft::auto_buffer<char> buff1(1); stlsoft::auto_buffer<char, 100> buff2(1); ff::fmt(buff1, "{0}{1}{0}", "abc", "---"); ff::fmt(buff2, "{0}{1}{0}", "abc", "---"); ff::write(buff2, "xyz", "MNO"); return EXIT_SUCCESS; }
bool test_osc_StateList() { size_t i; osc::StateList slist(4096); // KEEP IN MIND that each state take its own size PLUS 64 BYTES. TEST_ASSERT_EQUAL(slist.numberOfStates(),0); TEST_ASSERT_EQUAL(slist.getQuota(),4096); osc::byte_t bytes1[] = {0,1,2,3,4}; osc::Buffer buff1(bytes1,sizeof(bytes1)); osc::State s1(buff1); // Test single add TEST_ASSERT_EQUAL(s1.getRefCount(),0); slist.addState(&s1, 1, false); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64); // Test reset slist.reset(); TEST_ASSERT_EQUAL(s1.getRefCount(),0); // Test double add (same priority) slist.addState(&s1, 1, false); slist.addState(&s1, 1, false); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64); // Test multiple add (lower priority) slist.addState(&s1, 2, false); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64); // Test multiple add (higher priority) slist.addState(&s1, 0, false); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64); // Test adding second state osc::byte_t bytes2[] = {0,2,2,3,4}; osc::Buffer buff2(bytes2,sizeof(bytes2)); osc::State s2(buff2); slist.addState(&s2, 1, false); TEST_ASSERT_EQUAL(s2.getRefCount(),1); TEST_ASSERT_EQUAL(slist.getQuotaLeft(), 4096 - sizeof(bytes1) - sizeof(bytes2) - 128); // Test adding big state that removes other two osc::byte_t bigBytes1[4096 - 64]; for (i = 0; i < sizeof(bigBytes1); i++) { bigBytes1[i] = (i & 0xff); } osc::Buffer bigBuff1(bigBytes1, sizeof(bigBytes1)); osc::State bigState1(bigBuff1); slist.addState(&bigState1, 0, false); TEST_ASSERT_EQUAL(bigState1.getRefCount(),1); TEST_ASSERT_EQUAL(s1.getRefCount(),0); TEST_ASSERT_EQUAL(s2.getRefCount(),0); // Test adding state that bumps exactly one state out (based on time). slist.reset(); osc::Buffer bigBuff2(bigBytes1, sizeof(bigBytes1) - 64 - sizeof(bytes1)); osc::State bigState2(bigBuff2); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096); slist.addState(&s2, 0, false); slist.addState(&s1, 0, false); slist.addState(&bigState2, 0, false); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(s2.getRefCount(),0); TEST_ASSERT_EQUAL(bigState2.getRefCount(),1); // Lowest priority = freed first // Test adding state that bumps exactly one state out (based on priority). slist.reset(); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096); slist.addState(&s2, 1, false); slist.addState(&s1, 0, false); slist.addState(&bigState2, 0, false); TEST_ASSERT_EQUAL(s1.getRefCount(),0); TEST_ASSERT_EQUAL(s2.getRefCount(),1); TEST_ASSERT_EQUAL(bigState2.getRefCount(),1); // Same test, but with state reprioritization slist.reset(); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096); slist.addState(&s2, 0, false); slist.addState(&s1, 1, false); slist.addState(&s2, 2, false); slist.addState(&bigState2, 0, false); TEST_ASSERT_EQUAL(s1.getRefCount(),0); TEST_ASSERT_EQUAL(s2.getRefCount(),1); TEST_ASSERT_EQUAL(bigState2.getRefCount(),1); // Make sure insertion at a lower priority doesn't downgrade slist.reset(); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096); slist.addState(&s2, 2, false); slist.addState(&s1, 1, false); slist.addState(&s2, 0, false); slist.addState(&bigState2, 0, false); TEST_ASSERT_EQUAL(s1.getRefCount(),0); TEST_ASSERT_EQUAL(s2.getRefCount(),1); TEST_ASSERT_EQUAL(bigState2.getRefCount(),1); // Now, bump out the big state by lowering the quota slist.setQuota(2048); TEST_ASSERT_EQUAL(s1.getRefCount(),0); TEST_ASSERT_EQUAL(s2.getRefCount(),1); TEST_ASSERT_EQUAL(bigState2.getRefCount(),0); slist.setQuota(4096); // Try removing a state manually slist.reset(); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096); slist.addState(&s2, 2, false); slist.addState(&s1, 1, false); slist.removeState(s2.getStateId()); TEST_ASSERT_EQUAL(s1.getRefCount(),1); TEST_ASSERT_EQUAL(s2.getRefCount(),0); TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64); // Insert a pre-acked state, check acked state retreival slist.addState(&s2, 1, true); slist.addState(&s1, 1, false); TEST_ASSERT(!(slist.isStateAcked(s1.getStateId()))); TEST_ASSERT(slist.isStateAcked(s2.getStateId())); TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2); slist.ackState(s1.getStateId()); TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s1); slist.addState(&s2, 1, false); TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2); TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(0),0); TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(2),0); return true; }
void test1Gaps() { geryon::server::GUniformMemoryPool pool(BUF_SZ, 1, 0); std::vector<geryon::server::GBufferHandler> buffers; buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(0).get().buffer()[0] = 'a'; //0 buffers.at(0).get().buffer()[1] = 'X'; //1 buffers.at(0).get().buffer()[2] = 'a'; //2 buffers.at(0).get().setMarker(3); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(1).get().buffer()[0] = 'b'; //3 buffers.at(1).get().buffer()[1] = 'b'; //4 buffers.at(1).get().buffer()[2] = 'X'; //5 buffers.at(1).get().buffer()[3] = 'X'; //6 buffers.at(1).get().buffer()[4] = 'b'; //7 buffers.at(1).get().setMarker(5); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(2).get().buffer()[0] = 'c'; //8 buffers.at(2).get().buffer()[1] = 'c'; //9 buffers.at(2).get().buffer()[2] = 'c'; //10 buffers.at(2).get().buffer()[3] = 'X'; //11 buffers.at(2).get().setMarker(4); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(3).get().buffer()[0] = 'X'; //12 buffers.at(3).get().buffer()[1] = 'd'; //13 buffers.at(3).get().buffer()[2] = 'd'; //14 buffers.at(3).get().buffer()[3] = 'X'; //15 buffers.at(3).get().setMarker(4); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(4).get().buffer()[0] = 'X'; //16 buffers.at(4).get().buffer()[1] = 'e'; //17 buffers.at(4).get().buffer()[2] = 'e'; //18 buffers.at(4).get().buffer()[3] = 'X'; //19 buffers.at(4).get().setMarker(4); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(5).get().buffer()[0] = 'X'; //19 buffers.at(5).get().setMarker(1); //1st test : abb geryon::server::GIstreambuff buff1(buffers); buff1.addGap(1, 2); buff1.setup(1, 5); std::istream iss1(&buff1); std::string s; iss1 >> s; //our stream if("abb" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test1Gaps (1)"; } std::cout << "String 1 is >>" << s << "<<" << std::endl; //2nd test: all abbbcccddee geryon::server::GIstreambuff buff2(buffers); buff2.addGap(1, 2); buff2.addGap(5, 7); buff2.addGap(11, 13); buff2.addGap(15, 17); buff2.addGap(19, 20); buff2.setup(1, 20); std::istream iss2(&buff2); iss2 >> s; //our stream if("abbbcccddee" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test1Gaps (2)"; } std::cout << "String 2 is >>" << s << "<<" << std::endl; //3rd test: reset the stream buff2.setup(2,4); std::istream iss2_1(&buff2); //our stream iss2_1 >> s; if("ab" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test1Gaps (3.1)"; } std::cout << "String 3.1 is >>" << s << "<<" << std::endl; buff2.addGap(11, 13); buff2.addGap(15, 17); buff2.setup(11,18); iss2.rdbuf(&buff2); iss2 >> s; if("dde" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test1Gaps (3.2)"; } std::cout << "String 3.2 is >>" << s << "<<" << std::endl; //4th test: empty (EOF) geryon::server::GIstreambuff buff3(buffers); buff3.addGap(11, 13); buff2.setup(11,13); std::istream iss3(&buff3); if(iss3 >> s) { //yeap, this should return false LOG(geryon::util::Log::ERROR) << "ERROR: Failed test1Gaps (4)"; } std::cout << "String 4 is >>" << s << "<<" << std::endl; //unchanged }
void test1() { geryon::server::GUniformMemoryPool pool(BUF_SZ, 1, 0); std::vector<geryon::server::GBufferHandler> buffers; buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(0).get().buffer()[0] = 'a'; //0 buffers.at(0).get().buffer()[1] = 'a'; //1 buffers.at(0).get().setMarker(2); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(1).get().buffer()[0] = 'b'; //2 buffers.at(1).get().buffer()[1] = 'b'; //3 buffers.at(1).get().buffer()[2] = 'b'; //4 buffers.at(1).get().setMarker(3); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(2).get().buffer()[0] = 'c'; //5 buffers.at(2).get().buffer()[1] = 'c'; //6 buffers.at(2).get().buffer()[2] = 'c'; //7 buffers.at(2).get().buffer()[3] = 'c'; //8 buffers.at(2).get().setMarker(4); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(3).get().buffer()[0] = 'd'; //9 buffers.at(3).get().setMarker(1); //1st test : abbbc geryon::server::GIstreambuff buff1(buffers, 1, 6); std::istream iss1(&buff1); std::string s; iss1 >> s; //our stream if("abbbc" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed (1)"; } std::cout << "String 1 is >>" << s << "<<" << std::endl; //2nd test: all aabbbccccd geryon::server::GIstreambuff buff2(buffers, 0, 10); std::istream iss2(&buff2); iss2 >> s; //our stream if("aabbbccccd" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed (2)"; } std::cout << "String 2 is >>" << s << "<<" << std::endl; //3rd test: reset the stream buff2.setup(1,9); std::istream iss2_1(&buff2); //our stream iss2_1 >> s; if("abbbcccc" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed (3.1)"; } std::cout << "String 3.1 is >>" << s << "<<" << std::endl; buff2.setup(2,8); iss2.rdbuf(&buff2); iss2 >> s; if("bbbccc" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed (3.2)"; } std::cout << "String 3.2 is >>" << s << "<<" << std::endl; //4th test: empty (EOF) geryon::server::GIstreambuff buff3(buffers, 0, 0); std::istream iss3(&buff3); if(iss3 >> s) { //yeap, this should return false LOG(geryon::util::Log::ERROR) << "ERROR: Failed (4)"; } std::cout << "String 4 is >>" << s << "<<" << std::endl; //unchanged }
void test2Gaps() { geryon::server::GUniformMemoryPool pool(BUF_SZ, 1, 0); std::vector<geryon::server::GBufferHandler> buffers; buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(0).get().buffer()[0] = 'a'; //0 buffers.at(0).get().buffer()[1] = 'X'; //1 buffers.at(0).get().buffer()[2] = 'a'; //2 buffers.at(0).get().setMarker(3); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(1).get().buffer()[0] = 'b'; //3 buffers.at(1).get().buffer()[1] = 'b'; //4 buffers.at(1).get().buffer()[2] = 'X'; //5 buffers.at(1).get().buffer()[3] = 'X'; //6 buffers.at(1).get().buffer()[4] = 'b'; //7 buffers.at(1).get().setMarker(5); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(2).get().buffer()[0] = 'c'; //8 buffers.at(2).get().buffer()[1] = 'c'; //9 buffers.at(2).get().buffer()[2] = 'c'; //10 buffers.at(2).get().buffer()[3] = 'X'; //11 buffers.at(2).get().setMarker(4); buffers.push_back(std::move(geryon::server::GBufferHandler(&pool))); buffers.at(3).get().buffer()[0] = 'X'; //12 buffers.at(3).get().buffer()[1] = 'd'; //13 buffers.at(3).get().buffer()[2] = 'd'; //14 buffers.at(3).get().buffer()[3] = 'X'; //15 buffers.at(3).get().setMarker(4); //1st test : aabbbcccdd geryon::server::GIstreambuff buff1(buffers); buff1.addGap(1, 2); buff1.addGap(5, 7); buff1.addGap(11, 13); buff1.addGap(15, 16); buff1.setup(0, 16); std::istream iss1(&buff1); std::string s; iss1 >> s; //our stream if("aabbbcccdd" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (1)"; } std::cout << "String 1 is >>" << s << "<<" << std::endl; //2nd test: putback stuff geryon::server::GIstreambuff buff2(buffers); buff2.addGap(1, 2); buff2.addGap(5, 7); buff2.addGap(11, 13); buff2.addGap(15, 16); buff2.setup(0, 16); std::istream iss2(&buff2); char c; iss2 >> c; //a 0 if(c != 'a'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.0) found:" << c; } iss2.putback(c); //0 iss2 >> c; //a 0 if(c != 'a'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.1) found:" << c; } iss2 >> c; //a 2 if(c != 'a'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.2) found:" << c; } iss2.putback(c); //2 iss2 >> c; //a 2 if(c != 'a'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.3) found:" << c; } iss2 >> c; //b 3 if(c != 'b'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.4) found:" << c; } iss2 >> c; //b 4 iss2.putback(c); //4 iss2 >> c; //b 4 if(c != 'b'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.5) found:" << c; } iss2 >> c; //b 7 if(c != 'b'){ LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (2.6) found:" << c; } iss2 >> s; if("cccdd" != s) { LOG(geryon::util::Log::ERROR) << "ERROR: Failed test2Gaps (3)"; } std::cout << "String 2 is >>" << s << "<<" << std::endl; }
bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf){ bool ret = true; bool ret2 = true; duint32 bs =0; duint8 *tmpByteStr; std::map<duint32, objHandle>::iterator mit; DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size()); for (std::map<duint32, DRW_Block_Record*>::iterator it=blockRecordmap.begin(); it != blockRecordmap.end(); ++it){ DRW_Block_Record* bkr= it->second; DRW_DBG("\nParsing Block, record handle= "); DRW_DBGH(it->first); DRW_DBG(" Name= "); DRW_DBG(bkr->name); DRW_DBG("\n"); DRW_DBG("\nFinding Block, handle= "); DRW_DBGH(bkr->block); DRW_DBG("\n"); mit = ObjectMap.find(bkr->block); if (mit==ObjectMap.end()) { DRW_DBG("\nWARNING: block entity not found\n"); ret = false; continue; } objHandle oc = mit->second; ObjectMap.erase(mit); DRW_DBG("Block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n"); if ( !(dbuf->setPosition(oc.loc)) ){ DRW_DBG("Bad Location reading blocks\n"); ret = false; continue; } int size = dbuf->getModularShort(); if (version > DRW::AC1021) //2010+ bs = dbuf->getUModularChar(); else bs = 0; tmpByteStr = new duint8[size]; dbuf->getBytes(tmpByteStr, size); dwgBuffer buff(tmpByteStr, size, &decoder); DRW_Block bk; ret2 = bk.parseDwg(version, &buff, bs); delete[]tmpByteStr; ret = ret && ret2; parseAttribs(&bk); //complete block entity with block record data bk.basePoint = bkr->basePoint; bk.flags = bkr->flags; intfa.addBlock(bk); //and update block record name bkr->name = bk.name; /**read & send block entities**/ // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it (RLZ: only tested in 2000) if (bk.parentHandle == DRW::NoHandle) { // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it bk.parentHandle= bkr->handle; //and do not send block entities like dxf } else { if (version < DRW::AC1018) { //pre 2004 duint32 nextH = bkr->firstEH; while (nextH != 0){ mit = ObjectMap.find(nextH); if (mit==ObjectMap.end()) { nextH = bkr->lastEH;//end while if entity not foud DRW_DBG("\nWARNING: Entity of block not found\n"); ret = false; continue; } else {//foud entity reads it oc = mit->second; ObjectMap.erase(mit); ret2 = readDwgEntity(dbuf, oc, intfa); ret = ret && ret2; } if (nextH == bkr->lastEH) nextH = 0; //redundant, but prevent read errors else nextH = nextEntLink; } } else {//2004+ for (std::vector<duint32>::iterator it = bkr->entMap.begin() ; it != bkr->entMap.end(); ++it){ duint32 nextH = *it; mit = ObjectMap.find(nextH); if (mit==ObjectMap.end()) { DRW_DBG("\nWARNING: Entity of block not found\n"); ret = false; continue; } else {//foud entity reads it oc = mit->second; ObjectMap.erase(mit); DRW_DBG("\nBlocks, parsing entity: "); DRW_DBGH(oc.handle); DRW_DBG(", pos: "); DRW_DBG(oc.loc); DRW_DBG("\n"); ret2 = readDwgEntity(dbuf, oc, intfa); ret = ret && ret2; } } }//end 2004+ } //end block entity, really needed to parse a dummy entity?? mit = ObjectMap.find(bkr->endBlock); if (mit==ObjectMap.end()) { DRW_DBG("\nWARNING: end block entity not found\n"); ret = false; continue; } oc = mit->second; ObjectMap.erase(mit); DRW_DBG("End block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n"); dbuf->setPosition(oc.loc); size = dbuf->getModularShort(); if (version > DRW::AC1021) //2010+ bs = dbuf->getUModularChar(); else bs = 0; tmpByteStr = new duint8[size]; dbuf->getBytes(tmpByteStr, size); dwgBuffer buff1(tmpByteStr, size, &decoder); DRW_Block end; end.isEnd = true; ret2 = end.parseDwg(version, &buff1, bs); delete[]tmpByteStr; ret = ret && ret2; if (bk.parentHandle == DRW::NoHandle) bk.parentHandle= bkr->handle; parseAttribs(&end); intfa.endBlock(); } return ret; }