mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Try to use unique_ptr in tests so we can't forget to delete
This commit is contained in:
parent
e7fafc5a4f
commit
4ac5ca1449
|
@ -1,5 +1,6 @@
|
|||
#include "test.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
#include <engine/shared/datafile.h>
|
||||
#include <engine/storage.h>
|
||||
|
@ -7,7 +8,7 @@
|
|||
|
||||
TEST(Datafile, ExtendedType)
|
||||
{
|
||||
IStorage *pStorage = CreateLocalStorage();
|
||||
auto pStorage = std::unique_ptr<IStorage>(CreateLocalStorage());
|
||||
CTestInfo Info;
|
||||
|
||||
CMapItemTest Test;
|
||||
|
@ -19,7 +20,7 @@ TEST(Datafile, ExtendedType)
|
|||
|
||||
{
|
||||
CDataFileWriter Writer;
|
||||
Writer.Open(pStorage, Info.m_aFilename);
|
||||
Writer.Open(pStorage.get(), Info.m_aFilename);
|
||||
|
||||
Writer.AddItem(MAPITEMTYPE_TEST, 0x8000, sizeof(Test), &Test);
|
||||
|
||||
|
@ -28,7 +29,7 @@ TEST(Datafile, ExtendedType)
|
|||
|
||||
{
|
||||
CDataFileReader Reader;
|
||||
Reader.Open(pStorage, Info.m_aFilename, IStorage::TYPE_ALL);
|
||||
Reader.Open(pStorage.get(), Info.m_aFilename, IStorage::TYPE_ALL);
|
||||
|
||||
int Start, Num;
|
||||
Reader.GetType(MAPITEMTYPE_TEST, &Start, &Num);
|
||||
|
@ -56,6 +57,4 @@ TEST(Datafile, ExtendedType)
|
|||
{
|
||||
pStorage->RemoveFile(Info.m_aFilename, IStorage::TYPE_SAVE);
|
||||
}
|
||||
|
||||
delete pStorage;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
#include <engine/client/serverbrowser_ping_cache.h>
|
||||
#include <engine/console.h>
|
||||
|
@ -10,9 +11,10 @@
|
|||
TEST(ServerBrowser, PingCache)
|
||||
{
|
||||
CTestInfo Info;
|
||||
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
|
||||
IStorage *pStorage = Info.CreateTestStorage();
|
||||
IServerBrowserPingCache *pPingCache = CreateServerBrowserPingCache(pConsole, pStorage);
|
||||
|
||||
auto pConsole = std::unique_ptr<IConsole>(CreateConsole(CFGFLAG_CLIENT));
|
||||
auto pStorage = std::unique_ptr<IStorage>(Info.CreateTestStorage());
|
||||
auto pPingCache = std::unique_ptr<IServerBrowserPingCache>(CreateServerBrowserPingCache(pConsole.get(), pStorage.get()));
|
||||
|
||||
const IServerBrowserPingCache::CEntry *pEntries;
|
||||
int NumEntries;
|
||||
|
@ -84,8 +86,7 @@ TEST(ServerBrowser, PingCache)
|
|||
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
||||
}
|
||||
|
||||
delete pPingCache;
|
||||
pPingCache = CreateServerBrowserPingCache(pConsole, pStorage);
|
||||
pPingCache.reset(CreateServerBrowserPingCache(pConsole.get(), pStorage.get()));
|
||||
|
||||
// Persistence.
|
||||
pPingCache->Load();
|
||||
|
@ -99,9 +100,5 @@ TEST(ServerBrowser, PingCache)
|
|||
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
||||
}
|
||||
|
||||
delete pPingCache;
|
||||
delete pStorage;
|
||||
delete pConsole;
|
||||
|
||||
Info.DeleteTestStorageFilesOnSuccess();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue