|
|
@ -35,11 +35,11 @@ |
|
|
|
#include <set> |
|
|
|
#include <set> |
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "google/protobuf/timestamp.upb.h" |
|
|
|
|
|
|
|
#include "google/protobuf/timestamp.upbdefs.h" |
|
|
|
#include "gtest/gtest.h" |
|
|
|
#include "gtest/gtest.h" |
|
|
|
#include "tests/test_cpp.upb.h" |
|
|
|
#include "tests/test_cpp.upb.h" |
|
|
|
#include "tests/test_cpp.upbdefs.h" |
|
|
|
#include "tests/test_cpp.upbdefs.h" |
|
|
|
#include "google/protobuf/timestamp.upb.h" |
|
|
|
|
|
|
|
#include "google/protobuf/timestamp.upbdefs.h" |
|
|
|
|
|
|
|
#include "upb/def.h" |
|
|
|
#include "upb/def.h" |
|
|
|
#include "upb/def.hpp" |
|
|
|
#include "upb/def.hpp" |
|
|
|
#include "upb/json_decode.h" |
|
|
|
#include "upb/json_decode.h" |
|
|
@ -155,26 +155,30 @@ TEST(Cpp, TimestampEncoder) { |
|
|
|
upb::SymbolTable symtab; |
|
|
|
upb::SymbolTable symtab; |
|
|
|
upb::Arena arena; |
|
|
|
upb::Arena arena; |
|
|
|
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(symtab.ptr())); |
|
|
|
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(symtab.ptr())); |
|
|
|
google_protobuf_Timestamp* timestamp_upb = google_protobuf_Timestamp_new(arena.ptr()); |
|
|
|
google_protobuf_Timestamp* timestamp_upb = |
|
|
|
google_protobuf_Timestamp* timestamp_upb_decoded = google_protobuf_Timestamp_new(arena.ptr()); |
|
|
|
google_protobuf_Timestamp_new(arena.ptr()); |
|
|
|
|
|
|
|
google_protobuf_Timestamp* timestamp_upb_decoded = |
|
|
|
|
|
|
|
google_protobuf_Timestamp_new(arena.ptr()); |
|
|
|
|
|
|
|
|
|
|
|
long timestamps[] = { |
|
|
|
long timestamps[] = { |
|
|
|
253402300799, // 9999-12-31T23:59:59Z
|
|
|
|
253402300799, // 9999-12-31T23:59:59Z
|
|
|
|
1641006000, // 2022-01-01T03:00:00Z
|
|
|
|
1641006000, // 2022-01-01T03:00:00Z
|
|
|
|
0, // 1970-01-01T00:00:00Z
|
|
|
|
0, // 1970-01-01T00:00:00Z
|
|
|
|
-31525200, // 1969-01-01T03:00:00Z
|
|
|
|
-31525200, // 1969-01-01T03:00:00Z
|
|
|
|
-2208988800, // 1900-01-01T00:00:00Z
|
|
|
|
-2208988800, // 1900-01-01T00:00:00Z
|
|
|
|
-62135596800, // 0000-01-01T00:00:00Z
|
|
|
|
-62135596800, // 0000-01-01T00:00:00Z
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for(long timestamp: timestamps) { |
|
|
|
for (long timestamp : timestamps) { |
|
|
|
google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp); |
|
|
|
google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp); |
|
|
|
|
|
|
|
|
|
|
|
char json[128]; |
|
|
|
char json[128]; |
|
|
|
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json, sizeof(json), NULL); |
|
|
|
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json, |
|
|
|
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), NULL, 0, arena.ptr(), NULL); |
|
|
|
sizeof(json), NULL); |
|
|
|
const long timestamp_decoded = google_protobuf_Timestamp_seconds(timestamp_upb_decoded);
|
|
|
|
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), |
|
|
|
|
|
|
|
NULL, 0, arena.ptr(), NULL); |
|
|
|
|
|
|
|
const long timestamp_decoded = |
|
|
|
|
|
|
|
google_protobuf_Timestamp_seconds(timestamp_upb_decoded); |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(result); |
|
|
|
ASSERT_TRUE(result); |
|
|
|
EXPECT_EQ(timestamp, timestamp_decoded); |
|
|
|
EXPECT_EQ(timestamp, timestamp_decoded); |
|
|
|