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
  writer w = create_recordio_writer("/tmp/test_recordio_0");
H
Helin Wang 已提交
15 16 17
  recordio_write(w, "hello", 6);
  recordio_write(w, "hi", 3);
  release_recordio_writer(w);
18

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

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

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

H
Helin Wang 已提交
38
  size = recordio_read(r, &item);
H
Helin Wang 已提交
39 40
  if (strcmp(item, "dog") || size != 4) {
    fail();
41 42
  }
  free(item);
H
Helin Wang 已提交
43

H
Helin Wang 已提交
44
  size = recordio_read(r, &item);
H
Helin Wang 已提交
45 46 47 48 49
  if (strcmp(item, "cat") || size != 4) {
    fail();
  }
  free(item);

H
Helin Wang 已提交
50 51
  size = recordio_read(r, &item);
  if (size != -1) {
H
Helin Wang 已提交
52 53 54 55
    fail();
  }

  release_recordio_reader(r);
56
}