summaryrefslogtreecommitdiff
path: root/common/test/gtest_ctrl_packet.cpp
diff options
context:
space:
mode:
authorliuchang <[email protected]>2023-03-22 02:20:43 +0000
committerliuchang <[email protected]>2023-03-22 02:20:43 +0000
commit0f8b9ba46a16e63670ba21750dd3963edfc23b5d (patch)
tree4be63ca3a87762a7d13e17262da61a4e6eb114b0 /common/test/gtest_ctrl_packet.cpp
parentf48b403acc34f72df2679636e7c047c862045c5a (diff)
add project code
Diffstat (limited to 'common/test/gtest_ctrl_packet.cpp')
-rw-r--r--common/test/gtest_ctrl_packet.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/common/test/gtest_ctrl_packet.cpp b/common/test/gtest_ctrl_packet.cpp
new file mode 100644
index 0000000..6c7efeb
--- /dev/null
+++ b/common/test/gtest_ctrl_packet.cpp
@@ -0,0 +1,27 @@
+#include <cstring>
+#include <gtest/gtest.h>
+
+#include "shaper_marsio.h"
+
+TEST(CTRL_PACKET, PARSE)
+{
+ const char *data = "{\"tsync\":\"1.0\",\"session_id\":\"123456789\",\"state\":\"active\",\"method\":\"policy_update\",\"params\":{\"service_chaining\":[1,2,3],\"shaping\":[4,5,6]}}";
+ size_t length = strlen(data);
+
+ struct ctrl_pkt_data ctrl_data;
+ memset(&ctrl_data, 0, sizeof(ctrl_data));
+ EXPECT_TRUE(shaper_marsio_ctrl_pkt_data_parse(&ctrl_data, data, length) == 0);
+
+ EXPECT_TRUE(ctrl_data.session_id == 123456789);
+ EXPECT_TRUE(ctrl_data.state == SESSION_STATE_ACTIVE);
+ EXPECT_TRUE(ctrl_data.shaping_rule_num == 3);
+ EXPECT_TRUE(ctrl_data.shaping_rule_ids[0] == 4);
+ EXPECT_TRUE(ctrl_data.shaping_rule_ids[1] == 5);
+ EXPECT_TRUE(ctrl_data.shaping_rule_ids[2] == 6);
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+} \ No newline at end of file