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 "test.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <engine/shared/datafile.h>
|
#include <engine/shared/datafile.h>
|
||||||
#include <engine/storage.h>
|
#include <engine/storage.h>
|
||||||
|
@ -7,7 +8,7 @@
|
||||||
|
|
||||||
TEST(Datafile, ExtendedType)
|
TEST(Datafile, ExtendedType)
|
||||||
{
|
{
|
||||||
IStorage *pStorage = CreateLocalStorage();
|
auto pStorage = std::unique_ptr<IStorage>(CreateLocalStorage());
|
||||||
CTestInfo Info;
|
CTestInfo Info;
|
||||||
|
|
||||||
CMapItemTest Test;
|
CMapItemTest Test;
|
||||||
|
@ -19,7 +20,7 @@ TEST(Datafile, ExtendedType)
|
||||||
|
|
||||||
{
|
{
|
||||||
CDataFileWriter Writer;
|
CDataFileWriter Writer;
|
||||||
Writer.Open(pStorage, Info.m_aFilename);
|
Writer.Open(pStorage.get(), Info.m_aFilename);
|
||||||
|
|
||||||
Writer.AddItem(MAPITEMTYPE_TEST, 0x8000, sizeof(Test), &Test);
|
Writer.AddItem(MAPITEMTYPE_TEST, 0x8000, sizeof(Test), &Test);
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ TEST(Datafile, ExtendedType)
|
||||||
|
|
||||||
{
|
{
|
||||||
CDataFileReader Reader;
|
CDataFileReader Reader;
|
||||||
Reader.Open(pStorage, Info.m_aFilename, IStorage::TYPE_ALL);
|
Reader.Open(pStorage.get(), Info.m_aFilename, IStorage::TYPE_ALL);
|
||||||
|
|
||||||
int Start, Num;
|
int Start, Num;
|
||||||
Reader.GetType(MAPITEMTYPE_TEST, &Start, &Num);
|
Reader.GetType(MAPITEMTYPE_TEST, &Start, &Num);
|
||||||
|
@ -56,6 +57,4 @@ TEST(Datafile, ExtendedType)
|
||||||
{
|
{
|
||||||
pStorage->RemoveFile(Info.m_aFilename, IStorage::TYPE_SAVE);
|
pStorage->RemoveFile(Info.m_aFilename, IStorage::TYPE_SAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete pStorage;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <engine/client/serverbrowser_ping_cache.h>
|
#include <engine/client/serverbrowser_ping_cache.h>
|
||||||
#include <engine/console.h>
|
#include <engine/console.h>
|
||||||
|
@ -10,9 +11,10 @@
|
||||||
TEST(ServerBrowser, PingCache)
|
TEST(ServerBrowser, PingCache)
|
||||||
{
|
{
|
||||||
CTestInfo Info;
|
CTestInfo Info;
|
||||||
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
|
|
||||||
IStorage *pStorage = Info.CreateTestStorage();
|
auto pConsole = std::unique_ptr<IConsole>(CreateConsole(CFGFLAG_CLIENT));
|
||||||
IServerBrowserPingCache *pPingCache = CreateServerBrowserPingCache(pConsole, pStorage);
|
auto pStorage = std::unique_ptr<IStorage>(Info.CreateTestStorage());
|
||||||
|
auto pPingCache = std::unique_ptr<IServerBrowserPingCache>(CreateServerBrowserPingCache(pConsole.get(), pStorage.get()));
|
||||||
|
|
||||||
const IServerBrowserPingCache::CEntry *pEntries;
|
const IServerBrowserPingCache::CEntry *pEntries;
|
||||||
int NumEntries;
|
int NumEntries;
|
||||||
|
@ -84,8 +86,7 @@ TEST(ServerBrowser, PingCache)
|
||||||
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete pPingCache;
|
pPingCache.reset(CreateServerBrowserPingCache(pConsole.get(), pStorage.get()));
|
||||||
pPingCache = CreateServerBrowserPingCache(pConsole, pStorage);
|
|
||||||
|
|
||||||
// Persistence.
|
// Persistence.
|
||||||
pPingCache->Load();
|
pPingCache->Load();
|
||||||
|
@ -99,9 +100,5 @@ TEST(ServerBrowser, PingCache)
|
||||||
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
EXPECT_EQ(pEntries[1].m_Ping, 345);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete pPingCache;
|
|
||||||
delete pStorage;
|
|
||||||
delete pConsole;
|
|
||||||
|
|
||||||
Info.DeleteTestStorageFilesOnSuccess();
|
Info.DeleteTestStorageFilesOnSuccess();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue