void BlockFileInputStreamTestCase::testSeekInBuffer()
{
    OutputStreamPtr pOutput = m_pBlockFileSystem->createFile("testfile1");

    size_t dataSize = 10000;
    stringstream content;
    for (size_t i = 0; i < dataSize; ++i)
    {
        content << (i % 10);
    }
    pOutput->write((const void*)content.str().c_str(), content.str().size());
    pOutput.reset();

    InputStreamPtr pInput = m_pBlockFileSystem->openFile("testfile1");
    CPPUNIT_ASSERT(pInput != NULL);   

    CPPUNIT_ASSERT_EQUAL(dataSize, (size_t)pInput->getSize());   
    off_t off = 100;
    string readCont;
    readCont.resize((size_t)off);
    pInput->read((void*)readCont.c_str(), (size_t)off);
    pInput->seek(off);

    size_t readSize = 1000;
    readCont.resize(readSize);
    pInput->read((void*)readCont.c_str(), readSize);
    
    string expStr = content.str().substr((size_t)off, readSize);
    CPPUNIT_ASSERT_EQUAL(expStr, readCont);

    pInput.reset();
}
void BlockFileInputStreamTestCase::testReadInt()
{
    OutputStreamPtr pOutput = m_pBlockFileSystem->createFile("testfile1");
    uint8_t ui8v =81;
    int32_t i32v = 321;
    int64_t i64v = ((int64_t)1 << 32) + 641;

    string str(129, '1');
    
    pOutput->writeByte(ui8v);
    pOutput->writeInt32(i32v);
    pOutput->write(str.c_str(), str.size());
    pOutput->writeVInt32(i32v);
    pOutput->writeInt64(i64v);
    pOutput->writeVInt64(i64v);
    pOutput.reset();

    InputStreamPtr pInput = m_pBlockFileSystem->openFile("testfile1");
    CPPUNIT_ASSERT(pInput);

    string expStr;
    expStr.resize(str.size());

    CPPUNIT_ASSERT_EQUAL(ui8v, pInput->readByte());
    CPPUNIT_ASSERT_EQUAL(i32v, pInput->readInt32());

    pInput->read((void*)expStr.c_str(), str.size());
    CPPUNIT_ASSERT_EQUAL(str, expStr);

    CPPUNIT_ASSERT_EQUAL(i32v, pInput->readVInt32());
    CPPUNIT_ASSERT_EQUAL(i64v, pInput->readInt64());
    CPPUNIT_ASSERT_EQUAL(i64v, pInput->readVInt64());
}
void BlockFileOutputStreamTestCase::testWriteFromInputStream()
{
    const static size_t MAX_TEST_DATA = 10000;
    for (size_t i = 1; i < MAX_TEST_DATA; i += 31)
    {
        OutputStreamPtr pOutput = m_pBlockFileSystem->createFile("testfile1");

        string answer;
        makeData(answer, *pOutput, i);
        pOutput.reset();
        
        InputStreamPtr pInput = m_pBlockFileSystem->openFile("testfile1");

        pOutput = m_pBlockFileSystem->createFile("testfile2");
        pOutput->write(*pInput);
        pOutput.reset();

        pInput = m_pBlockFileSystem->openFile("testfile2");
        
        string expStr;
        expStr.resize(i);
        pInput->read((void*)expStr.c_str(), i);
        assert(answer==expStr);        
        CPPUNIT_ASSERT_EQUAL(answer, expStr);
    }
}
void BlockFileOutputStreamTestCase::testSeekAndWrite()
{
    size_t dataSize = 10000;
    stringstream content;
    for (size_t i = 0; i < dataSize; ++i)
    {
        content << (i % 10);
    }

    for (size_t i = 0; i < dataSize - 1; ++i)
    {
        OutputStreamPtr pOutput = m_pBlockFileSystem->createFile("testfile1");
        pOutput->write((const void*) content.str().c_str(), i);
        if (i % 137)
        {
            pOutput->write((const void*) content.str().c_str(), i % dataSize);
        }
        pOutput->seek(i);
        pOutput->write((const void*) (content.str().c_str() + i), dataSize - i);
        pOutput->close();

        InputStreamPtr pInput = m_pBlockFileSystem->openFile("testfile1");
        string readCont;
        readCont.resize(dataSize);
        pInput->read((void*)readCont.c_str(), dataSize);

        CPPUNIT_ASSERT_EQUAL(content.str(), readCont);
    }
}
Exemplo n.º 5
0
void XMLConfigurator::load(const string& sCfgFile, FileSystemPtr& pFileSys)
{
    InputStreamPtr pInStream = pFileSys->openFile(sCfgFile);
    string str;
    str.resize((size_t)pInStream->getSize());
    pInStream->read((void*)str.c_str(), str.length());
    loadFromBuffer(str);
}
Exemplo n.º 6
0
void
Ice::ice_readObject(const InputStreamPtr& in, ObjectPtr& p)
{
    in->read(p);
}