Skip to content

Commit

Permalink
RDKEMW-959: Analytics: add timezone changed test case to L2
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Jan 14, 2025
1 parent bd3fb78 commit c9fbbe7
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions Tests/L2Tests/L2TestsPlugin/tests/Analytics_L2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@
#define SIFT_SERVER_PORT 12345
#define SIFT_SERVER_TIMEOUT_SEC (30)

#define ZDUMP_MOCK_OUT "America/New_York Sun Mar 9 07:00:00 2008 UT = Sun Mar 9 03:00:00 2008 EDT isdst=1 gmtoff=-14400\n" \
#define ZDUMP_MOCK_OUT_AMERICA "America/New_York Sun Mar 9 07:00:00 2008 UT = Sun Mar 9 03:00:00 2008 EDT isdst=1 gmtoff=-14400\n" \
"America/New_York Sun Nov 2 05:59:59 2008 UT = Sun Nov 2 01:59:59 2008 EDT isdst=1 gmtoff=-14400\n" \
"America/New_York Sun Nov 2 06:00:00 2008 UT = Sun Nov 2 01:00:00 2008 EST isdst=0 gmtoff=-18000\n" \
"America/New_York Sun Mar 8 06:59:59 2009 UT = Sun Mar 8 01:59:59 2009 EST isdst=0 gmtoff=-18000\n" \
"America/New_York Sun Mar 8 07:00:00 2009 UT = Sun Mar 8 03:00:00 2009 EDT isdst=1 gmtoff=-14400"

#define ZDUMP_MOCK_OUT_AUSTRALIA "Australia/Sydney Sat Oct 27 15:59:59 2007 UT = Sun Oct 28 01:59:59 2007 AEST isdst=0 gmtoff=36000\n" \
"Australia/Sydney Sat Oct 27 16:00:00 2007 UT = Sun Oct 28 03:00:00 2007 AEDT isdst=1 gmtoff=39600\n" \
"Australia/Sydney Sat Apr 5 15:59:59 2008 UT = Sun Apr 6 02:59:59 2008 AEDT isdst=1 gmtoff=39600\n" \
"Australia/Sydney Sat Apr 5 16:00:00 2008 UT = Sun Apr 6 02:00:00 2008 AEST isdst=0 gmtoff=36000\n" \
"Australia/Sydney Sat Oct 4 15:59:59 2008 UT = Sun Oct 5 01:59:59 2008 AEST isdst=0 gmtoff=36000\n" \
"Australia/Sydney Sat Oct 4 16:00:00 2008 UT = Sun Oct 5 03:00:00 2008 AEDT isdst=1 gmtoff=39600\n" \
"Australia/Sydney Sat Apr 4 15:59:59 2009 UT = Sun Apr 5 02:59:59 2009 AEDT isdst=1 gmtoff=39600"



#define TIME_MOCK_OUT 1212537600 // 2008-06-03 12:00:00

#define EVENTS_MAP "[ \
Expand Down Expand Up @@ -300,7 +311,10 @@ AnalyticsTest::AnalyticsTest()
vsnprintf(strFmt, sizeof(strFmt), command, args2);
va_end(args2);
if (strcmp(strFmt, "zdump -v America/New_York") == 0) {
valueToReturn = ZDUMP_MOCK_OUT;
valueToReturn = ZDUMP_MOCK_OUT_AMERICA;
}
if (strcmp(strFmt, "zdump -v Australia/Sydney") == 0) {
valueToReturn = ZDUMP_MOCK_OUT_AUSTRALIA;
}
if (valueToReturn != NULL) {
memset(gPipeBuffer, 0, sizeof(gPipeBuffer));
Expand Down Expand Up @@ -1061,4 +1075,55 @@ TEST_F(AnalyticsTest, EventsMapping)
EXPECT_EQ(eventObj["event_name"].String(), "L2TestEventMappedGenericSourceVersion");
}

}

TEST_F(AnalyticsTest, TimezoneChanged)
{
JsonObject paramsJson;
JsonObject resultJson;

paramsJson.Clear();
paramsJson["timeZone"] = "America/New_York";
paramsJson["accuracy"] = "FINAL";
uint32_t status = InvokeServiceMethod("org.rdk.System", "setTimeZoneDST", paramsJson, resultJson);
EXPECT_EQ(status, Core::ERROR_NONE);

sleep(3);

paramsJson.Clear();
paramsJson["timeZone"] = "Australia/Sydney";
paramsJson["accuracy"] = "FINAL";
status = InvokeServiceMethod("org.rdk.System", "setTimeZoneDST", paramsJson, resultJson);
EXPECT_EQ(status, Core::ERROR_NONE);

sleep(3);

paramsJson.Clear();
paramsJson["eventName"] = "L2TestEvent";
paramsJson["eventVersion"] = "1";
paramsJson["eventSource"] = "L2Test";
paramsJson["eventSourceVersion"] = "1.0.0";
JsonObject eventPayload;
eventPayload["data"] = "random data";
paramsJson["eventPayload"] = eventPayload;

status = InvokeServiceMethod("org.rdk.Analytics", "sendEvent", paramsJson, resultJson);
EXPECT_EQ(status, Core::ERROR_NONE);

SiftServerMock siftServer;
EXPECT_TRUE(siftServer.Start());

string eventsMsg = siftServer.AwaitData(SIFT_SERVER_TIMEOUT_SEC);
EXPECT_NE(eventsMsg, "");

// Check if the event message contains the expected fields
JsonArray eventArray;
eventArray.FromString(eventsMsg);
EXPECT_EQ(eventArray.Length(), 1);

if (eventArray.Length() == 1) {
JsonObject eventObj = eventArray[0].Object();
EXPECT_TRUE(eventObj.HasLabel("device_timezone"));
EXPECT_EQ(eventObj["device_timezone"].Number(), 39600000);
}
}

0 comments on commit c9fbbe7

Please sign in to comment.