1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 20:01:35 +01:00

LLC almost works

This commit is contained in:
Santiago Alessandri
2012-03-19 12:04:55 -03:00
parent 937a4d66cc
commit 01a7b812df
6 changed files with 710 additions and 60 deletions

202
tests/src/llc.cpp Normal file
View File

@@ -0,0 +1,202 @@
#include <gtest/gtest.h>
#include <cstring>
#include <string>
#include <stdint.h>
#include "llc.h"
using namespace Tins;
using namespace std;
class LLCTest : public testing::Test {
public:
static const uint8_t expected_packet[];
static const uint8_t from_buffer_unnumbered[];
static const uint8_t from_buffer_info[];
static const uint8_t from_buffer_super[];
//void test_equals(const IP &ip1, const IP &ip2);
};
const uint8_t LLCTest::expected_packet[] = {};
const uint8_t LLCTest::from_buffer_info[] = {'\xfe', '\x48', '\x3c', '\x3b'};
const uint8_t LLCTest::from_buffer_super[] = {'\x4b', '\x19', '\x05', '\x3a'};
const uint8_t LLCTest::from_buffer_unnumbered[] = {'\xaa', '\x17', '\xcf'};
TEST_F(LLCTest, DefaultConstructor) {
LLC llc;
EXPECT_EQ(llc.ssap(), 0);
EXPECT_EQ(llc.dsap(), 0);
EXPECT_EQ(llc.type(), LLC::INFORMATION);
EXPECT_EQ(llc.header_size(), 4);
EXPECT_EQ(llc.pdu_type(), PDU::LLC);
}
TEST_F(LLCTest, ParamsConstructor) {
LLC llc(0xAD, 0x16);
EXPECT_EQ(llc.dsap(), 0xAD);
EXPECT_EQ(llc.ssap(), 0x16);
EXPECT_EQ(llc.type(), LLC::INFORMATION);
EXPECT_EQ(llc.header_size(), 4);
EXPECT_EQ(llc.pdu_type(), PDU::LLC);
}
TEST_F(LLCTest, Group) {
LLC llc;
llc.group(true);
EXPECT_TRUE(llc.group());
llc.group(false);
EXPECT_FALSE(llc.group());
}
TEST_F(LLCTest, Dsap) {
LLC llc;
llc.dsap(0xaa);
EXPECT_EQ(llc.dsap(), 0xaa);
llc.dsap(0x01);
EXPECT_EQ(llc.dsap(), 0x01);
}
TEST_F(LLCTest, Command) {
LLC llc;
llc.command(true);
EXPECT_TRUE(llc.command());
llc.command(false);
EXPECT_FALSE(llc.command());
}
TEST_F(LLCTest, Ssap) {
LLC llc;
llc.ssap(0xaa);
EXPECT_EQ(llc.ssap(), 0xaa);
llc.ssap(0x01);
EXPECT_EQ(llc.ssap(), 0x01);
}
TEST_F(LLCTest, Type) {
LLC llc;
llc.type(LLC::INFORMATION);
EXPECT_EQ(llc.type(), LLC::INFORMATION);
llc.type(LLC::SUPERVISORY);
EXPECT_EQ(llc.type(), LLC::SUPERVISORY);
llc.type(LLC::UNNUMBERED);
EXPECT_EQ(llc.type(), LLC::UNNUMBERED);
}
TEST_F(LLCTest, HeadSize) {
LLC llc;
llc.type(LLC::INFORMATION);
EXPECT_EQ(llc.header_size(), 4);
llc.type(LLC::SUPERVISORY);
EXPECT_EQ(llc.header_size(), 4);
llc.type(LLC::UNNUMBERED);
EXPECT_EQ(llc.header_size(), 3);
}
TEST_F(LLCTest, SendSeqNumber) {
LLC llc;
llc.type(LLC::INFORMATION);
llc.send_seq_number(18);
EXPECT_EQ(18, llc.send_seq_number());
llc.send_seq_number(127);
EXPECT_EQ(127, llc.send_seq_number());
llc.type(LLC::SUPERVISORY);
EXPECT_EQ(0, llc.send_seq_number());
llc.type(LLC::UNNUMBERED);
EXPECT_EQ(0, llc.send_seq_number());
}
TEST_F(LLCTest, ReceiveSeqNumber) {
LLC llc;
llc.type(LLC::INFORMATION);
llc.receive_seq_number(18);
EXPECT_EQ(18, llc.receive_seq_number());
llc.send_seq_number(127);
EXPECT_EQ(127, llc.receive_seq_number());
llc.type(LLC::SUPERVISORY);
llc.receive_seq_number(19);
EXPECT_EQ(19, llc.receive_seq_number());
llc.send_seq_number(127);
EXPECT_EQ(127, llc.receive_seq_number());
llc.type(LLC::UNNUMBERED);
EXPECT_EQ(0, llc.receive_seq_number());
}
TEST_F(LLCTest, PollFinal) {
LLC llc;
llc.type(LLC::INFORMATION);
llc.poll_final(true);
EXPECT_TRUE(llc.poll_final());
llc.poll_final(false);
EXPECT_FALSE(llc.poll_final());
llc.type(LLC::SUPERVISORY);
llc.poll_final(true);
EXPECT_TRUE(llc.poll_final());
llc.poll_final(false);
EXPECT_FALSE(llc.poll_final());
llc.type(LLC::UNNUMBERED);
llc.poll_final(true);
EXPECT_TRUE(llc.poll_final());
llc.poll_final(false);
EXPECT_FALSE(llc.poll_final());
}
TEST_F(LLCTest, SupervisoryFunction) {
LLC llc;
llc.type(LLC::INFORMATION);
EXPECT_EQ(0, llc.supervisory_function());
llc.type(LLC::SUPERVISORY);
llc.supervisory_function(LLC::RECEIVE_NOT_READY);
EXPECT_EQ(LLC::RECEIVE_NOT_READY, llc.supervisory_function());
llc.supervisory_function(LLC::RECEIVE_READY);
EXPECT_EQ(LLC::RECEIVE_READY, llc.supervisory_function());
llc.type(LLC::UNNUMBERED);
EXPECT_EQ(0, llc.supervisory_function());
}
TEST_F(LLCTest, ModifierFunction) {
LLC llc;
llc.type(LLC::INFORMATION);
EXPECT_EQ(0, llc.modifier_function());
llc.type(LLC::SUPERVISORY);
EXPECT_EQ(0, llc.modifier_function());
llc.type(LLC::UNNUMBERED);
llc.modifier_function(LLC::TEST);
EXPECT_EQ(LLC::TEST, llc.modifier_function());
llc.modifier_function(LLC::XID);
EXPECT_EQ(LLC::XID, llc.modifier_function());
}
TEST_F(LLCTest, ConstructorFromBuffer) {
LLC llc(LLCTest::from_buffer_info, 4);
EXPECT_EQ(llc.type(), LLC::INFORMATION);
EXPECT_EQ(llc.header_size(), 4);
EXPECT_EQ(llc.dsap(), 0xFE);
EXPECT_EQ(llc.ssap(), 0x48);
EXPECT_FALSE(llc.group());
EXPECT_TRUE(llc.command());
EXPECT_TRUE(llc.poll_final());
EXPECT_EQ(llc.send_seq_number(), 30);
EXPECT_EQ(llc.receive_seq_number(), 29);
LLC llc_super(LLCTest::from_buffer_super, 4);
EXPECT_EQ(llc_super.header_size(), 4);
EXPECT_EQ(llc_super.dsap(), 0x4B);
EXPECT_EQ(llc_super.ssap(), 0x19);
EXPECT_TRUE(llc_super.group());
EXPECT_FALSE(llc_super.command());
EXPECT_FALSE(llc_super.poll_final());
EXPECT_EQ(llc_super.receive_seq_number(), 29);
EXPECT_EQ(llc_super.supervisory_function(), LLC::RECEIVE_NOT_READY);
LLC llc_unnum(LLCTest::from_buffer_unnumbered, 3);
EXPECT_EQ(llc_unnum.header_size(), 3);
EXPECT_EQ(llc_unnum.dsap(), 0xaa);
EXPECT_EQ(llc_unnum.ssap(), 0x17);
EXPECT_FALSE(llc_unnum.group());
EXPECT_FALSE(llc_unnum.command());
EXPECT_FALSE(llc_unnum.poll_final());
EXPECT_EQ(llc_unnum.modifier_function(), LLC::SABME);
}