2 * test-obj-pool.c: code to exercise the svn importer's object pool
6 #include "vcs-svn/obj_pool.h"
8 enum pool
{ POOL_ONE
, POOL_TWO
};
9 obj_pool_gen(one
, int, 1)
10 obj_pool_gen(two
, int, 4096)
12 static uint32_t strtouint32(const char *s
)
15 uintmax_t n
= strtoumax(s
, &end
, 10);
16 if (*s
== '\0' || (*end
!= '\n' && *end
!= '\0'))
17 die("invalid offset: %s", s
);
21 static void handle_command(const char *command
, enum pool pool
, const char *arg
)
25 if (!prefixcmp(command
, "alloc ")) {
26 uint32_t n
= strtouint32(arg
);
29 one_alloc(n
) : two_alloc(n
));
33 if (!prefixcmp(command
, "commit ")) {
34 pool
== POOL_ONE
? one_commit() : two_commit();
37 if (!prefixcmp(command
, "committed ")) {
40 one_pool
.committed
: two_pool
.committed
);
44 if (!prefixcmp(command
, "free ")) {
45 uint32_t n
= strtouint32(arg
);
46 pool
== POOL_ONE
? one_free(n
) : two_free(n
);
50 if (!prefixcmp(command
, "null ")) {
53 one_offset(NULL
) : two_offset(NULL
));
57 if (!prefixcmp(command
, "offset ")) {
58 uint32_t n
= strtouint32(arg
);
61 one_offset(one_pointer(n
)) :
62 two_offset(two_pointer(n
)));
66 if (!prefixcmp(command
, "reset ")) {
67 pool
== POOL_ONE
? one_reset() : two_reset();
71 if (!prefixcmp(command
, "set ")) {
72 uint32_t n
= strtouint32(arg
);
80 if (!prefixcmp(command
, "test ")) {
81 uint32_t n
= strtouint32(arg
);
82 printf("%d\n", pool
== POOL_ONE
?
83 *one_pointer(n
) : *two_pointer(n
));
87 die("unrecognized command: %s", command
);
91 static void handle_line(const char *line
)
93 const char *arg
= strchr(line
, ' ');
96 if (arg
&& !prefixcmp(arg
+ 1, "one"))
98 else if (arg
&& !prefixcmp(arg
+ 1, "two"))
101 die("no pool specified: %s", line
);
103 handle_command(line
, pool
, arg
+ strlen("one "));
106 int main(int argc
, char *argv
[])
108 struct strbuf sb
= STRBUF_INIT
;
110 usage("test-obj-str < script");
112 while (strbuf_getline(&sb
, stdin
, '\n') != EOF
)