/* * MIT License * * Copyright (c) 2019 Alexey Edelev * * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be included in all copies * or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "wellknowntypes.qpb.h" #include "../testscommon.h" using namespace google::protobuf; namespace QtProtobuf { namespace tests { class WellknowntypesTest : public ::testing::Test { public: // see simpletest.proto for property names and their field indices WellknowntypesTest() { } static void SetUpTestCase() { QtProtobuf::qRegisterProtobufTypes(); serializer.reset(new QProtobufSerializer); } static std::unique_ptr serializer; }; std::unique_ptr WellknowntypesTest::serializer; TEST_F(WellknowntypesTest, AnyTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "typeUrl"); assertMessagePropertyRegistered(2, "QByteArray", "value"); } TEST_F(WellknowntypesTest, ApiTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "google::protobuf::MethodRepeated", "methodsData"); assertMessagePropertyRegistered(3, "google::protobuf::OptionRepeated", "optionsData"); assertMessagePropertyRegistered(4, "QString", "version"); assertMessagePropertyRegistered(5, "google::protobuf::SourceContext*", "sourceContext", true); assertMessagePropertyRegistered(6, "google::protobuf::MixinRepeated", "mixinsData"); assertMessagePropertyRegistered(7, "google::protobuf::SyntaxGadget::Syntax", "syntax"); } TEST_F(WellknowntypesTest, MethodTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "QString", "requestTypeUrl"); assertMessagePropertyRegistered(3, "bool", "requestStreaming"); assertMessagePropertyRegistered(4, "QString", "responseTypeUrl"); assertMessagePropertyRegistered(5, "bool", "responseStreaming"); assertMessagePropertyRegistered(6, "google::protobuf::OptionRepeated", "optionsData"); assertMessagePropertyRegistered(7, "google::protobuf::SyntaxGadget::Syntax", "syntax"); } TEST_F(WellknowntypesTest, MixinTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "QString", "root"); } TEST_F(WellknowntypesTest, DurationTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QtProtobuf::int64", "seconds"); assertMessagePropertyRegistered(2, "QtProtobuf::int32", "nanos_p"); } TEST_F(WellknowntypesTest, EmptyTest) { ASSERT_GT(qMetaTypeId(), 0); } TEST_F(WellknowntypesTest, FieldMaskTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QStringList", "pathsData"); } TEST_F(WellknowntypesTest, SourceContextTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "fileName"); } TEST_F(WellknowntypesTest, StructTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "google::protobuf::Struct::FieldsEntry", "fields"); } TEST_F(WellknowntypesTest, ValueTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "google::protobuf::NullValueGadget::NullValue", "nullValue"); assertMessagePropertyRegistered(2, "double", "numberValue"); assertMessagePropertyRegistered(3, "QString", "stringValue"); assertMessagePropertyRegistered(4, "bool", "boolValue"); assertMessagePropertyRegistered(5, "google::protobuf::Struct*", "structValue"); assertMessagePropertyRegistered(6, "google::protobuf::ListValue*", "listValue"); } TEST_F(WellknowntypesTest, ListValueTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "google::protobuf::ValueRepeated", "valuesData"); } TEST_F(WellknowntypesTest, TimestampTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QtProtobuf::int64", "seconds"); assertMessagePropertyRegistered(2, "QtProtobuf::int32", "nanos_p"); } TEST_F(WellknowntypesTest, TypeTest) { ASSERT_GT(qMetaTypeId(), 0); Q_PROPERTY(QStringList oneofs READ oneofs WRITE setOneofs NOTIFY oneofsChanged) assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "google::protobuf::FieldRepeated", "fieldsData"); assertMessagePropertyRegistered(3, "QStringList", "oneofsData"); assertMessagePropertyRegistered(4, "google::protobuf::OptionRepeated", "optionsData"); assertMessagePropertyRegistered(5, "google::protobuf::SourceContext*", "sourceContext", true); assertMessagePropertyRegistered(6, "google::protobuf::SyntaxGadget::Syntax", "syntax"); } TEST_F(WellknowntypesTest, FieldTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "Kind", "kind"); assertMessagePropertyRegistered(2, "Cardinality", "cardinality"); assertMessagePropertyRegistered(3, "QtProtobuf::int32", "number_p"); assertMessagePropertyRegistered(4, "QString", "name"); assertMessagePropertyRegistered(6, "QString", "typeUrl"); assertMessagePropertyRegistered(7, "QtProtobuf::int32", "oneofIndex_p"); assertMessagePropertyRegistered(8, "bool", "packed"); assertMessagePropertyRegistered(9, "google::protobuf::OptionRepeated", "optionsData"); assertMessagePropertyRegistered(10, "QString", "jsonName"); assertMessagePropertyRegistered(11, "QString", "defaultValue"); } TEST_F(WellknowntypesTest, EnumTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "google::protobuf::EnumValueRepeated", "enumvalueData"); assertMessagePropertyRegistered(3, "google::protobuf::OptionRepeated", "optionsData"); assertMessagePropertyRegistered(4, "google::protobuf::SourceContext*", "sourceContext", true); assertMessagePropertyRegistered(5, "google::protobuf::SyntaxGadget::Syntax", "syntax"); } TEST_F(WellknowntypesTest, EnumValueTest) { ASSERT_GT(qMetaTypeId(), 0); assertMessagePropertyRegistered(1, "QString", "name"); assertMessagePropertyRegistered(2, "QtProtobuf::int32", "number_p"); assertMessagePropertyRegistered(3, "google::protobuf::OptionRepeated", "optionsData"); } TEST_F(WellknowntypesTest, OptionTest) { ASSERT_GT(qMetaTypeId