diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-01-22 01:03:02 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-01-22 01:03:02 -0800 |
commit | c9df91b04a429f9324afeefece28f21e7078e3ac (patch) | |
tree | 28f038af1ed47b0da2b49c78d8def02486da99fa /tests/test_string.c | |
parent | a695b92ccea4b82180ae45d21d7ed4445f7d0769 (diff) |
upb bootstraps again! and with no memory leaks!
Diffstat (limited to 'tests/test_string.c')
-rw-r--r-- | tests/test_string.c | 11 |
1 files changed, 11 insertions, 0 deletions
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); |