summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2011-01-22 01:03:02 -0800
committerJoshua Haberman <joshua@reverberate.org>2011-01-22 01:03:02 -0800
commitc9df91b04a429f9324afeefece28f21e7078e3ac (patch)
tree28f038af1ed47b0da2b49c78d8def02486da99fa /tests
parenta695b92ccea4b82180ae45d21d7ed4445f7d0769 (diff)
upb bootstraps again! and with no memory leaks!
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