Re-arrange. Add "range" test (covered by other tests)
[yaz-moved-to-github.git] / test / test_shared_ptr.c
index cff3ee0..464a534 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 
 #include <stdlib.h>
 #include <string.h>
 
-#include <yaz/mutex.h>
+#include <yaz/shptr.h>
 #include <yaz/wrbuf.h>
 #include <yaz/test.h>
 
-#define YAZ_SHPTR_TYPE(type) \
-    struct type##_shptr \
-    {                          \
-    type ptr;                  \
-    int ref;                   \
-    YAZ_MUTEX mutex;           \
-    };  \
-    typedef struct type##_shptr *type##_shptr_t;
-
-#define YAZ_SHPTR_INIT(p,n) {                   \
-        p = xmalloc(sizeof(*p));                \
-        p->ptr = n;                             \
-        p->ref = 1;                             \
-        p->mutex = 0;  \
-        yaz_mutex_create(&p->mutex);            \
-    }
-
-#define YAZ_SHPTR_INC(p) {                      \
-        yaz_mutex_enter(p->mutex);              \
-        p->ref++;                               \
-        yaz_mutex_leave(p->mutex);              \
-    }
-
-#define YAZ_SHPTR_DEC(p, destroy)  {             \
-    yaz_mutex_enter(p->mutex);                   \
-    if (--p->ref == 0) {                         \
-        yaz_mutex_leave(p->mutex);               \
-        destroy(p->ptr);                         \
-        yaz_mutex_destroy(&p->mutex);            \
-        xfree(p);                                \
-        p = 0;                                   \
-    } else { \
-    yaz_mutex_leave(p->mutex); \
-    } \
-    }
-
 YAZ_SHPTR_TYPE(WRBUF)
 
 static void test(void)
@@ -63,7 +27,7 @@ static void test(void)
     WRBUF w = wrbuf_alloc();
 
     WRBUF_shptr_t t = 0;
-    
+
     YAZ_SHPTR_INIT(t, w);
     YAZ_CHECK(t);