sdb_lock.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * Author: hakanai
  12. */
  13. #include <stdio.h>
  14. #include <assert.h>
  15. #include <string.h>
  16. #include <libsdb.h>
  17. #include <unistd.h>
  18. #define TFILE "/tmp/oosaAest39ax.sdb"
  19. static int simple_lock_test() {
  20. sdb_header_t header;
  21. sdb_t db;
  22. assert(sdb_open(TFILE, &db) == SDB_OK);
  23. assert(sdb_create_header(&header) == SDB_OK);
  24. assert(sdb_write_header(&db, &header) == SDB_OK);
  25. assert(sdb_set_lock(&db, 1) == SDB_OK);
  26. assert(sdb_read_header(&db, &header) == SDB_OK);
  27. assert(header.lock == 1);
  28. assert(sdb_get_lock(&db) == true);
  29. assert(sdb_set_lock(&db, 0) == SDB_OK);
  30. assert(sdb_read_header(&db, &header) == SDB_OK);
  31. assert(header.lock == 0);
  32. assert(sdb_get_lock(&db) == false);
  33. sdb_close(&db);
  34. return 0;
  35. }
  36. int main() {
  37. assert(!simple_lock_test());
  38. unlink(TFILE);
  39. return 0;
  40. }