#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "bst.h"

void test_bump(FILE *f, const char *user) {
  int e, r;
  clearerr(f);
  e = 0;
  r = bump(f, user, &e);
  fprintf(stderr, "%d %s\n", r, strerror(e));
}

int main(void) {
  FILE *f;
  if ((f = fopen("sample-tree.bin", "r+")) == NULL) {
    perror("fopen");
    exit(1);
  }
  test_bump(f, "lilypad");
  test_bump(f, "rex");
  fclose(f);

  // Here is an error case. Open the file in just "r" mode so writing should be
  // an error.
  if ((f = fopen("sample-tree.bin", "r")) == NULL) {
    perror("fopen");
    exit(1);
  }
  test_bump(f, "rex");
  fclose(f);
  return 0;
}
