CORDET Framework - C2 Implementation
CrFwUtilityFunctionsTestCases.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
21 /* Include framework files */
23 #include "CrFwOutRegistryUserPar.h"
25 #include "BaseCmp/CrFwBaseCmp.h"
26 #include "Pckt/CrFwPckt.h"
27 #include "InCmd/CrFwInCmd.h"
29 #include "CrFwTime.h"
30 #include "CrFwRepErr.h"
32 
34 #define CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE 20
35 
36 #define CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE 21
37 
38 /* ---------------------------------------------------------------------------------------------*/
42  CrFwCmdRepKindKey_t testArray3[1];
44 
45  /* Fill up the test arrays */
47  testArray1[i] = (CrFwCmdRepKindKey_t)(2*i+4);
48 
50  testArray2[i] = (CrFwCmdRepKindKey_t)(2*i+4);
51 
52  testArray3[0] = 5;
53 
54  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,8) != 2)
55  return 0;
56  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,8) != 2)
57  return 0;
58 
59  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,10) != 3)
60  return 0;
61  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,10) != 3)
62  return 0;
63 
64  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,4) != 0)
65  return 0;
66  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,4) != 0)
67  return 0;
68 
69  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,
70  2*CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE+4) != CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE)
71  return 0;
72  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,
73  2*CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE+4) != CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE)
74  return 0;
75 
76  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,2) !=
78  return 0;
79  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,2) !=
81  return 0;
82 
83  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,60) !=
85  return 0;
86  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,60) !=
88  return 0;
89 
90  if (CrFwFindCmdRepKindIndex(testArray1,CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE,11) !=
92  return 0;
93  if (CrFwFindCmdRepKindIndex(testArray2,CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE,11) !=
95  return 0;
96 
97  if (CrFwFindCmdRepKindIndex(testArray3,1,5) != 0)
98  return 0;
99 
100  if (CrFwFindCmdRepKindIndex(testArray3,1,6) != 1)
101  return 0;
102 
103  /* Check application errors */
104  if (CrFwGetAppErrCode() != crNoAppErr)
105  return 0;
106 
107  return 1;
108 }
109 
110 /* ---------------------------------------------------------------------------------------------*/
112  FwSmDesc_t inFactory, inCmd1;
113  CrFwPckt_t pckt1;
114  CrFwCrc_t crc;
115 
116  /* Instantiate the InFactory */
117  inFactory = CrFwInFactoryMake();
118 
119  /* Initialize and Configure InFactory and check success */
120  CrFwCmpInit(inFactory);
121  CrFwCmpReset(inFactory);
122  if (!CrFwCmpIsInConfigured(inFactory))
123  return 0;
124 
125  /* Allocate two InCommands of which one has the correct CRC and one the incorrect CRC */
126  pckt1 = CrFwPcktMake(100);
127  CrFwPcktSetServType(pckt1,8);
128  CrFwPcktSetServSubType(pckt1,1);
129  CrFwPcktSetDiscriminant(pckt1,2);
130  CrFwPcktSetCmdRepId(pckt1,111);
131  CrFwPcktSetSrc(pckt1,11);
132  CrFwPcktSetGroup(pckt1,88);
133  CrFwPcktSetAckLevel(pckt1,1,0,1,0);
134  CrFwPcktSetSeqCnt(pckt1,1111);
135  crc = CrFwPcktComputeCrc(pckt1);
136  CrFwPcktSetCrc(pckt1, crc);
137  inCmd1 = CrFwInFactoryMakeInCmd(pckt1);
138  if (CrFwSmCheckAlwaysTrue(NULL) != 1)
139  return 0;
140 
141  /* Execute the Empty Action */
142  CrFwSmEmptyAction(NULL);
143 
144  /* Execute the Success Action and verify that it sets the command's outcome to 1 */
145  CrFwSetSmOutcome(inCmd1, 0);
146  CrFwSmSuccessAction(inCmd1);
147  if (CrFwGetSmOutcome(inCmd1) != 1)
148  return 0;
149 
150  /* Release the InCommand */
152 
153  /* Check application errors */
154  if (CrFwGetAppErrCode() != crNoAppErr)
155  return 0;
156 
157  return 1;
158 }
void CrFwPcktSetAckLevel(CrFwPckt_t pckt, CrFwBool_t accept, CrFwBool_t start, CrFwBool_t progress, CrFwBool_t term)
Set the acknowledge level for the command encapsulated in a packet.
Definition: CrFwPckt.c:345
Interface through which framework components access the current time.
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:321
void CrFwSmEmptyAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which retu...
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:392
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc)
Return true if the argument component is in state CONFIGURED.
Definition: CrFwBaseCmp.c:177
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Definition: CrFwPckt.c:129
static FwSmDesc_t inFactory
The singleton instance of the InFactory.
Interface for creating and accessing a report or command packet.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
CrFwCmdRepKindIndex_t CrFwFindCmdRepKindIndex(CrFwCmdRepKindKey_t *cmdRepKindArray, CrFwCmdRepKindIndex_t length, CrFwCmdRepKindKey_t targetKey)
Convenience function to retrieve the index of an array where a certain target value is located...
void CrFwPcktSetCmdRepId(CrFwPckt_t pckt, CrFwInstanceId_t id)
Set the command or report identifier in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:333
Definition of the OutRegistry Component.
CrFwCrc_t CrFwPcktComputeCrc(CrFwPckt_t pckt)
Compute the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:247
unsigned int CrFwCmdRepKindKey_t
Type for the component kind key in CrFwInFactory.c and CrFwOutFactory.c.
Interface for reporting an error detected by a framework component.
unsigned short CrFwCmdRepKindIndex_t
Type for the index of a command or report kind.
CrFwBool_t CrFwSmCheckAlwaysTrue(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
void CrFwSmSuccessAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which sets...
#define CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE
The odd size of the test array.
void CrFwPcktSetServSubType(CrFwPckt_t pckt, CrFwServSubType_t servSubType)
Set the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:297
#define CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE
The even size of the test array.
Definition of the InFactory component.
CrFwBool_t CrFwUtilityFunctionsTestCase2()
Test the convenience utility functions which are not exercised in other test cases.
Definition of the utility functions for the CORDET Framework.
void CrFwCmpReset(FwSmDesc_t smDesc)
Reset a framework component.
Definition: CrFwBaseCmp.c:117
CrFwOutcome_t CrFwGetSmOutcome(FwSmDesc_t smDesc)
Convenience function to get the outcome of the last check or action of a state machine.
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:285
void CrFwSetSmOutcome(FwSmDesc_t smDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome of the last check or action of a state machine.
CrFwBool_t CrFwUtilityFunctionsTestCase1()
Test the CrFwFindCmdRepKindIndex function.
Definition of Base Component.
FwSmDesc_t CrFwInFactoryMake()
Factory function for the singleton instance of the InFactory.
unsigned short CrFwCrc_t
Type used for the CRC field in a packet.
Declaration of the test cases for the Utility Functions (see CrFwUtilityFunctions.h).
void CrFwInFactoryReleaseInCmd(FwSmDesc_t inCmdInstance)
Release function for an InCommand.
void CrFwPcktSetCrc(CrFwPckt_t pckt, CrFwCrc_t crc)
Set the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:253
User-modifiable parameters for the OutRegistry component (see CrFwOutRegistry.h). ...
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:229
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:279
No application errors have been detected.
FwSmDesc_t CrFwInFactoryMakeInCmd(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming command (InCommand).
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
Definition of the InCommand Component of the framework.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved