Replace wxScopedPtr with std::unique_ptr in the tests

Just use the standard class instead of the wx one, as they can be used
in exactly the same way.
This commit is contained in:
Vadim Zeitlin 2023-03-06 23:34:44 +01:00
parent 29a97bb52d
commit 363f0988cf
34 changed files with 185 additions and 152 deletions

View file

@ -19,6 +19,7 @@
#include <string>
#include <list>
#include <map>
#include <memory>
#include <sys/stat.h>
using std::string;
@ -537,7 +538,7 @@ TestEntry& ArchiveTestCase<ClassFactoryT>::Add(const char *name,
template <class ClassFactoryT>
void ArchiveTestCase<ClassFactoryT>::CreateArchive(wxOutputStream& out)
{
wxScopedPtr<OutputStreamT> arc(m_factory->NewStream(out));
std::unique_ptr<OutputStreamT> arc(m_factory->NewStream(out));
TestEntries::iterator it;
OnCreateArchive(*arc);
@ -565,7 +566,7 @@ void ArchiveTestCase<ClassFactoryT>::CreateArchive(wxOutputStream& out)
if ((choices & 2) || testEntry.IsText()) {
// try PutNextEntry(EntryT *pEntry)
wxScopedPtr<EntryT> entry(m_factory->NewEntry());
std::unique_ptr<EntryT> entry(m_factory->NewEntry());
entry->SetName(name, wxPATH_UNIX);
if (setIsDir)
entry->SetIsDir();
@ -681,8 +682,8 @@ template <class ClassFactoryT>
void ArchiveTestCase<ClassFactoryT>::ModifyArchive(wxInputStream& in,
wxOutputStream& out)
{
wxScopedPtr<InputStreamT> arcIn(m_factory->NewStream(in));
wxScopedPtr<OutputStreamT> arcOut(m_factory->NewStream(out));
std::unique_ptr<InputStreamT> arcIn(m_factory->NewStream(in));
std::unique_ptr<OutputStreamT> arcOut(m_factory->NewStream(out));
EntryT *pEntry;
const wxString deleteName = wxT("bin/bin1000");
@ -694,7 +695,7 @@ void ArchiveTestCase<ClassFactoryT>::ModifyArchive(wxInputStream& in,
arcOut->CopyArchiveMetaData(*arcIn);
while ((pEntry = arcIn->GetNextEntry()) != nullptr) {
wxScopedPtr<EntryT> entry(pEntry);
std::unique_ptr<EntryT> entry(pEntry);
OnSetNotifier(*entry);
wxString name = entry->GetName(wxPATH_UNIX);
@ -739,7 +740,7 @@ void ArchiveTestCase<ClassFactoryT>::ModifyArchive(wxInputStream& in,
// try adding a new entry
TestEntry& testEntry = Add(newName.mb_str(), newData);
wxScopedPtr<EntryT> newentry(m_factory->NewEntry());
std::unique_ptr<EntryT> newentry(m_factory->NewEntry());
newentry->SetName(newName);
newentry->SetDateTime(testEntry.GetDateTime());
newentry->SetSize(testEntry.GetLength());
@ -762,7 +763,7 @@ void ArchiveTestCase<ClassFactoryT>::ExtractArchive(wxInputStream& in)
typedef std::list<EntryPtr> Entries;
typedef typename Entries::iterator EntryIter;
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
int expectedTotal = m_testEntries.size();
EntryPtr entry;
Entries entries;
@ -973,13 +974,13 @@ void ArchiveTestCase<ClassFactoryT>::TestIterator(wxInputStream& in)
typedef std::list<EntryT*> ArchiveCatalog;
typedef typename ArchiveCatalog::iterator CatalogIter;
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
size_t count = 0;
ArchiveCatalog cat((IterT)*arc, IterT());
for (CatalogIter it = cat.begin(); it != cat.end(); ++it) {
wxScopedPtr<EntryT> entry(*it);
std::unique_ptr<EntryT> entry(*it);
count += m_testEntries.count(entry->GetName(wxPATH_UNIX));
}
@ -996,13 +997,13 @@ void ArchiveTestCase<ClassFactoryT>::TestPairIterator(wxInputStream& in)
typedef std::map<wxString, EntryT*> ArchiveCatalog;
typedef typename ArchiveCatalog::iterator CatalogIter;
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
size_t count = 0;
ArchiveCatalog cat((PairIterT)*arc, PairIterT());
for (CatalogIter it = cat.begin(); it != cat.end(); ++it) {
wxScopedPtr<EntryT> entry(it->second);
std::unique_ptr<EntryT> entry(it->second);
count += m_testEntries.count(entry->GetName(wxPATH_UNIX));
}
@ -1019,7 +1020,7 @@ void ArchiveTestCase<ClassFactoryT>::TestSmartIterator(wxInputStream& in)
typedef typename ArchiveCatalog::iterator CatalogIter;
typedef wxArchiveIterator<InputStreamT, Ptr<EntryT> > Iter;
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
ArchiveCatalog cat((Iter)*arc, Iter());
@ -1039,7 +1040,7 @@ void ArchiveTestCase<ClassFactoryT>::TestSmartPairIterator(wxInputStream& in)
typedef wxArchiveIterator<InputStreamT,
std::pair<wxString, Ptr<EntryT> > > PairIter;
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
ArchiveCatalog cat((PairIter)*arc, PairIter());
@ -1060,8 +1061,8 @@ void ArchiveTestCase<ClassFactoryT>::ReadSimultaneous(TestInputStream& in)
// create two archive input streams
TestInputStream in2(in);
wxScopedPtr<InputStreamT> arc(m_factory->NewStream(in));
wxScopedPtr<InputStreamT> arc2(m_factory->NewStream(in2));
std::unique_ptr<InputStreamT> arc(m_factory->NewStream(in));
std::unique_ptr<InputStreamT> arc2(m_factory->NewStream(in2));
// load the catalog
ArchiveCatalog cat((PairIter)*arc, PairIter());
@ -1147,7 +1148,7 @@ protected:
void CreateArchive(wxOutputStream& out);
void ExtractArchive(wxInputStream& in);
wxScopedPtr<wxArchiveClassFactory> m_factory; // factory to make classes
std::unique_ptr<wxArchiveClassFactory> m_factory; // factory to make classes
int m_options; // test options
};
@ -1187,7 +1188,7 @@ void CorruptionTestCase::runTest()
void CorruptionTestCase::CreateArchive(wxOutputStream& out)
{
wxScopedPtr<wxArchiveOutputStream> arc(m_factory->NewStream(out));
std::unique_ptr<wxArchiveOutputStream> arc(m_factory->NewStream(out));
arc->PutNextDirEntry(wxT("dir"));
arc->PutNextEntry(wxT("file"));
@ -1196,8 +1197,8 @@ void CorruptionTestCase::CreateArchive(wxOutputStream& out)
void CorruptionTestCase::ExtractArchive(wxInputStream& in)
{
wxScopedPtr<wxArchiveInputStream> arc(m_factory->NewStream(in));
wxScopedPtr<wxArchiveEntry> entry(arc->GetNextEntry());
std::unique_ptr<wxArchiveInputStream> arc(m_factory->NewStream(in));
std::unique_ptr<wxArchiveEntry> entry(arc->GetNextEntry());
while (entry.get() != nullptr) {
char buf[1024];

View file

@ -12,7 +12,6 @@
#define WX_TEST_ARCHIVE_ITERATOR
#include "wx/archive.h"
#include "wx/scopedptr.h"
#include "wx/wfstream.h"
#include <map>
@ -220,7 +219,7 @@ protected:
typedef std::map<wxString, TestEntry*> TestEntries;
TestEntries m_testEntries; // test data
wxScopedPtr<ClassFactoryT> m_factory; // factory to make classes
std::unique_ptr<ClassFactoryT> m_factory; // factory to make classes
int m_options; // test options
wxDateTime m_timeStamp; // timestamp to give test entries
int m_id; // select between the possibilites

View file

@ -17,6 +17,8 @@
#include "archivetest.h"
#include "wx/zipstrm.h"
#include <memory>
using std::string;
@ -183,7 +185,7 @@ void ZipPipeTestCase::runTest()
TestInputStream in(out, m_id % ((m_options & PipeIn) ? 4 : 3));
wxZipInputStream zip(in);
wxScopedPtr<wxZipEntry> entry(zip.GetNextEntry());
std::unique_ptr<wxZipEntry> entry(zip.GetNextEntry());
CPPUNIT_ASSERT(entry.get() != nullptr);
if ((m_options & PipeIn) == 0)