Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/offline/LogSessionDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace MAT_NS_BEGIN

void LogSessionDataProvider::DeleteLogSessionDataFromFile()
{
std::string sessionPath = m_cacheFilePath.empty() ? "" : (m_cacheFilePath + ".ses").c_str();
std::string sessionPath =
(m_cacheFilePath.empty() || m_cacheFilePath == ":memory:") ? "" : m_cacheFilePath + ".ses";
if (!sessionPath.empty() && MAT::FileExists(sessionPath.c_str()))
{
MAT::FileDelete(sessionPath.c_str());
Expand All @@ -108,7 +109,8 @@ namespace MAT_NS_BEGIN
{
uint64_t sessionFirstTimeLaunch = 0;
std::string sessionSDKUid;
std::string sessionPath = m_cacheFilePath.empty() ? "" : (m_cacheFilePath + ".ses").c_str();
std::string sessionPath =
(m_cacheFilePath.empty() || m_cacheFilePath == ":memory:") ? "" : m_cacheFilePath + ".ses";
if (!sessionPath.empty())
{
if (MAT::FileExists(sessionPath.c_str()))
Expand Down Expand Up @@ -209,4 +211,3 @@ namespace MAT_NS_BEGIN
}
}
MAT_NS_END

21 changes: 19 additions & 2 deletions tests/functests/LogSessionDataFuncTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ using namespace MAT;

const std::string SessionFileArgument = "test";
const char* const SessionFile = "test.ses";
const char* const MemorySessionFile = ":memory:.ses";

class LogSessionDataFuncTests : public ::testing::Test
{
void CleanupLocalSessionFile()
{
if (MAT::FileExists(SessionFile))
for (const auto* sessionFile : {SessionFile, MemorySessionFile})
{
MAT::FileDelete(SessionFile);
if (MAT::FileExists(sessionFile))
{
MAT::FileDelete(sessionFile);
}
}
}

Expand Down Expand Up @@ -76,6 +80,19 @@ TEST_F(LogSessionDataFuncTests, Constructor_SessionFile_FileCreated)
ASSERT_TRUE(MAT::FileExists(SessionFile));
}

TEST_F(LogSessionDataFuncTests, Constructor_InMemoryCache_NoSessionFileCreated)
{
auto logSessionDataProvider = LogSessionDataProvider(":memory:");
logSessionDataProvider.CreateLogSessionData();
ASSERT_NE(logSessionDataProvider.GetLogSessionData(), nullptr);
EXPECT_FALSE(MAT::FileExists(MemorySessionFile));

logSessionDataProvider.ResetLogSessionData();
EXPECT_FALSE(MAT::FileExists(MemorySessionFile));
logSessionDataProvider.DeleteLogSessionData();
EXPECT_FALSE(MAT::FileExists(MemorySessionFile));
}

TEST_F(LogSessionDataFuncTests, Constructor_ValidSessionFileExists_MembersSetToExistingFile)
{
const std::string validSessionFirstTime{ "123456" };
Expand Down
Loading