diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cpp.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index 86d7bc5..f1badc4 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -893,6 +893,26 @@ void TestHandlerDataDestruction() { ASSERT(x == 0); } +void TestIteration() { + upb::SymbolTable symtab; + upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(symtab.ptr())); + + // Test range-based for on both fields and oneofs (with the iterator adaptor). + int field_count = 0; + for (auto field : md.fields()) { + UPB_UNUSED(field); + field_count++; + } + ASSERT(field_count == md.field_count()); + + int oneof_count = 0; + for (auto oneof : md.oneofs()) { + UPB_UNUSED(oneof); + oneof_count++; + } + ASSERT(oneof_count == md.oneof_count()); +} + extern "C" { int run_tests(int argc, char *argv[]) { |