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);
    }
}
void BlockFileInputStreamTestCase::testSeekAndRead()
{
    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());   

    for (size_t i = 0; i < dataSize - 1; ++i)
    {
        string readCont;
        readCont.resize(dataSize - i);
        if (i % 147 == 0)
        {
            pInput->seek(i % 789);
        }
        pInput->seekAndRead(i, (void*)readCont.c_str(), dataSize - i);

        string expStr = content.str().substr(i);
//        assert(expStr == readCont);
        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 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 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);
    }
}
Exemplo n.º 6
0
void XMLConfigurator::save(const string& sCfgFile, FileSystemPtr& pFileSys)
{
    XMLDocumentWrapper xmlDoc;
    XMLNodeWrapperPtr pRoot = xmlDoc.appendNode(
            XMLDocumentWrapper::NODE_ELEMENT, CONFIGURE_TAG_NAME);
    Iterator it = iterator();
    while (it.hasNext())
    {
        Configurator::KeyValuePair kv = it.next();

        if (kv.second.getType() == typeid(Configurator::ConfMap))
        {
            XMLNodeWrapperPtr pNode = xmlDoc.allocateNode(
                    XMLDocumentWrapper::NODE_ELEMENT, kv.first.c_str());
            save(xmlDoc, pNode, AnyCast<Configurator::ConfMap>(kv.second));
            pRoot->appendNode(pNode);
        }
        else 
        {
            string str = AnyCast<string>(kv.second);
            XMLNodeWrapperPtr pNode = xmlDoc.allocateNode(
                    XMLDocumentWrapper::NODE_ELEMENT, kv.first.c_str(), str);
            pRoot->appendNode(pNode);
        }
    }

    OutputStreamPtr pOutStream = pFileSys->createFile(sCfgFile);
    if (pOutStream.isNull())
    {
        FIRTEX_THROW(FileIOException, "Save configure [%s] FAILED ",
                     sCfgFile.c_str());
    }
    string str;
    xmlDoc.addDeclarationNode("UTF-8");
    xmlDoc.print(str);
    pOutStream->write((const void*)str.c_str(), str.length());
}
Exemplo n.º 7
0
void
Ice::ice_writeObject(const OutputStreamPtr& out, const ObjectPtr& p)
{
    out->write(p);
}