]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test: test json encode/decode of utime_t
authorCasey Bodley <cbodley@redhat.com>
Mon, 6 May 2019 16:58:43 +0000 (12:58 -0400)
committerSage Weil <sage@redhat.com>
Wed, 29 May 2019 19:12:15 +0000 (14:12 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/common/test_json_formatter.cc

index ed6972a7121363c6c79219cacec8ffe27bd26340..8a0f547a9298a7be32bef141c43aa0438143c9a6 100644 (file)
@@ -16,6 +16,7 @@
 #include <gtest/gtest.h>
 
 #include "common/ceph_json.h"
+#include "common/Clock.h"
 
 #include <sstream>
 
@@ -56,3 +57,25 @@ TEST(formatter, bug_37706) {
    ASSERT_EQ(pgs.back(), "1.0");
 }
 
+TEST(formatter, utime)
+{
+  JSONFormatter formatter;
+
+  utime_t input = ceph_clock_now();
+  input.gmtime_nsec(formatter.dump_stream("timestamp"));
+
+  bufferlist bl;
+  formatter.flush(bl);
+
+  JSONParser parser;
+  EXPECT_TRUE(parser.parse(bl.c_str(), bl.length()));
+
+  cout << input << " -> '" << std::string(bl.c_str(), bl.length())
+       << std::endl;
+
+  utime_t output;
+  decode_json_obj(output, &parser);
+  cout << " -> " << output << std::endl;
+  EXPECT_EQ(input.sec(), output.sec());
+  EXPECT_EQ(input.nsec(), output.nsec());
+}