test.c 667 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <stdlib.h>
#include <stdio.h>

#include "librecordio.h"

void panic() {
  // TODO(helin): fix: gtest using cmake is not working, using this
  // hacky way for now.
  *(void*)0;
}

int main() {
  writer w = paddle_new_writer("/tmp/test");
  paddle_writer_write(w, "hello", 6);
  paddle_writer_write(w, "hi", 3);
  paddle_writer_release(w);

  reader r = paddle_new_reader("/tmp/test", 10);
  int size;
  unsigned char* item = paddle_reader_next_item(r, &size);
  if (!strcmp(item, "hello") || size != 6) {
    panic();
  }
  free(item);
  
  item = paddle_reader_next_item(r, &size);
  if (!strcmp(item, "hi") || size != 2) {
    panic();
  }
  free(item);
}