Эх сурвалжийг харах

Added a test case to verify setting and clearing a enum in a oneof field.

Bart Hertog 5 жил өмнө
parent
commit
39c463d6f4

+ 8 - 0
test/proto/oneof_fields.proto

@@ -50,11 +50,19 @@ message message_oneof
 {
   int32 a = 1;
 
+  enum States {
+    Idle = 0;
+    Run = 1;
+    Done = 2;
+    Error = 3;
+  }
+
   oneof xyz 
   {
     int32 x = 5;
     int32 y = 6;
     int32 z = 7;
+    States state = 8;
   }
 
   int32 b = 10;

+ 6 - 0
test/test_oneof_fields.cpp

@@ -84,6 +84,12 @@ TEST(OneofField, set_get_clear)
   EXPECT_EQ(message_oneof::id::Z, msg.get_which_xyz());
   msg.clear_z();
 
+  EXPECT_EQ(message_oneof::id::NOT_SET, msg.get_which_xyz());
+  msg.set_state(message_oneof::States::Run);
+  EXPECT_EQ(message_oneof::States::Run, msg.get_state());
+  EXPECT_EQ(message_oneof::id::STATE, msg.get_which_xyz());
+  msg.clear_state();
+
   EXPECT_EQ(message_oneof::id::NOT_SET, msg.get_which_xyz());
 
   EXPECT_EQ(message_oneof::id::NOT_SET, msg.get_which_message());