summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_def.c4
-rw-r--r--tests/test_string.c11
2 files changed, 12 insertions, 3 deletions
diff --git a/tests/test_def.c b/tests/test_def.c
index 5be0672..2d2658f 100644
--- a/tests/test_def.c
+++ b/tests/test_def.c
@@ -10,13 +10,10 @@ int main() {
int count;
upb_def **defs = upb_symtab_getdefs(s, &count, UPB_DEF_ANY);
for (int i = 0; i < count; i++) {
- printf("Def with name: " UPB_STRFMT "\n", UPB_STRARG(defs[i]->fqname));
upb_def_unref(defs[i]);
}
free(defs);
- printf("Size: %zd\n", sizeof(upb_ntof_ent));
-
upb_string *str = upb_strdupc("google.protobuf.FileDescriptorSet");
upb_def *fds = upb_symtab_lookup(s, str);
assert(fds != NULL);
@@ -24,4 +21,5 @@ int main() {
upb_def_unref(fds);
upb_string_unref(str);
upb_symtab_unref(s);
+ return 0;
}
diff --git a/tests/test_string.c b/tests/test_string.c
index 6446806..ef0e2a9 100644
--- a/tests/test_string.c
+++ b/tests/test_string.c
@@ -40,6 +40,17 @@ static void test_dynamic() {
upb_string_recycle(&str);
assert(str != NULL);
+ // Take a ref and recycle; should create a new string and release a ref
+ // on the old one.
+ upb_string *strcp = upb_string_getref(str);
+ assert(strcp == str);
+ assert(upb_atomic_read(&str->refcount) == 2);
+ upb_string_recycle(&str);
+ assert(strcp != str);
+ assert(upb_atomic_read(&str->refcount) == 1);
+ assert(upb_atomic_read(&strcp->refcount) == 1);
+ upb_string_unref(strcp);
+
upb_strcpyc(str, static_str);
assert(upb_string_len(str) == (sizeof(static_str) - 1));
const char *robuf = upb_string_getrobuf(str);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback