diff options
author | Josh Haberman <jhaberman@gmail.com> | 2014-06-26 20:24:32 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2014-06-26 20:24:32 -0700 |
commit | 2d10fa33071d52d7a35ce3b13bc459cd16a0aa33 (patch) | |
tree | bf47d38e2e1cc8ddb4711b23b26e7fd10742e07d /tests/test_cpp.cc | |
parent | 7d565f1e7a0f107506d3cf31ef2e33e22a504d2b (diff) |
Sync from internal Google development.
Diffstat (limited to 'tests/test_cpp.cc')
-rw-r--r-- | tests/test_cpp.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index 60d6527..fe0695f 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -153,6 +153,9 @@ static void TestSymbolTable(const char *descriptor_file) { std::cerr << "Couldn't load descriptor: " << status.error_message(); exit(1); } + ASSERT(!s->IsFrozen()); + s->Freeze(); + ASSERT(s->IsFrozen()); upb::reffed_ptr<const upb::MessageDef> md(s->LookupMessage("C")); ASSERT(md.get()); @@ -1038,6 +1041,39 @@ void TestMismatchedTypes() { // match top-level closure of sub-handlers. } +class IntIncrementer { + public: + IntIncrementer(int* x) : x_(x) { (*x_)++; } + ~IntIncrementer() { (*x_)--; } + + static void Handler(void* closure, const IntIncrementer* incrementer, + int32_t x) {} + + private: + int* x_; +}; + + +void TestHandlerDataDestruction() { + upb::reffed_ptr<upb::MessageDef> md(upb::MessageDef::New()); + upb::reffed_ptr<upb::FieldDef> f(upb::FieldDef::New()); + f->set_type(UPB_TYPE_INT32); + ASSERT(f->set_name("test", NULL)); + ASSERT(f->set_number(1, NULL)); + ASSERT(md->AddField(f, NULL)); + ASSERT(md->Freeze(NULL)); + + int x = 0; + { + upb::reffed_ptr<upb::Handlers> h(upb::Handlers::New(md.get())); + h->SetInt32Handler( + f.get(), UpbBind(&IntIncrementer::Handler, new IntIncrementer(&x))); + ASSERT(x == 1); + } + + ASSERT(x == 0); +} + extern "C" { int run_tests(int argc, char *argv[]) { @@ -1091,6 +1127,8 @@ int run_tests(int argc, char *argv[]) { TestMismatchedTypes(); + TestHandlerDataDestruction(); + #ifdef UPB_CXX11 #define ASSERT_STD_LAYOUT(type) \ static_assert(std::is_standard_layout<type>::value, \ |