Add unit test validating seeking to last event of a trace
[babeltrace.git] / tests / lib / test-seeks.c
index 47bb42e216cbb1287c0c2ec9e4c5a9e017c6472f..a7b1360f97779a10b354fa4774b25644e1fb6a17 100644 (file)
@@ -32,7 +32,7 @@
 #include "common.h"
 #include "tap.h"
 
-#define NR_TESTS       23
+#define NR_TESTS       29
 
 void run_seek_begin(char *path, uint64_t expected_begin)
 {
@@ -134,6 +134,58 @@ void run_seek_last(char *path, uint64_t expected_last)
        bt_context_put(ctx);
 }
 
+void run_seek_time_at_last(char *path, uint64_t expected_last)
+{
+       struct bt_context *ctx;
+       struct bt_ctf_iter *iter;
+       struct bt_ctf_event *event;
+       struct bt_iter_pos newpos;
+       int ret;
+       uint64_t timestamp_last;
+
+       /* Open the trace */
+       ctx = create_context_with_path(path);
+       if (!ctx) {
+               plan_skip_all("Cannot create valid context");
+       }
+
+       /* Create iterator with null last and end */
+       iter = bt_ctf_iter_create(ctx, NULL, NULL);
+       if (!iter) {
+               plan_skip_all("Cannot create valid iterator");
+       }
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at beginning");
+
+       /* Seek to last */
+       newpos.type = BT_SEEK_TIME;
+       newpos.u.seek_time = expected_last;
+       ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+       ok(ret == 0, "Seek time at last retval %d", ret);
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at last position");
+
+       timestamp_last = bt_ctf_get_timestamp(event);
+
+       ok1(timestamp_last == expected_last);
+
+       /* Try to read next event */
+       ret = bt_iter_next(bt_ctf_get_iter(iter));
+
+       ok(ret == 0, "iter next should return an error");
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event == 0, "Event after last should be invalid");
+
+       bt_context_put(ctx);
+}
+
 void run_seek_cycles(char *path,
                uint64_t expected_begin,
                uint64_t expected_last)
@@ -242,6 +294,7 @@ int main(int argc, char **argv)
        }
 
        run_seek_begin(path, expected_begin);
+       run_seek_time_at_last(path, expected_last);
        run_seek_last(path, expected_last);
        run_seek_cycles(path, expected_begin, expected_last);
 
This page took 0.026529 seconds and 4 git commands to generate.