dep-protobuf/upb/test/parse_text_proto.h
Adam Cozzette 501ececd39 Reorganize upb file structure
This change moves almost everything in the `upb/` directory up one level, so
that for example `upb/upb/generated_code_support.h` becomes just
`upb/generated_code_support.h`. The only exceptions I made to this were that I
left `upb/cmake` and `upb/BUILD` where they are, mostly because that avoids
conflict with other files and the current locations seem reasonable for now.

The `python/` directory is a little bit of a challenge because we had to merge
the existing directory there with `upb/python/`. I made `upb/python/BUILD` into
the BUILD file for the merged directory, and it effectively loads the contents
of the other BUILD file via `python/build_targets.bzl`, but I plan to clean
this up soon.

PiperOrigin-RevId: 568651768
2023-09-26 14:38:35 -07:00

44 lines
1.2 KiB
C++

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef UPB_UPB_TEST_PARSE_TEXT_PROTO_H_
#define UPB_UPB_TEST_PARSE_TEXT_PROTO_H_
#include <string>
#include <gtest/gtest.h>
#include "google/protobuf/message.h"
#include "google/protobuf/text_format.h"
namespace upb_test {
// Replacement for Google ParseTextProtoOrDie.
// Only to be used in unit tests.
// Usage: MyMessage msg = ParseTextProtoOrDie(my_text_proto);
class ParseTextProtoOrDie {
public:
explicit ParseTextProtoOrDie(absl::string_view text_proto)
: text_proto_(text_proto) {}
template <class T>
operator T() { // NOLINT: Needed to support parsing text proto as appropriate
// type.
T message;
if (!google::protobuf::TextFormat::ParseFromString(text_proto_, &message)) {
ADD_FAILURE() << "Failed to parse textproto: " << text_proto_;
abort();
}
return message;
}
private:
std::string text_proto_;
};
} // namespace upb_test
#endif // UPB_UPB_TEST_PARSE_TEXT_PROTO_H_