1 /* Test for dispatching replies in AT driver */
8 #include "../libgammu/phone/at/atgen.h"
9 #include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
10 #include "../libgammu/gsmstate.h" /* Needed for state machine internals */
11 #include "../libgammu/gsmphones.h" /* Phone data */
15 void do_test(const char *reply
, GSM_AT_Reply_State expected
, GSM_Error expect_error
)
17 GSM_Protocol_Message msg
;
20 msg
.Length
= strlen(reply
);
21 msg
.Buffer
= (char *)reply
;
24 s
->Phone
.Data
.RequestMsg
= &msg
;
26 error
= ATGEN_DispatchMessage(s
);
27 gammu_test_result_code(error
, "Dispatch", expect_error
);
31 int main(int argc UNUSED
, char **argv UNUSED
)
33 GSM_Debug_Info
*debug_info
;
34 GSM_Phone_ATGENData
*Priv
;
36 GSM_SecurityCodeType Status
;
37 GSM_SignalQuality Signal
;
39 /* Init locales to get proper encoding */
40 GSM_InitLocales(NULL
);
42 /* Configure state machine */
43 debug_info
= GSM_GetGlobalDebug();
44 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
45 GSM_SetDebugLevel("textall", debug_info
);
47 /* Allocates state machine */
48 s
= GSM_AllocStateMachine();
49 test_result(s
!= NULL
);
50 debug_info
= GSM_GetDebug(s
);
51 GSM_SetDebugGlobal(TRUE
, debug_info
);
53 /* Initialize AT engine */
54 Data
= &s
->Phone
.Data
;
55 Data
->ModelInfo
= GetModelData(NULL
, NULL
, "unknown", NULL
);
56 Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
57 Priv
->ReplyState
= AT_Reply_OK
;
58 Priv
->SMSMode
= SMS_AT_PDU
;
59 Priv
->Charset
= AT_CHARSET_GSM
;
60 s
->Phone
.Data
.SecurityStatus
= &Status
;
61 s
->Phone
.Functions
= &ATGENPhone
;
62 InitLines(&s
->Phone
.Data
.Priv
.ATGEN
.Lines
);
64 /* Perform real tests */
65 s
->Phone
.Data
.RequestID
= ID_GetSecurityStatus
;
66 s
->Protocol
.Data
.AT
.CPINNoOK
= TRUE
;
67 do_test("AT+CPIN?\r\n+CPIN: READY\r\n", AT_Reply_OK
, ERR_NONE
);
69 s
->Phone
.Data
.RequestID
= ID_GetSecurityStatus
;
70 s
->Protocol
.Data
.AT
.CPINNoOK
= FALSE
;
71 do_test("AT+CPIN?\r\n+CPIN: READY\r\n", AT_Reply_Unknown
, ERR_UNKNOWNRESPONSE
);
73 s
->Phone
.Data
.RequestID
= ID_GetSignalQuality
;
74 s
->Phone
.Data
.SignalQuality
= &Signal
;
75 do_test("AT+CSQ\r\nAT+CSQ\r\n+CME ERROR: 515", AT_Reply_CMEError
, ERR_UNKNOWN
);
77 /* Free state machine */
78 GSM_FreeStateMachine(s
);
83 /* Editor configuration
84 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: