Skip to content

Commit

Permalink
Fix 64-bit integers on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsimantov committed Jan 24, 2024
1 parent 97a72bd commit cafc98b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions database/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
WaitForCompletion(f7, "GetLongDouble");

// Get the current time to compare to the Timestamp.
int64_t current_time_milliseconds = GetCurrentTimeInSecondsSinceEpoch() * 1000L;
int64_t current_time_milliseconds = GetCurrentTimeInSecondsSinceEpoch() * 1000LL;

EXPECT_EQ(f1.result()->value().AsString(), kSimpleString);
EXPECT_EQ(f2.result()->value().AsInt64(), kSimpleInt);
Expand Down Expand Up @@ -673,7 +673,9 @@ TEST_F(FirebaseDatabaseTest, TestUpdateChildren) {
read_future = ref.Child(test_name).GetValue();
WaitForCompletion(read_future, "GetValue 2");
int64_t current_time_milliseconds = GetCurrentTimeInSecondsSinceEpoch() * 1000L;

LogDebug("Comparing current time %I64d with timestamp %I64d",
current_time_milliseconds,
read_future.result()->value().map()["timestamp"].AsInt64().int64_value());
EXPECT_THAT(
read_future.result()->value().map(),
UnorderedElementsAre(
Expand Down
14 changes: 8 additions & 6 deletions testing/test_framework/src/firebase_test_framework.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ int64_t FirebaseTest::GetCurrentTimeInSecondsSinceEpoch() {
empty_headers, &response_code, &response_body);
if (!success || response_code != 200 || response_body.empty()) {
LogDebug("GetCurrentTimeInSecondsSinceEpoch: HTTP request failed");
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000L);
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000LL);
}

const char kJsonTag[] = "\"unixtime\":";
size_t begin = response_body.find(kJsonTag);
if (begin < 0) {
LogDebug(
"GetCurrentTimeInSecondsSinceEpoch: Can't find unixtime JSON field");
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000L);
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000LL);
}
begin += strlen(kJsonTag);
if (response_body[begin] == ' ') {
Expand All @@ -329,22 +329,24 @@ int64_t FirebaseTest::GetCurrentTimeInSecondsSinceEpoch() {
if (end < 0) {
LogDebug(
"GetCurrentTimeInSecondsSinceEpoch: Can't extract unixtime JSON field");
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000L);
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000LL);
}
std::string time_str = response_body.substr(begin, end - begin);
int64_t timestamp = std::stoll(time_str);
if (timestamp <= 0) {
LogDebug(
"GetCurrentTimeInSecondsSinceEpoch: Can't parse unixtime JSON value %s",
time_str.c_str());
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000L);
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000LL);
}
LogDebug("Got remote timestamp: %lld", timestamp);
LogDebug("Got remote timestamp: %I64d", timestamp);
return timestamp;
#else
// On desktop, just return the local time since SendHttpGetRequest is not
// implemented.
return (app_framework::GetCurrentTimeInMicroseconds() / 1000000L);
int64_t time_in_microseconds = app_framework::GetCurrentTimeInMicroseconds();
LogDebug("Got local time: %I64d", time_in_microseconds);
return (time_in_microseconds / 1000000LL);
#endif
}

Expand Down

0 comments on commit cafc98b

Please sign in to comment.