コード例 #1
0
ファイル: Parser.cpp プロジェクト: syrus44/rtype_project
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();
}
コード例 #2
0
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;
}
コード例 #3
0
void BlindOFDM_Multimediaread::run(){


    if(!infile.is_open()){
         infile.open(file_name, ifstream::binary);
        cout << file_name << " has been opened for reading"<< endl;
    }
    else{
        cout << file_name << " is already opened for reading"<< endl;
    }
    buff.resize(buff_size);
    vector<char> buff2(buff_size);

    if(is_readsome==false){
        nb_read=buff_size;
        while(!stopped){
            infile.read(&buff2.front(), buff2.size());
            buff=buff2;
            //cout << "##################  INPUT STREAM HAS BEEN READ #####################" << endl;
        }
    }
    else{
        int nb_read2=0;
        while(!stopped){
            while(nb_read2==0){
                nb_read2=infile.readsome(&buff2.front(), buff2.size());
            }
            nb_read=nb_read2;
            buff=buff2;
            nb_read2=0;
            //cout << "##################  INPUT STREAM HAS BEEN READ #####################" << endl;
        }


    }



}
コード例 #4
0
ファイル: MainCpu.cpp プロジェクト: nyhu/PCPP
void MainCpu::setCpuDatas()
{
    char buffer[BUFFERLEN];
    size_t bufferlen = BUFFERLEN;
    memset (buffer, 0, bufferlen);
    sysctlbyname("machdep.cpu.brand_string", &buffer, &bufferlen, NULL, 0);

    std::string buff(buffer);
    std::string delim = " CPU @ ";
    size_t pos = 0;

    while ((pos = buff.find(delim)) != std::string::npos) {
        this->_data["CPU Brand"] = buff.substr(0, pos);
        buff.erase(0, pos + delim.length());
    }
    this->_data["CPU Frequecy"] = buff;

    memset (buffer, 0, bufferlen);
    sysctlbyname("hw.ncpu", &buffer, &bufferlen, NULL, 0);
    std::string buff2("4");
    this->_data["Number of Core"] = buff2;
}
コード例 #5
0
ファイル: TestUConv.cpp プロジェクト: rn10950/RetroZilla
nsresult nsTestUConv::DisplayCharsets()
{
  char * trace = "DisplayCharsets";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  nsCOMPtr<nsIUTF8StringEnumerator> decoders;
  nsCOMPtr<nsIUTF8StringEnumerator> encoders;

  res = ccMan->GetDecoderList(getter_AddRefs(decoders));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetDecoderList()", res);
    return res;
  }

  res = ccMan->GetEncoderList(getter_AddRefs(encoders));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetEncoderList()", res);
    return res;
  }


  printf("***** Character Sets *****\n");

  PRUint32 encCount = 0, decCount = 0;
  PRUint32 basicEncCount = 0, basicDecCount = 0;

  nsCStringArray allCharsets;
  
  nsCAutoString charset;
  PRBool hasMore;
  encoders->HasMore(&hasMore);
  while (hasMore) {
    res = encoders->GetNext(charset);
    if (NS_SUCCEEDED(res))
      allCharsets.AppendCString(charset);

    encoders->HasMore(&hasMore);
  }

  nsAutoString prop, str;
  PRUint32 count = allCharsets.Count();
  for (PRUint32 i = 0; i < count; i++) {

    const nsCString* charset = allCharsets[i];
    printf("%s", charset->get());
    PrintSpaces(24 - charset->Length());  // align to hard coded column number


    nsCOMPtr<nsIUnicodeDecoder> dec = NULL;
    res = ccMan->GetUnicodeDecoder(charset->get(), getter_AddRefs(dec));
    if (NS_FAILED(res)) printf (" "); 
    else {
      printf("D");
      decCount++;
    }
#ifdef NS_DEBUG
    // show the "basic" decoder classes
    if (dec) {
      nsCOMPtr<nsIBasicDecoder> isBasic = do_QueryInterface(dec);
      if (isBasic) {
        basicDecCount++;
        printf("b");
      }
      else printf(" ");
    }
    else printf(" ");
#endif

    nsCOMPtr<nsIUnicodeEncoder> enc = NULL;
    res = ccMan->GetUnicodeEncoder(charset->get(), getter_AddRefs(enc));
    if (NS_FAILED(res)) printf (" "); 
    else {
      printf("E");
      encCount++;
    }

#ifdef NS_DEBUG
    if (enc) {
      nsCOMPtr<nsIBasicEncoder> isBasic = do_QueryInterface(enc);
      if (isBasic) {
        basicEncCount++;
        printf("b");
      }
      else printf(" ");
    }
    else printf(" ");
#endif
    
    printf(" ");

    prop.AssignLiteral(".notForBrowser");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((dec != NULL) && (NS_FAILED(res))) printf ("B"); 
    else printf("X");

    prop.AssignLiteral(".notForComposer");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((enc != NULL) && (NS_FAILED(res))) printf ("C"); 
    else printf("X");

    prop.AssignLiteral(".notForMailView");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((dec != NULL) && (NS_FAILED(res))) printf ("V"); 
    else printf("X");

    prop.AssignLiteral(".notForMailEdit");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((enc != NULL) && (NS_FAILED(res))) printf ("E"); 
    else printf("X");

    printf("(%3d, %3d) ", encCount, decCount);
    res = ccMan->GetCharsetTitle(charset->get(), str);
    if (NS_FAILED(res)) str.SetLength(0);
    NS_LossyConvertUCS2toASCII buff2(str);
    printf(" \"%s\"\n", buff2.get());
  }

  printf("%u of %u decoders are basic (%d%%)\n",
         basicDecCount, decCount, (basicDecCount * 100) / decCount);

  printf("%u of %u encoders are basic (%d%%)\n",
         basicEncCount, encCount, (basicEncCount * 100) / encCount);
  mLog.DelTrace(trace);
  return NS_OK;
}
コード例 #6
0
ファイル: mysql_lang.cpp プロジェクト: svn2github/ncbi_tk
int
CDemoApp::Run(void)
{
    const CArgs& args = GetArgs();

    // Get command-line arguments ...
    string ServerName = args["S"].AsString();
    string UserName   = args["U"].AsString();
    string Password   = args["P"].AsString();
    string Database   = args["D"].AsString();

    try {
        DBLB_INSTALL_DEFAULT();

        CMySQLContext my_context;
        unique_ptr<CDB_Connection> con(my_context.Connect(ServerName, UserName, Password, 0));

        // changing database
        con->SetDatabaseName(Database);
        cout << "Database changed" << endl;

        // creating table
        {
            unique_ptr<CDB_LangCmd>
                lcmd(con->LangCmd("create temporary table tmp_t1("
                                  "a int,"
                                  "b datetime,"
                                  "c varchar(100),"
                                  "d text,"
                                  "e double,"
                                  "bl BLOB)"
                                  ));
            lcmd->Send();
            cout << "Table created" << endl;
        }

        int nBlobSize = 0xffff;
        unique_ptr<char> buff( new char[nBlobSize]);

        // inserting data
        {
            char* p = buff.get();
            for( int i = 0; i < nBlobSize; i++)
                *(p++) = i;

            unique_ptr<CDB_LangCmd> tmp_cmd(con->LangCmd("tmp"));

            string sql = "insert into tmp_t1 values";
            sql += "(1, '2002-11-25 12:45:59', 'Hello, world', 'SOME TEXT', 3.1415, '";
            sql += reinterpret_cast<CMySQL_LangCmd*>(tmp_cmd.get())->EscapeString( buff.get(), nBlobSize);
            sql += ")";

            unique_ptr<CDB_LangCmd> lcmd(con->LangCmd(sql));
            lcmd->Send();
            cout << "Data inserted " << lcmd->RowCount() << " row(s) affected" << endl;
        }

        // selecting data
        {
            unique_ptr<CDB_LangCmd> lcmd(con->LangCmd("select * from tmp_t1"));
            lcmd->Send();
            while (lcmd->HasMoreResults()) {
                unique_ptr<CDB_Result> r(lcmd->Result());
                while (r->Fetch()) {
                    CDB_Int a;
                    CDB_DateTime b;
                    CDB_VarChar c;
                    CDB_VarChar d;
                    CDB_Double e;
                    CDB_Image blob;

                    r->GetItem(&a);
                    r->GetItem(&b);
                    r->GetItem(&c);
                    r->GetItem(&d);
                    r->GetItem(&e);
                    r->GetItem(&blob);

                    unique_ptr<char> buff2( new char[blob.Size()]);
                    blob.Read( buff2.get(), blob.Size());
                    int correct = memcmp( buff2.get(), buff.get(), nBlobSize);

                    cout
                        << "a=" << a.Value() << endl
                        << "b=" << b.Value().AsString() << endl
                        << "c=" << c.AsString() << endl
                        << "d=" << d.AsString() << endl
                        << "e=" << e.Value() << endl
                        << "blob size is " << nBlobSize << " blob data is "
                        << (!correct ? "correct" : "not correct") << endl;
                }
            }
        }

        // selecting data as strings
        {
            unique_ptr<CDB_LangCmd> lcmd(con->LangCmd("select * from tmp_t1"));
            lcmd->Send();
            while (lcmd->HasMoreResults()) {
                unique_ptr<CDB_Result> r(lcmd->Result());
                for(unsigned i = 0; i < r->NofItems(); ++i)
                    cout << "[" << r->ItemName(i) << "]";
                cout << endl;

                while (r->Fetch()) {
                    for(unsigned i = 0; i < r->NofItems(); ++i) {
                        CDB_VarChar field;
                        r->GetItem(&field);
                        if(! field.IsNULL())
                            cout << field.AsString() << endl;
                                else
                                    cout << "NULL\n";

                    }
                }
            }
        }
    } catch (CDB_Exception& e) {
        CDB_UserHandler_Stream myExHandler(&cerr);

        myExHandler.HandleIt(&e);
        return 1;
    } catch (const CException&) {
        return 1;
    }

    return 0;
}
コード例 #7
0
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;
}
コード例 #8
0
ファイル: test_buf_istream.cpp プロジェクト: rdumitriu/geryon
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
}
コード例 #9
0
ファイル: test_buf_istream.cpp プロジェクト: rdumitriu/geryon
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
}
コード例 #10
0
ファイル: test_buf_istream.cpp プロジェクト: rdumitriu/geryon
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;
}