@@ -2051,30 +2051,19 @@ TEST(Value, TypeAndValuesMatchDepthExceeded) {
20512051 std::string type_text = " int64_type {}" ;
20522052 std::string value_text = " int_value: 1" ;
20532053
2054- // Each layer of struct nesting increases the depth count. The initial call is
2055- // at depth 1. With the current implementation, each level of nesting
2056- // increases the depth by 2. To exceed the limit of 10, we need 5 levels of
2057- // nesting, which will result in a call with depth 11.
2058- for (int i = 0 ; i < 5 ; ++i) {
2059- type_text =
2060- absl::Substitute (" struct_type { fields { type { $0 } } }" , type_text);
2061- value_text = absl::Substitute (" array_value { values { $0 } }" , value_text);
2062- }
2063-
2064- TestTypeAndValuesMatch (
2065- type_text, value_text,
2066- internal::InternalError (" Nested value depth exceeds 10 levels" ));
2067-
2068- // Verify that nesting up to the limit is fine. 4 levels of nesting will
2069- // result in a maximum depth of 9.
2070- type_text = " int64_type {}" ;
2071- value_text = " int_value: 1" ;
2072- for (int i = 0 ; i < 4 ; ++i) {
2054+ // Test that exactly 10 levels does not cause a depth exceeded error.
2055+ for (int level = 1 ; level < 12 ; ++level) {
2056+ if (level <= 10 ) {
2057+ TestTypeAndValuesMatch (type_text, value_text, Status{});
2058+ } else {
2059+ TestTypeAndValuesMatch (
2060+ type_text, value_text,
2061+ internal::InternalError (" Nested value depth exceeds 10 levels" ));
2062+ }
20732063 type_text =
20742064 absl::Substitute (" struct_type { fields { type { $0 } } }" , type_text);
20752065 value_text = absl::Substitute (" array_value { values { $0 } }" , value_text);
20762066 }
2077- TestTypeAndValuesMatch (type_text, value_text, Status{});
20782067}
20792068
20802069} // namespace
0 commit comments