Andrew Geissler | 0e948dc | 2024-05-23 09:51:48 -0500 | [diff] [blame] | 1 | #include "slp.hpp" |
| 2 | #include "slp_meta.hpp" |
| 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | /* 0 1 2 3 |
| 7 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 8 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 9 | | Version | Function-ID | Length | |
| 10 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 11 | | Length, contd.|O|F|R| reserved |Next Ext Offset| |
| 12 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 13 | | Next Extension Offset, contd.| XID | |
| 14 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 15 | | Language Tag Length | Language Tag \ |
| 16 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ |
| 17 | |
| 18 | TEST(parseHeaderTest, BasicGoodPath) |
| 19 | { |
| 20 | // Basic buffer with valid Function-ID |
| 21 | slp::buffer testData{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 23 | |
| 24 | slp::Message req; |
| 25 | int rc = slp::SUCCESS; |
| 26 | std::tie(rc, req) = slp::parser::internal::parseHeader(testData); |
| 27 | |
| 28 | EXPECT_EQ(rc, 0); |
| 29 | } |
| 30 | |
| 31 | TEST(parseHeaderTest, InvalidBufferSize) |
| 32 | { |
| 33 | // 1 byte too small |
| 34 | slp::buffer testData{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 36 | |
| 37 | slp::Message req; |
| 38 | int rc = slp::SUCCESS; |
| 39 | std::tie(rc, req) = slp::parser::internal::parseHeader(testData); |
| 40 | |
| 41 | EXPECT_NE(rc, 0); |
| 42 | } |
Andrew Geissler | c668313 | 2024-05-23 10:21:26 -0500 | [diff] [blame^] | 43 | |
| 44 | TEST(parseHeaderTest, ValidLangTagLength) |
| 45 | { |
| 46 | // Language Tag Length that is valid |
| 47 | slp::buffer testData{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; |
| 49 | |
| 50 | slp::Message req; |
| 51 | int rc = slp::SUCCESS; |
| 52 | std::tie(rc, req) = slp::parser::internal::parseHeader(testData); |
| 53 | |
| 54 | EXPECT_EQ(rc, 0); |
| 55 | } |
| 56 | |
| 57 | TEST(parseHeaderTest, InvalidLangTagLength) |
| 58 | { |
| 59 | // Language Tag Length that is too big |
| 60 | slp::buffer testData{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 61 | 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; |
| 62 | |
| 63 | slp::Message req; |
| 64 | int rc = slp::SUCCESS; |
| 65 | std::tie(rc, req) = slp::parser::internal::parseHeader(testData); |
| 66 | |
| 67 | EXPECT_NE(rc, 0); |
| 68 | } |