test.c 1.1 KB
Newer Older
1
#include <stdio.h>
H
Helin Wang 已提交
2
#include <stdlib.h>
3 4 5

#include "librecordio.h"

H
Helin Wang 已提交
6
void fail() {
7 8
  // TODO(helin): fix: gtest using cmake is not working, using this
  // hacky way for now.
H
Helin Wang 已提交
9 10
  printf("test failed.\n");
  exit(-1);
11 12 13
}

int main() {
H
Helin Wang 已提交
14 15 16 17
  writer w = create_recordio_writer("/tmp/test_recordio_0");
  write_recordio(w, "hello", 6);
  write_recordio(w, "hi", 3);
  release_recordio(w);
18

H
Helin Wang 已提交
19 20 21 22 23 24
  w = create_recordio_writer("/tmp/test_recordio_1");
  write_recordio(w, "dog", 4);
  write_recordio(w, "cat", 4);
  release_recordio(w);

  reader r = create_recordio_reader("/tmp/test_recordio_*");
25
  int size;
H
Helin Wang 已提交
26 27 28 29 30 31 32 33 34 35
  unsigned char* item = read_next_item(r, &size);
  if (strcmp(item, "hello") || size != 6) {
    fail();
  }

  free(item);

  item = read_next_item(r, &size);
  if (strcmp(item, "hi") || size != 3) {
    fail();
36 37
  }
  free(item);
H
Helin Wang 已提交
38

H
Helin Wang 已提交
39 40 41
  item = read_next_item(r, &size);
  if (strcmp(item, "dog") || size != 4) {
    fail();
42 43
  }
  free(item);
H
Helin Wang 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56

  item = read_next_item(r, &size);
  if (strcmp(item, "cat") || size != 4) {
    fail();
  }
  free(item);

  item = read_next_item(r, &size);
  if (item != NULL || size != -1) {
    fail();
  }

  release_recordio_reader(r);
57
}