-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathLogSessionDataTests.cpp
89 lines (71 loc) · 3.42 KB
/
LogSessionDataTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "common/Common.hpp"
#include "offline/LogSessionDataProvider.hpp"
#include <LogSessionData.hpp>
using namespace testing;
using namespace Microsoft::Applications::Events;
class TestLogSessionDataProvider : public LogSessionDataProvider
{
public:
TestLogSessionDataProvider(const std::string &str): LogSessionDataProvider(str) {}
using LogSessionDataProvider::parse;
};
const char* const PathToTestSesFile = "";
const char* const PathToNonEmptyTestSesFile = "sesfile";
std::string sessionSDKUid;
uint64_t sessionFirstTimeLaunch;
TEST(LogSessionDataTests, parse_EmptyString_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string {}, sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_OneLine_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string {"foo" }, sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_ThreeLines_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "foo\nbar\n\baz" }, sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_TwoLinesFirstLaunchNotNumber_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "foo\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_TwoLinesFirstLaunchTooLarge_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "1111111111111111111111111111111111111111111111111111111111111111111\nbar" },
sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_MissingNewLineAtEnd_ReturnsFalse)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_FALSE(logSessionDataProvider.parse(std::string { "1234567890\nbar" }, sessionFirstTimeLaunch, sessionSDKUid));
}
TEST(LogSessionDataTests, parse_ValidInput_ReturnsTrue)
{
TestLogSessionDataProvider logSessionDataProvider(PathToTestSesFile);
ASSERT_TRUE(logSessionDataProvider.parse(std::string { "1234567890\nbar\n" }, sessionFirstTimeLaunch, sessionSDKUid));
ASSERT_EQ(sessionFirstTimeLaunch, (uint64_t)1234567890);
ASSERT_EQ(sessionSDKUid, "bar");
}
TEST(LogSessionDataTests, getLogSessionData_ValidInput_SessionDataPersists)
{
TestLogSessionDataProvider logSessionDataProvider1(PathToNonEmptyTestSesFile);
logSessionDataProvider1.CreateLogSessionData();
const auto* logSessionData1 = logSessionDataProvider1.GetLogSessionData();
// Create another provider instance and validate session data is not re-generated
TestLogSessionDataProvider logSessionDataProvider2(PathToNonEmptyTestSesFile);
logSessionDataProvider2.CreateLogSessionData();
const auto* logSessionData2 = logSessionDataProvider2.GetLogSessionData();
ASSERT_EQ(logSessionData1->getSessionFirstTime(), logSessionData2->getSessionFirstTime());
ASSERT_EQ(logSessionData1->getSessionSDKUid(), logSessionData2->getSessionSDKUid());
logSessionDataProvider1.DeleteLogSessionData();
logSessionDataProvider2.DeleteLogSessionData();
}