update review comments
This commit is contained in:
Родитель
09dd7dcb0f
Коммит
0db227acf0
|
@ -41,6 +41,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\http\HttpRequestEncoder.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\http\HttpResponseDecoder.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\MemoryStorage.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\LogSessionDataProvider.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageHandler.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorage_SQLite.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\StorageObserver.cpp" />
|
||||
|
@ -197,4 +198,4 @@
|
|||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\Version.hpp.template" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -161,6 +161,8 @@
|
|||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\OfflineStorageHandler.cpp">
|
||||
<Filter>offline</Filter>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\offline\LogSessionDataProvider.cpp">
|
||||
<Filter>offline</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogConfiguration.cpp">
|
||||
<Filter>api</Filter>
|
||||
|
@ -619,4 +621,4 @@
|
|||
<Filter>include\public</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -42,6 +42,7 @@ set(SRCS decorators/BaseDecorator.cpp
|
|||
offline/MemoryStorage.cpp
|
||||
offline/OfflineStorage_SQLite.cpp
|
||||
offline/OfflineStorageHandler.cpp
|
||||
offline/LogSessionDataProvider.cpp
|
||||
backoff/IBackoff.cpp
|
||||
pal/PAL.cpp
|
||||
pal/TaskDispatcher_CAPI.cpp
|
||||
|
|
|
@ -53,6 +53,7 @@ set(SRCS
|
|||
${SDK_ROOT}/lib/jni/SemanticContext_jni.cpp
|
||||
${SDK_ROOT}/lib/jni/Utils_jni.cpp
|
||||
${SDK_ROOT}/lib/offline/MemoryStorage.cpp
|
||||
${SDK_ROOT}/lib/offline/LogSessionDataProvider.cpp
|
||||
${SDK_ROOT}/lib/offline/OfflineStorageHandler.cpp
|
||||
${SDK_ROOT}/lib/offline/StorageObserver.cpp
|
||||
${SDK_ROOT}/lib/packager/BondSplicer.cpp
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "mat/config.h"
|
||||
|
||||
#include "offline/OfflineStorageHandler.hpp"
|
||||
#include "offline/LogSessionDataProvider.hpp"
|
||||
|
||||
#include "system/TelemetrySystem.hpp"
|
||||
|
||||
|
@ -268,8 +269,14 @@ namespace ARIASDK_NS_BEGIN
|
|||
|
||||
m_offlineStorage.reset(new OfflineStorageHandler(*this, *m_config, *m_taskDispatcher));
|
||||
|
||||
m_system.reset(new TelemetrySystem(*this, *m_config, *m_offlineStorage, *m_httpClient, *m_taskDispatcher, m_bandwidthController,
|
||||
m_logSessionData, cacheFilePath ));
|
||||
#if defined(STORE_SESSION_DB) && defined(HAVE_MAT_STORAGE)
|
||||
LogSessionDataProvider logSessionDataProvider(m_offlineStorage);
|
||||
#else
|
||||
LogSessionDataProvider logSessionDataProvider(cacheFilePath);
|
||||
#endif
|
||||
|
||||
m_system.reset(new TelemetrySystem(*this, *m_config, *m_offlineStorage, *m_httpClient, *m_taskDispatcher, m_bandwidthController, &logSessionDataProvider,
|
||||
m_logSessionData));
|
||||
LOG_TRACE("Telemetry system created, starting up...");
|
||||
if (m_system && !deferSystemStart)
|
||||
{
|
||||
|
|
|
@ -18,15 +18,15 @@ namespace ARIASDK_NS_BEGIN
|
|||
/// Gets the time that this session began.
|
||||
/// </summary>
|
||||
/// <returns>A 64-bit integer that contains the time.</returns>
|
||||
unsigned long long getSessionFirstTime() const ;
|
||||
unsigned long long getSessionFirstTime() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SDK unique identifier.
|
||||
/// </summary>
|
||||
std::string getSessionSDKUid() const ;
|
||||
std::string getSessionSDKUid() const;
|
||||
|
||||
protected:
|
||||
unsigned long long m_sessionFirstTimeLaunch{0ull} ;
|
||||
unsigned long long m_sessionFirstTimeLaunch{0ull};
|
||||
std::string m_sessionSDKUid;
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
#include "LogSessionDataProvider.hpp"
|
||||
#include "utils/FileUtils.hpp"
|
||||
#include "utils/StringUtils.hpp"
|
||||
|
||||
namespace ARIASDK_NS_BEGIN
|
||||
{
|
||||
static const char* sessionFirstLaunchTimeName = "sessionfirstlaunchtime";
|
||||
static const char* sessionSdkUidName = "sessionsdkuid";
|
||||
|
||||
std::shared_ptr<LogSessionData> LogSessionDataProvider::GetLogSessionData()
|
||||
{
|
||||
if (m_storageType == SessionStorageType::FILE_STORE ) {
|
||||
return GetLogSessionDataFromFile();
|
||||
} else {
|
||||
return GetLogSessionDataFromDB();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<LogSessionData> LogSessionDataProvider::GetLogSessionDataFromDB()
|
||||
{
|
||||
std::string sessionSDKUid;
|
||||
unsigned long long sessionFirstTimeLaunch = 0;
|
||||
if (nullptr != m_offlineStorage)
|
||||
{
|
||||
sessionSDKUid = m_offlineStorage->GetSetting(sessionSdkUidName);
|
||||
sessionFirstTimeLaunch = convertStrToLong(m_offlineStorage->GetSetting(sessionFirstLaunchTimeName));
|
||||
if ((sessionFirstTimeLaunch == 0) || sessionSDKUid.empty()) {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
if (!m_offlineStorage->StoreSetting(sessionFirstLaunchTimeName, std::to_string(sessionFirstTimeLaunch))) {
|
||||
LOG_WARN("Unable to save session analytics to DB for %d", sessionFirstLaunchTimeName);
|
||||
}
|
||||
if (!m_offlineStorage->StoreSetting(sessionSdkUidName, sessionSDKUid)) {
|
||||
LOG_WARN("Unable to save session analytics to DB for %s", sessionSDKUid.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::make_shared<LogSessionData>(sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
|
||||
std::shared_ptr<LogSessionData> LogSessionDataProvider::GetLogSessionDataFromFile()
|
||||
{
|
||||
std::string sessionSDKUid;
|
||||
unsigned long long sessionFirstTimeLaunch = 0;
|
||||
std::string sessionPath = m_cacheFilePath.empty() ? "" : (m_cacheFilePath + ".ses").c_str();
|
||||
if (!sessionPath.empty()) {
|
||||
if (MAT::FileExists(sessionPath.c_str())) {
|
||||
auto content = MAT::FileGetContents(sessionPath.c_str());
|
||||
if (!parse (content, sessionFirstTimeLaunch, sessionSDKUid)) {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
writeFileContents(sessionPath, sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
} else {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
writeFileContents(sessionPath, sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
}
|
||||
return std::make_shared<LogSessionData>(sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
|
||||
bool LogSessionDataProvider::parse(
|
||||
const std::string &content,
|
||||
unsigned long long &sessionFirstTimeLaunch,
|
||||
std::string &sessionSDKUid)
|
||||
{
|
||||
if (content.empty()) {
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> v;
|
||||
StringUtils::SplitString(content, '\n', v);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
remove_eol(v[0]);
|
||||
remove_eol(v[1]);
|
||||
sessionFirstTimeLaunch = convertStrToLong(v[0]);
|
||||
if (sessionFirstTimeLaunch == 0 ) {
|
||||
return false;
|
||||
}
|
||||
sessionSDKUid = v[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long long LogSessionDataProvider::convertStrToLong(const std::string& s)
|
||||
{
|
||||
unsigned long long res = 0ull;
|
||||
try
|
||||
{
|
||||
res = std::stoull(s);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
LOG_WARN("Non-integer data passed to std::stoull");
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
LOG_WARN("Value passed to std::stoull was larger than unsigned long long could represent");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void LogSessionDataProvider::writeFileContents(
|
||||
const std::string &path,
|
||||
unsigned long long sessionFirstTimeLaunch,
|
||||
const std::string &sessionSDKUid)
|
||||
{
|
||||
std::string contents;
|
||||
contents += std::to_string(sessionFirstTimeLaunch);
|
||||
contents += '\n';
|
||||
contents += sessionSDKUid;
|
||||
contents += '\n';
|
||||
if (!MAT::FileWrite(path.c_str(), contents.c_str()))
|
||||
{
|
||||
LOG_WARN("Unable to save session analytics to %s", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void LogSessionDataProvider::remove_eol(std::string& result)
|
||||
{
|
||||
if (!result.empty() && result[result.length() - 1] == '\n')
|
||||
{
|
||||
result.erase(result.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
ARIASDK_NS_END
|
||||
|
||||
|
||||
|
|
@ -2,127 +2,48 @@
|
|||
#define MAT_LOGSESSIONDATA_PROVIDER_HPP
|
||||
|
||||
#include "LogSessionData.hpp"
|
||||
#include "utils/FileUtils.hpp"
|
||||
#include "utils/StringUtils.hpp"
|
||||
|
||||
#include "IOfflineStorage.hpp"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace ARIASDK_NS_BEGIN
|
||||
{
|
||||
static const char* sessionFirstLaunchTimeName = "sessionfirstlaunchtime";
|
||||
static const char* sessionSdkUidName = "sessionsdkuid";
|
||||
enum class SessionStorageType {
|
||||
FILE_STORE,
|
||||
DATABASE_STORE
|
||||
};
|
||||
|
||||
class LogSessionDataProvider
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<LogSessionData> CreateLogSessionData(
|
||||
IOfflineStorage* offlineStorage)
|
||||
LogSessionDataProvider(std::shared_ptr<IOfflineStorage> offlineStorage):
|
||||
m_storageType(SessionStorageType::DATABASE_STORE),
|
||||
m_offlineStorage(offlineStorage)
|
||||
|
||||
{
|
||||
std::string sessionSDKUid;
|
||||
unsigned long long sessionFirstTimeLaunch = 0;
|
||||
sessionSDKUid = offlineStorage->GetSetting(sessionSdkUidName);
|
||||
sessionFirstTimeLaunch = convertStrToLong(offlineStorage->GetSetting(sessionFirstLaunchTimeName));
|
||||
if (!sessionFirstTimeLaunch || sessionSDKUid.empty()) {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
if (!offlineStorage->StoreSetting(sessionFirstLaunchTimeName, std::to_string(sessionFirstTimeLaunch))) {
|
||||
LOG_WARN("Unable to save session analytics to DB for %d", sessionFirstLaunchTimeName);
|
||||
}
|
||||
if (!offlineStorage->StoreSetting(sessionSdkUidName, sessionSDKUid)) {
|
||||
LOG_WARN("Unable to save session analytics to DB for %s", sessionSDKUid.c_str());
|
||||
}
|
||||
}
|
||||
return std::make_shared<LogSessionData>(sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
|
||||
static std::shared_ptr<LogSessionData> CreateLogSessionData(
|
||||
std::string const& cacheFilePath)
|
||||
LogSessionDataProvider(std::string const& cacheFilePath):
|
||||
m_storageType(SessionStorageType::FILE_STORE),
|
||||
m_cacheFilePath(cacheFilePath)
|
||||
|
||||
{
|
||||
std::string sessionSDKUid;
|
||||
unsigned long long sessionFirstTimeLaunch = 0;
|
||||
std::string sessionPath = cacheFilePath.empty() ? "" : (cacheFilePath + ".ses").c_str();
|
||||
if (!sessionPath.empty()) {
|
||||
if (MAT::FileExists(sessionPath.c_str())) {
|
||||
auto content = MAT::FileGetContents(sessionPath.c_str());
|
||||
if (!parse (content, sessionFirstTimeLaunch, sessionSDKUid)) {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
writeFileContents(sessionPath, sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
} else {
|
||||
sessionFirstTimeLaunch = PAL::getUtcSystemTimeMs();
|
||||
sessionSDKUid = PAL::generateUuidString();
|
||||
writeFileContents(sessionPath, sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
}
|
||||
return std::make_shared<LogSessionData>(sessionFirstTimeLaunch, sessionSDKUid);
|
||||
}
|
||||
|
||||
std::shared_ptr<LogSessionData> GetLogSessionData();
|
||||
|
||||
protected:
|
||||
static bool parse(
|
||||
const std::string &content,
|
||||
unsigned long long &sessionFirstTimeLaunch,
|
||||
std::string &sessionSDKUid)
|
||||
{
|
||||
if (content.empty()) {
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> v;
|
||||
StringUtils::SplitString(content, '\n', v);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
remove_eol(v[0]);
|
||||
remove_eol(v[1]);
|
||||
sessionFirstTimeLaunch = convertStrToLong(v[0]);
|
||||
if (sessionFirstTimeLaunch == 0 ) {
|
||||
return false;
|
||||
}
|
||||
sessionSDKUid = v[1];
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<LogSessionData> GetLogSessionDataFromFile();
|
||||
std::shared_ptr<LogSessionData> GetLogSessionDataFromDB();
|
||||
bool parse(const std::string &, unsigned long long &, std::string &) ;
|
||||
|
||||
private:
|
||||
static unsigned long long convertStrToLong(const std::string& s)
|
||||
{
|
||||
unsigned long long res = 0ull;
|
||||
try
|
||||
{
|
||||
res = std::stoull(s);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
LOG_WARN("Non-integer data passed to std::stoull");
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
LOG_WARN("Value passed to std::stoull was larger than unsigned long long could represent");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void writeFileContents(
|
||||
const std::string &path,
|
||||
unsigned long long sessionFirstTimeLaunch,
|
||||
const std::string &sessionSDKUid)
|
||||
{
|
||||
std::string contents;
|
||||
contents += std::to_string(sessionFirstTimeLaunch);
|
||||
contents += '\n';
|
||||
contents += sessionSDKUid;
|
||||
contents += '\n';
|
||||
if (!MAT::FileWrite(path.c_str(), contents.c_str()))
|
||||
{
|
||||
LOG_WARN("Unable to save session analytics to %s", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_eol(std::string& result)
|
||||
{
|
||||
if (!result.empty() && result[result.length() - 1] == '\n')
|
||||
{
|
||||
result.erase(result.length() - 1);
|
||||
}
|
||||
}
|
||||
SessionStorageType m_storageType;
|
||||
std::shared_ptr<IOfflineStorage> m_offlineStorage;
|
||||
std::string const m_cacheFilePath;
|
||||
unsigned long long convertStrToLong(const std::string& );
|
||||
void writeFileContents(const std::string &, unsigned long long, const std::string &);
|
||||
void remove_eol(std::string& );
|
||||
};
|
||||
}
|
||||
ARIASDK_NS_END
|
||||
|
|
|
@ -25,8 +25,8 @@ namespace ARIASDK_NS_BEGIN {
|
|||
IHttpClient& httpClient,
|
||||
ITaskDispatcher& taskDispatcher,
|
||||
IBandwidthController* bandwidthController,
|
||||
std::shared_ptr<LogSessionData> &logSessionData,
|
||||
std::string const &cacheFilePath)
|
||||
LogSessionDataProvider* logSessionDataProvider,
|
||||
std::shared_ptr<LogSessionData> &logSessionData)
|
||||
:
|
||||
TelemetrySystemBase(logManager, runtimeConfig, taskDispatcher),
|
||||
compression(runtimeConfig),
|
||||
|
@ -39,15 +39,11 @@ namespace ARIASDK_NS_BEGIN {
|
|||
{
|
||||
|
||||
// Handler for start
|
||||
onStart = [this, &logSessionData, cacheFilePath, &offlineStorage](void)
|
||||
onStart = [this, &logSessionData, &offlineStorage, logSessionDataProvider](void)
|
||||
{
|
||||
bool result = true;
|
||||
result&=storage.start();
|
||||
#if defined(STORE_SESSION_DB) && defined(HAVE_MAT_STORAGE)
|
||||
logSessionData = LogSessionDataProvider::CreateLogSessionData(&offlineStorage);
|
||||
#else
|
||||
logSessionData = LogSessionDataProvider::CreateLogSessionData(cacheFilePath);
|
||||
#endif
|
||||
logSessionData = logSessionDataProvider->GetLogSessionData();
|
||||
result&=tpm.start();
|
||||
result&=stats.onStart(); // TODO: [MG]- readd this
|
||||
return result;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "http/HttpResponseDecoder.hpp"
|
||||
|
||||
#include "offline/StorageObserver.hpp"
|
||||
#include "offline/LogSessionDataProvider.hpp"
|
||||
#include "LogSessionData.hpp"
|
||||
|
||||
#include "IOfflineStorage.hpp"
|
||||
|
@ -47,8 +48,8 @@ namespace ARIASDK_NS_BEGIN {
|
|||
IHttpClient& httpClient,
|
||||
ITaskDispatcher& taskDispatcher,
|
||||
IBandwidthController* bandwidthController,
|
||||
std::shared_ptr<LogSessionData> &logSessionData,
|
||||
std::string const & cacheFilePath
|
||||
LogSessionDataProvider *logSessionDataProvider,
|
||||
std::shared_ptr<LogSessionData> &logSessionData
|
||||
);
|
||||
|
||||
~TelemetrySystem();
|
||||
|
|
|
@ -32,15 +32,6 @@ class LogSessionDataFuncTests : public ::testing::Test
|
|||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
class TestLogSessionData : public LogSessionData
|
||||
{
|
||||
public:
|
||||
TestLogSessionData(const std::string& cacheFilePath)
|
||||
: LogSessionData(LogSessionDataProvider(cacheFilePath)) { }
|
||||
};
|
||||
#endif
|
||||
|
||||
void ConstructSesFile(const char* sessionFile, const std::string& contents)
|
||||
{
|
||||
ASSERT_TRUE(MAT::FileWrite(sessionFile, contents.c_str()));
|
||||
|
@ -76,7 +67,7 @@ std::pair<unsigned long long, std::string> ReadPropertiesFromSessionFile(const c
|
|||
|
||||
TEST(LogSessionDataFuncTests, Constructor_SessionFile_FileCreated)
|
||||
{
|
||||
auto logSessionData = LogSessionDataProvider::CreateLogSessionData(SessionFileArgument);
|
||||
auto logSessionData = LogSessionDataProvider(SessionFileArgument).GetLogSessionData();
|
||||
ASSERT_TRUE(MAT::FileExists(SessionFile));
|
||||
}
|
||||
|
||||
|
@ -85,8 +76,7 @@ TEST(LogSessionDataFuncTests, Constructor_ValidSessionFileExists_MembersSetToExi
|
|||
const std::string validSessionFirstTime{ "123456" };
|
||||
const std::string validSkuId{ "abc123" };
|
||||
ConstructSesFile(SessionFile, validSessionFirstTime, validSkuId);
|
||||
auto logSessionData = LogSessionDataProvider::CreateLogSessionData(SessionFileArgument);
|
||||
//LogSessionData logSessionData = LogSessionDataProvider(SessionFileArgument) ;
|
||||
auto logSessionData = LogSessionDataProvider(SessionFileArgument).GetLogSessionData();
|
||||
|
||||
ASSERT_EQ(logSessionData->getSessionFirstTime(), 123456ull);
|
||||
ASSERT_EQ(logSessionData->getSessionSDKUid(), validSkuId);
|
||||
|
@ -97,8 +87,7 @@ TEST(LogSessionDataFuncTests, Constructor_InvalidSessionFileExists_MembersRegene
|
|||
const std::string invalidSessionFirstTime{ "not-a-number" };
|
||||
const std::string validSkuId{ "abc123" };
|
||||
ConstructSesFile(SessionFile, invalidSessionFirstTime, validSkuId);
|
||||
auto logSessionData = LogSessionDataProvider::CreateLogSessionData(SessionFileArgument);
|
||||
//LogSessionData logSessionData{ SessionFileArgument };
|
||||
auto logSessionData = LogSessionDataProvider(SessionFileArgument).GetLogSessionData();
|
||||
|
||||
ASSERT_NE(logSessionData->getSessionFirstTime(), 123456ull);
|
||||
ASSERT_NE(logSessionData->getSessionSDKUid(), validSkuId);
|
||||
|
@ -109,9 +98,7 @@ TEST(LogSessionDataFuncTests, Constructor_InvalidSessionFileExists_NewFileWritte
|
|||
const std::string invalidSessionFirstTime{ "not-a-number" };
|
||||
const std::string validSkuId{ "abc123" };
|
||||
ConstructSesFile(SessionFile, invalidSessionFirstTime, validSkuId);
|
||||
auto logSessionData = LogSessionDataProvider::CreateLogSessionData(SessionFileArgument);
|
||||
//LogSessionData logSessionData{ SessionFileArgument };
|
||||
|
||||
auto logSessionData = LogSessionDataProvider(SessionFileArgument).GetLogSessionData();
|
||||
auto properties = ReadPropertiesFromSessionFile(SessionFile);
|
||||
|
||||
ASSERT_EQ(logSessionData->getSessionFirstTime(), properties.first);
|
||||
|
|
|
@ -10,7 +10,8 @@ using namespace Microsoft::Applications::Events;
|
|||
class TestLogSessionDataProvider : public LogSessionDataProvider
|
||||
{
|
||||
public:
|
||||
using LogSessionDataProvider::parse;
|
||||
TestLogSessionDataProvider(const std::string &str): LogSessionDataProvider(str) {}
|
||||
using LogSessionDataProvider::parse;
|
||||
};
|
||||
|
||||
const char* const PathToTestSesFile = "";
|
||||
|
@ -19,44 +20,45 @@ unsigned long long sessionFirstTimeLaunch;
|
|||
|
||||
|
||||
TEST(LogSessionDataTests, parse_EmptyString_ReturnsFalse)
|
||||
{
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
ASSERT_FALSE(TestLogSessionDataProvider::parse(std::string {}, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
{
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_FALSE(logSessionDataProvider.parse(std::string {}, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
||||
TEST(LogSessionDataTests, parse_OneLine_ReturnsFalse)
|
||||
{
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
ASSERT_FALSE(TestLogSessionDataProvider::parse(std::string {"foo" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_FALSE(logSessionDataProvider.parse(std::string {"foo" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
||||
TEST(LogSessionDataTests, parse_ThreeLines_ReturnsFalse)
|
||||
{
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
ASSERT_FALSE(TestLogSessionDataProvider::parse(std::string { "foo\nbar\n\baz" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "foo\nbar\n\baz" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
||||
TEST(LogSessionDataTests, parse_TwoLinesFirstLaunchNotNumber_ReturnsFalse)
|
||||
{
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
ASSERT_FALSE(TestLogSessionDataProvider::parse(std::string { "foo\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "foo\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
||||
TEST(LogSessionDataTests, parse_TwoLinesFirstLaunchTooLarge_ReturnsFalse)
|
||||
{
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
ASSERT_FALSE(TestLogSessionDataProvider::parse(std::string { "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\nbar" },
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\nbar" },
|
||||
sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
||||
TEST(LogSessionDataTests, parse_ValidInput_ReturnsTrue)
|
||||
{
|
||||
//TestLogSessionData sessionData { std::string { PathToTestSesFile } };
|
||||
auto logSessionData = TestLogSessionDataProvider::CreateLogSessionData(std::string { PathToTestSesFile });
|
||||
ASSERT_TRUE(TestLogSessionDataProvider::parse(std::string { "1234567890\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
|
||||
auto logSessionData = logSessionDataProvider.GetLogSessionData();
|
||||
ASSERT_TRUE(logSessionDataProvider.parse(std::string { "1234567890\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче