Added option not to use configured logging in SMSD inject and monitor (bug #1539).
[gammu.git] / tests / at-dispatch.c
blobb1a325d2a4c4e7bc86e032afbbec32ab02ab265d
1 /* Test for dispatching replies in AT driver */
3 #include <gammu.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include "common.h"
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 */
13 GSM_StateMachine *s;
15 void do_test(const char *reply, GSM_AT_Reply_State expected, GSM_Error expect_error)
17 GSM_Protocol_Message msg;
18 GSM_Error error;
20 msg.Length = strlen(reply);
21 msg.Buffer = (char *)reply;
22 msg.Type = 0;
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;
35 GSM_Phone_Data *Data;
36 GSM_SecurityCodeType Status;
38 /* Init locales to get proper encoding */
39 GSM_InitLocales(NULL);
41 /* Configure state machine */
42 debug_info = GSM_GetGlobalDebug();
43 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
44 GSM_SetDebugLevel("textall", debug_info);
46 /* Allocates state machine */
47 s = GSM_AllocStateMachine();
48 test_result(s != NULL);
49 debug_info = GSM_GetDebug(s);
50 GSM_SetDebugGlobal(TRUE, debug_info);
52 /* Initialize AT engine */
53 Data = &s->Phone.Data;
54 Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
55 Priv = &s->Phone.Data.Priv.ATGEN;
56 Priv->ReplyState = AT_Reply_OK;
57 Priv->SMSMode = SMS_AT_PDU;
58 Priv->Charset = AT_CHARSET_GSM;
59 s->Phone.Data.SecurityStatus = &Status;
60 s->Phone.Functions = &ATGENPhone;
61 InitLines(&s->Phone.Data.Priv.ATGEN.Lines);
63 /* Perform real tests */
64 s->Phone.Data.RequestID = ID_GetSecurityStatus;
65 s->Protocol.Data.AT.CPINNoOK = TRUE;
66 do_test("AT+CPIN?\r\n+CPIN: READY\r\n", AT_Reply_OK, ERR_NONE);
68 s->Phone.Data.RequestID = ID_GetSecurityStatus;
69 s->Protocol.Data.AT.CPINNoOK = FALSE;
70 do_test("AT+CPIN?\r\n+CPIN: READY\r\n", AT_Reply_Unknown, ERR_UNKNOWNRESPONSE);
72 /* Free state machine */
73 GSM_FreeStateMachine(s);
75 return 0;
78 /* Editor configuration
79 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: