Browse Source

Implement integer types tests

Alexey Edelev 6 years ago
parent
commit
fb3290adbd
3 changed files with 108 additions and 9 deletions
  1. 9 9
      src/generator/templates.cpp
  2. 28 0
      tests/proto/simpletest.proto
  3. 71 0
      tests/simpletest.cpp

+ 9 - 9
src/generator/templates.cpp

@@ -128,17 +128,17 @@ const char *Templates::QEnumTemplate = "Q_ENUM($type$)\n";
 const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string> Templates::TypeReflection = {
     {::google::protobuf::FieldDescriptor::TYPE_DOUBLE, "double"},
     {::google::protobuf::FieldDescriptor::TYPE_FLOAT, "float"},
-    {::google::protobuf::FieldDescriptor::TYPE_INT64, "int64"},
-    {::google::protobuf::FieldDescriptor::TYPE_UINT64,"uint64"},
+    {::google::protobuf::FieldDescriptor::TYPE_INT64, "int64"},     //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_UINT64,"uint64"},    //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
     {::google::protobuf::FieldDescriptor::TYPE_INT32, "int32"},
-    {::google::protobuf::FieldDescriptor::TYPE_FIXED64, "fint64"},
-    {::google::protobuf::FieldDescriptor::TYPE_FIXED32, "fint32"},
+    {::google::protobuf::FieldDescriptor::TYPE_FIXED64, "fint64"},  //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_FIXED32, "fint32"},  //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
     {::google::protobuf::FieldDescriptor::TYPE_BOOL, "bool"},
     {::google::protobuf::FieldDescriptor::TYPE_STRING, "QString"},
     {::google::protobuf::FieldDescriptor::TYPE_BYTES, "QByteArray"},
-    {::google::protobuf::FieldDescriptor::TYPE_UINT32, "sint32"},//Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
-    {::google::protobuf::FieldDescriptor::TYPE_SFIXED32, "sfint32"},
-    {::google::protobuf::FieldDescriptor::TYPE_SFIXED64, "sfint64"},
-    {::google::protobuf::FieldDescriptor::TYPE_SINT32, "sint32"},
-    {::google::protobuf::FieldDescriptor::TYPE_SINT64, "sint64"}
+    {::google::protobuf::FieldDescriptor::TYPE_UINT32, "uint32"},    //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_SFIXED32, "sfint32"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_SFIXED64, "sfint64"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_SINT32, "sint32"},    //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
+    {::google::protobuf::FieldDescriptor::TYPE_SINT64, "sint64"}     //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
 };

+ 28 - 0
tests/proto/simpletest.proto

@@ -18,6 +18,26 @@ message SimpleIntMessage {
     int32 testFieldInt = 1;
 }
 
+message SimpleSIntMessage {
+    sint32 testFieldInt = 1;
+}
+
+message SimpleUIntMessage {
+    uint32 testFieldInt = 1;
+}
+
+message SimpleInt64Message {
+    int64 testFieldInt = 1;
+}
+
+message SimpleSInt64Message {
+    sint64 testFieldInt = 1;
+}
+
+message SimpleUInt64Message {
+    uint64 testFieldInt = 1;
+}
+
 message SimpleStringMessage {
     string testFieldString = 6;
 }
@@ -42,6 +62,14 @@ message SimpleFixedInt64Message {
     fixed64 testFieldFixedInt64 = 1;
 }
 
+message SimpleSFixedInt32Message {
+    sfixed32 testFieldFixedInt32 = 1;
+}
+
+message SimpleSFixedInt64Message {
+    sfixed64 testFieldFixedInt64 = 1;
+}
+
 message ComplexMessage {
     int32 testFieldInt = 1;
     SimpleStringMessage testComplexField = 2;

+ 71 - 0
tests/simpletest.cpp

@@ -26,6 +26,11 @@
 #include "simpletest.h"
 
 #include "simpleintmessage.h"
+#include "simplesintmessage.h"
+#include "simpleuintmessage.h"
+#include "simpleint64message.h"
+#include "simplesint64message.h"
+#include "simpleuint64message.h"
 #include "simplefixedint32message.h"
 #include "simplefixedint64message.h"
 #include "simplestringmessage.h"
@@ -55,6 +60,7 @@ TEST_F(SimpleTest, SimpleIntMessageTest)
     const char* propertyName = "testFieldInt";
     SimpleIntMessage test;
     int propertyNumber = SimpleIntMessage::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32");
     ASSERT_EQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int32>());
     ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
@@ -62,6 +68,71 @@ TEST_F(SimpleTest, SimpleIntMessageTest)
     ASSERT_EQ(test.testFieldInt(), 1);
 }
 
+TEST_F(SimpleTest, SimpleSIntMessageTest)
+{
+    const char* propertyName = "testFieldInt";
+    SimpleSIntMessage test;
+    int propertyNumber = SimpleSIntMessage::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32");
+    ASSERT_EQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint32>());
+    ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
+    ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
+    ASSERT_EQ(test.property(propertyName).toInt(), 1);
+    ASSERT_EQ(test.testFieldInt(), 1);
+}
+
+TEST_F(SimpleTest, SimpleUIntMessageTest)
+{
+    const char* propertyName = "testFieldInt";
+    SimpleUIntMessage test;
+    int propertyNumber = SimpleUIntMessage::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32");
+    ASSERT_EQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint32>());
+    ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
+    ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
+    ASSERT_EQ(test.property(propertyName).toInt(), 1);
+    ASSERT_EQ(test.testFieldInt(), 1);
+}
+
+TEST_F(SimpleTest, SimpleInt64MessageTest)
+{
+    const char* propertyName = "testFieldInt";
+    SimpleInt64Message test;
+    int propertyNumber = SimpleInt64Message::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64");
+    ASSERT_EQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int64>());
+    ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
+    ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
+    ASSERT_EQ(test.property(propertyName).toInt(), 1);
+    ASSERT_EQ(test.testFieldInt(), 1);
+}
+
+TEST_F(SimpleTest, SimpleSInt64MessageTest)
+{
+    const char* propertyName = "testFieldInt";
+    SimpleSInt64Message test;
+    int propertyNumber = SimpleSInt64Message::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64");
+    ASSERT_EQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint64>());
+    ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
+    ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
+    ASSERT_EQ(test.property(propertyName).toInt(), 1);
+    ASSERT_EQ(test.testFieldInt(), 1);
+}
+
+TEST_F(SimpleTest, SimpleUInt64MessageTest)
+{
+    const char* propertyName = "testFieldInt";
+    SimpleUInt64Message test;
+    int propertyNumber = SimpleUInt64Message::propertyOrdering.at(1); //See simpletest.proto
+    ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64");
+    ASSERT_EQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint64>());
+    ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
+    ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
+    ASSERT_EQ(test.property(propertyName).toInt(), 1);
+    ASSERT_EQ(test.testFieldInt(), 1);
+}
+
 TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
 {
     const char* propertyName = "testFieldFixedInt32";