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"
12 class PDU_Factory_Filter_Test
: public PDU_Factory_Filter
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
)
48 PDU_Factory_Filter_Test
* filter
= new PDU_Factory_Filter_Test();
49 factory
.AddFilter( filter
);
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
)
65 PDU_Factory_Filter_Test
* filter
= new PDU_Factory_Filter_Test();
66 filter
->m_ApplyFilterReturnValue
= false;
67 factory
.AddFilter(filter
);
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
)
78 PDU_Factory_Filter_Test
* filter
= new PDU_Factory_Filter_Test();
79 filter
->m_ApplyFilterBeforeDecodingPDUBodyReturnValue
= false;
80 factory
.AddFilter(filter
);
82 KDataStream stream
= pdu
.Encode();
84 std::unique_ptr
<Header
> header
= factory
.Decode(stream
);
85 EXPECT_FALSE(header
.get());