コード例 #1
0
void ArchiveTestCase<ClassFactoryT>::TestSmartPairIterator(wxInputStream& in)
{
#if defined _MSC_VER && defined _MSC_VER < 1200
    // With VC++ 5.0 the '=' operator of std::pair breaks when the second
    // type is Ptr<EntryT>, so this iterator can't be made to work.
    (void)in;
#else
    typedef std::map<wxString, Ptr<EntryT> > ArchiveCatalog;
    typedef typename ArchiveCatalog::iterator CatalogIter;
    typedef wxArchiveIterator<InputStreamT,
                std::pair<wxString, Ptr<EntryT> > > PairIter;

    auto_ptr<InputStreamT> arc(m_factory->NewStream(in));

#ifdef WXARC_MEMBER_TEMPLATES
    ArchiveCatalog cat((PairIter)*arc, PairIter());
#else
    ArchiveCatalog cat;
    for (PairIter i(*arc); i != PairIter(); ++i)
        cat.insert(*i);
#endif

    CPPUNIT_ASSERT(m_testEntries.size() == cat.size());

    for (CatalogIter it = cat.begin(); it != cat.end(); ++it)
        CPPUNIT_ASSERT(m_testEntries.count(it->second->GetName(wxPATH_UNIX)));
#endif
}
コード例 #2
0
void ArchiveTestCase<ClassFactoryT>::TestPairIterator(wxInputStream& in)
{
    typedef std::map<wxString, EntryT*> ArchiveCatalog;
    typedef typename ArchiveCatalog::iterator CatalogIter;

    auto_ptr<InputStreamT> arc(m_factory->NewStream(in));
    size_t count = 0;

#ifdef WXARC_MEMBER_TEMPLATES
    ArchiveCatalog cat((PairIterT)*arc, PairIterT());
#else
    ArchiveCatalog cat;
    for (PairIterT i(*arc); i != PairIterT(); ++i)
        cat.insert(*i);
#endif

    for (CatalogIter it = cat.begin(); it != cat.end(); ++it) {
        auto_ptr<EntryT> entry(it->second);
        count += m_testEntries.count(entry->GetName(wxPATH_UNIX));
    }

    CPPUNIT_ASSERT(m_testEntries.size() == cat.size());
    CPPUNIT_ASSERT(count == cat.size());
}
コード例 #3
0
void ArchiveTestCase<ClassFactoryT>::ReadSimultaneous(TestInputStream& in)
{
    typedef std::map<wxString, Ptr<EntryT> > ArchiveCatalog;
    typedef wxArchiveIterator<InputStreamT,
                std::pair<wxString, Ptr<EntryT> > > PairIter;

    // create two archive input streams
    TestInputStream in2(in);
    auto_ptr<InputStreamT> arc(m_factory->NewStream(in));
    auto_ptr<InputStreamT> arc2(m_factory->NewStream(in2));

    // load the catalog
#ifdef WXARC_MEMBER_TEMPLATES
    ArchiveCatalog cat((PairIter)*arc, PairIter());
#else
    ArchiveCatalog cat;
    for (PairIter i(*arc); i != PairIter(); ++i)
        cat.insert(*i);
#endif

    // the names of two entries to read
    const wxChar *name = _T("text/small");
    const wxChar *name2 = _T("bin/bin1000");

    // open them
    typename ArchiveCatalog::iterator j;
    CPPUNIT_ASSERT((j = cat.find(name)) != cat.end());
    CPPUNIT_ASSERT(arc->OpenEntry(*j->second));
    CPPUNIT_ASSERT((j = cat.find(name2)) != cat.end());
    CPPUNIT_ASSERT(arc2->OpenEntry(*j->second));

    // get pointers to the expected data
    TestEntries::iterator k;
    CPPUNIT_ASSERT((k = m_testEntries.find(name)) != m_testEntries.end());
    TestEntry *entry = k->second;
    CPPUNIT_ASSERT((k = m_testEntries.find(name2)) != m_testEntries.end());
    TestEntry *entry2 = k->second;

    size_t count = 0, count2 = 0;
    size_t size = entry->GetSize(), size2 = entry2->GetSize();
    const char *data = entry->GetData(), *data2 = entry2->GetData();

    // read and check the two entries in parallel, character by character
    while (arc->IsOk() || arc2->IsOk()) {
        char ch = arc->GetC();
        if (arc->LastRead() == 1) {
            CPPUNIT_ASSERT(count < size);
            CPPUNIT_ASSERT(ch == data[count++]);
        }
        char ch2 = arc2->GetC();
        if (arc2->LastRead() == 1) {
            CPPUNIT_ASSERT(count2 < size2);
            CPPUNIT_ASSERT(ch2 == data2[count2++]);
        }
    }

    CPPUNIT_ASSERT(arc->Eof());
    CPPUNIT_ASSERT(arc2->Eof());
    CPPUNIT_ASSERT(count == size);
    CPPUNIT_ASSERT(count2 == size2);
}