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
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 
55  return 0;
57  return 0;
58 
60  return 0;
62  return 0;
63 
65  return 0;
67  return 0;
68 
71  return 0;
74  return 0;
75 
78  return 0;
81  return 0;
82 
85  return 0;
88  return 0;
89 
92  return 0;
95  return 0;
96 
97  if (CrFwFindKeyIndex(testArray3,1,5) != 0)
98  return 0;
99 
100  if (CrFwFindKeyIndex(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 */
118 
119  /* Initialize and Configure InFactory and check success */
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 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
void CrFwCmpReset(FwSmDesc_t smDesc)
Reset a framework component.
Definition: CrFwBaseCmp.c:117
Definition of Base Component.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
Definition of the InCommand Component of the framework.
FwSmDesc_t CrFwInFactoryMakeInCmd(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming command (InCommand).
void CrFwInFactoryReleaseInCmd(FwSmDesc_t inCmdInstance)
Release function for an InCommand.
FwSmDesc_t CrFwInFactoryMake()
Factory function for the singleton instance of the InFactory.
static FwSmDesc_t inFactory
The singleton instance of the InFactory.
Definition of the InFactory component.
Definition of the OutRegistry Component.
User-modifiable parameters for the OutRegistry component (see CrFwOutRegistry.h).
Interface for creating and accessing a report or command packet.
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:327
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:363
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:247
CrFwCrc_t CrFwPcktComputeCrc(CrFwPckt_t pckt)
Compute the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:277
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:309
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:315
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:375
void CrFwPcktSetCrc(CrFwPckt_t pckt, CrFwCrc_t crc)
Set the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:283
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:351
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:422
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Definition: CrFwPckt.c:147
Interface for reporting an error detected by a framework component.
Interface through which framework components access the current time.
unsigned short CrFwCmdRepKindIndex_t
Type for the index of a command or report kind.
unsigned short CrFwCrc_t
Type used for the CRC field in a packet.
@ crNoAppErr
No application errors have been detected.
unsigned int CrFwCmdRepKindKey_t
Type for the component kind key in CrFwInFactory.c and CrFwOutFactory.c.
CrFwOutcome_t CrFwGetSmOutcome(FwSmDesc_t smDesc)
Convenience function to get the outcome of the last check or action of a state machine.
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
void CrFwSetSmOutcome(FwSmDesc_t smDesc, CrFwOutcome_t outcome)
Convenience function to set the outcome of the last check or action of a state machine.
void CrFwSmEmptyAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which retu...
CrFwBool_t CrFwSmCheckAlwaysTrue(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for a check which always...
CrFwCounterU2_t CrFwFindKeyIndex(CrFwCounterU3_t *keyValArray, CrFwCounterU2_t length, CrFwCounterU3_t targetKey)
Convenience function to retrieve the index of an array where a certain target value is located.
void CrFwSmSuccessAction(FwSmDesc_t smDesc)
Convenience function to be used in a state machine as default implementation for an action which sets...
Definition of the utility functions for the CORDET Framework.
CrFwBool_t CrFwUtilityFunctionsTestCase2()
Test the convenience utility functions which are not exercised in other test cases.
#define CR_FW_UTILITYFUNCTIONS_TESTCASES_EVEN_SIZE
The even size of the test array.
#define CR_FW_UTILITYFUNCTIONS_TESTCASES_ODD_SIZE
The odd size of the test array.
CrFwBool_t CrFwUtilityFunctionsTestCase1()
Test the CrFwFindKeyIndex function.
Declaration of the test cases for the Utility Functions (see CrFwUtilityFunctions....
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved