chore: added config.h.in generated by CMake
[KDIS.git] / test / UnitTests / PDU_Factory.cpp
blob4796b95acd561ae88304098589e7dc025824f677
1 #include <iostream>
2 #include "gtest/gtest.h"
4 #include "KDIS/KDefines.h"
5 #include "KDIS/Extras/PDU_Factory.h"
6 #include "KDIS/PDU/Entity_Info_Interaction/Entity_State_PDU.h"
8 using namespace KDIS;
9 using namespace UTILS;
10 using namespace PDU;
12 class PDU_Factory_Filter_Test : public PDU_Factory_Filter
14 public:
16 int m_ApplyFilterCalled;
17 int m_AppplyFilterBeforeDecodingPDUBodyCalled;
19 KBOOL m_ApplyFilterReturnValue;
20 KBOOL m_ApplyFilterBeforeDecodingPDUBodyReturnValue;
22 PDU_Factory_Filter_Test() :
23 m_ApplyFilterCalled(0),
24 m_AppplyFilterBeforeDecodingPDUBodyCalled(0),
25 m_ApplyFilterReturnValue(true),
26 m_ApplyFilterBeforeDecodingPDUBodyReturnValue(true)
30 ~PDU_Factory_Filter_Test() {};
32 virtual KBOOL ApplyFilter( const KDIS::PDU::Header * H )
34 ++m_ApplyFilterCalled;
35 return m_ApplyFilterReturnValue;
38 virtual KBOOL ApplyFilterBeforeDecodingPDUBody(const KDIS::PDU::Header * H)
40 ++m_AppplyFilterBeforeDecodingPDUBodyCalled;
41 return m_ApplyFilterBeforeDecodingPDUBodyReturnValue;
45 TEST( PDU_Factory, PDU_Factory_Filter_FiltersAreUsed )
47 PDU_Factory factory;
48 PDU_Factory_Filter_Test * filter = new PDU_Factory_Filter_Test();
49 factory.AddFilter( filter );
50 Entity_State_PDU pdu;
51 KDataStream stream = pdu.Encode();
53 ASSERT_EQ(0, filter->m_ApplyFilterCalled);
54 ASSERT_EQ(0, filter->m_AppplyFilterBeforeDecodingPDUBodyCalled);
56 std::unique_ptr<Header> header = factory.Decode(stream);
58 EXPECT_EQ(1, filter->m_ApplyFilterCalled);
59 EXPECT_EQ(1, filter->m_AppplyFilterBeforeDecodingPDUBodyCalled);
62 TEST( PDU_Factory, PDU_Factory_Filter_ApplyFilterFalse_RejectsPDU )
64 PDU_Factory factory;
65 PDU_Factory_Filter_Test * filter = new PDU_Factory_Filter_Test();
66 filter->m_ApplyFilterReturnValue = false;
67 factory.AddFilter(filter);
68 Entity_State_PDU pdu;
69 KDataStream stream = pdu.Encode();
71 std::unique_ptr<Header> header = factory.Decode(stream);
72 EXPECT_FALSE(header.get());
75 TEST( PDU_Factory, PDU_Factory_Filter_ApplyFilterBeforeDecodingPDUBody_RejectsPDU )
77 PDU_Factory factory;
78 PDU_Factory_Filter_Test * filter = new PDU_Factory_Filter_Test();
79 filter->m_ApplyFilterBeforeDecodingPDUBodyReturnValue = false;
80 factory.AddFilter(filter);
81 Entity_State_PDU pdu;
82 KDataStream stream = pdu.Encode();
84 std::unique_ptr<Header> header = factory.Decode(stream);
85 EXPECT_FALSE(header.get());