1 /* Test for decoding 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 */
13 #define BUFFER_SIZE ((size_t)16384)
15 int main(int argc UNUSED
, char **argv UNUSED
)
17 GSM_Debug_Info
*debug_info
;
18 GSM_Phone_ATGENData
*Priv
;
21 unsigned char buffer
[BUFFER_SIZE
];
26 /* Init locales to get proper encoding */
27 GSM_InitLocales(NULL
);
29 /* Configure state machine */
30 debug_info
= GSM_GetGlobalDebug();
31 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
32 GSM_SetDebugLevel("textall", debug_info
);
34 /* Allocates state machine */
35 s
= GSM_AllocStateMachine();
36 test_result(s
!= NULL
);
37 debug_info
= GSM_GetDebug(s
);
38 GSM_SetDebugGlobal(TRUE
, debug_info
);
40 /* Initialize AT engine */
41 Data
= &s
->Phone
.Data
;
42 Data
->ModelInfo
= GetModelData(NULL
, NULL
, "unknown", NULL
);
43 Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
44 Priv
->ReplyState
= AT_Reply_OK
;
45 Priv
->SMSMode
= SMS_AT_PDU
;
46 Priv
->Charset
= AT_CHARSET_GSM
;
48 /* Perform real tests */
49 error
= ATGEN_ParseReply(s
,
50 "+CPBR: 1,,\"+31234657899\",145,\"Mama GSM\",\"2007/11/02,09:27\"",
51 "+CPBR: @i, @s, @p, @i, @s, @d", &i
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
, &dt
);
52 gammu_test_result(error
, "+CPBR: @i, @s, @p, @i, @s, @d");
54 error
= ATGEN_ParseReply(s
,
55 "+CPBR: 6,\"\",,\"005300740061006E006C006500790020005000610075006C\"", "+CPBR: @i, @p, @I, @s", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
);
56 gammu_test_result(error
, "+CPBR: @i, @p, @I, @s");
58 error
= ATGEN_ParseReply(s
,
59 "+CPBR: 1,\"+60122256476\",145,\"\",\"08/07/04\",\"17:24:55\"",
60 "+CPBR: @i, @p, @I, @s, @d", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
, &dt
);
61 gammu_test_result(error
, "+CPBR: @i, @p, @I, @s, @d");
63 Priv
->Charset
= AT_CHARSET_UCS2
;
64 Priv
->Manufacturer
= AT_Motorola
;
65 error
= ATGEN_ParseReply(s
,
66 "+CPBR: 419,\"030450566735\",129,56697263686F77204B6C696E696B756D2053742E20333100",
67 "+CPBR: @i, @p, @I, @s", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
);
68 gammu_test_result(error
, "+CPBR: @i, @p, @I, @s");
70 Priv
->Charset
= AT_CHARSET_UCS2
;
71 Priv
->Manufacturer
= AT_Motorola
;
72 error
= ATGEN_ParseReply(s
,
73 "+CPBR: 419,\"030450566735\",129,56697263686F77204B6C696E696B756D2053742E20333100",
74 "+CPBR: @i, @p, @I, @e", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
);
75 gammu_test_result(error
, "+CPBR: @i, @p, @I, @e");
77 Priv
->Charset
= AT_CHARSET_UCS2
;
78 Priv
->Manufacturer
= AT_Motorola
;
79 error
= ATGEN_ParseReply(s
,
80 "+CPBR: 212,\"mlaubner@web.de\",128,004D0061006E00660072006500640020004C006100750062006E00650072",
81 "+CPBR: @i, @p, @I, @s", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
);
82 gammu_test_result(error
, "+CPBR: @i, @p, @I, @s");
84 Priv
->Charset
= AT_CHARSET_UCS2
;
85 Priv
->Manufacturer
= AT_Motorola
;
86 error
= ATGEN_ParseReply(s
, "+CPBR: 1,\"+33616918685\",145,\"68506C6970696570\"", "+CPBR: @i, @p, @I, @s", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
);
87 gammu_test_result(error
, "+CPBR: @i, @p, @I, @s");
89 Priv
->Charset
= AT_CHARSET_HEX
;
90 Priv
->Manufacturer
= AT_Motorola
;
91 error
= ATGEN_ParseReply(s
, "+CSCA: 002B003300380030003600330039003000310030003000300030,145", "+CSCA: @p, @i", buffer
, BUFFER_SIZE
, &i
);
92 gammu_test_result(error
, "+CSCA: @p, @i");
94 Priv
->Charset
= AT_CHARSET_GSM
;
95 Priv
->Manufacturer
= AT_Motorola
;
96 error
= ATGEN_ParseReply(s
, "+CPBR: (1-250),50,14,,,,40,20", "+CPBR: (@i-@i), @i, @i, @0", &i
, &i
, &i
, &i
);
97 gammu_test_result(error
, "+CPBR: (@i-@i), @i, @i, @0");
99 error
= ATGEN_ParseReply(s
, "+CMGL:1,0,,26", "+CMGL: @i, @r, @p, @0", &i
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
);
100 gammu_test_result(error
, "+CMGL: @i, @r, @p, @0");
102 Priv
->Charset
= AT_CHARSET_GSM
;
103 Priv
->Manufacturer
= AT_Motorola
;
104 error
= ATGEN_ParseReply(s
,
105 "+SPBR: 10,\"12345\",\"\",\"\",\"\",\"\",\"\",\"5,test1\",\"0,\",\"0,\",\"0,\"",
106 "+SPBR: @i, @p, @p, @p, @p, @p, @s, @t, @t, @t, @t",
111 buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
);
112 gammu_test_result(error
, "+SPBR: @i, @p, @p, @p, @p, @p, @s, @t, @t, @t, @t");
114 error
= ATGEN_ParseReply(s
,
115 "+SPBR: 2,\"+79217962807\",\"+78125313912\",\"\",\"\",\"\",\"\",\"16,Абакумов\",\"18,Александр\",\"0,\",\"0,\"",
116 "+SPBR: @i, @p, @p, @p, @p, @p, @s, @T, @T, @T, @T",
121 buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
, buffer
, BUFFER_SIZE
);
122 gammu_test_result(error
, "+SPBR: @i, @p, @p, @p, @p, @p, @s, @T, @T, @T, @T");
124 Priv
->Charset
= AT_CHARSET_UCS2
;
125 Priv
->Manufacturer
= AT_Motorola
;
127 error
= ATGEN_ParseReply(s
,
128 "+MPBR: 253,\"069912158732\",129,005700650067006C006500690074006E0065007200200053006100620069006E00650020004D0065006E00730061,3,0,255,0,1,1,255,255,0,,0,0,,,,,,,,\"\",\"\"",
129 "+MPBR: @i, @p, @i, @s, @i, @0", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
, &i
);
130 gammu_test_result(error
, "+MPBR: @i, @p, @i, @s, @i, @0");
132 error
= ATGEN_ParseReply(s
,
133 "+MPBR: 181,\"0800886600\",129,004400440055006600440055006600770044,0,0,255,70,1,1,255,255,0,,0,0,,,,,,,,\"\",\"\"",
134 "+MPBR: @i, @p, @i, @s, @i, @0", &i
, buffer
, BUFFER_SIZE
, &i
, buffer
, BUFFER_SIZE
, &i
);
135 gammu_test_result(error
, "+MPBR: @i, @p, @i, @s, @i, @0");
137 error
= ATGEN_ParseReply(s
, "+CPIN: SIM PIN", "+CPIN: @r", buffer
, BUFFER_SIZE
);
138 gammu_test_result(error
, "+CPIN: @s");
140 Priv
->Charset
= AT_CHARSET_GSM
;
141 error
= ATGEN_ParseReply(s
,
142 "\"Lieber Kunde! Sie telefonieren innerhalb der EU aktiv um \ee 0.52; passiv um \ee 0.23; SMS \ee 0.13. Roaminginfo +43680680627, Euro Notruf 12. Ihr bob Team\"",
143 "@s", buffer
, BUFFER_SIZE
);
144 gammu_test_result(error
, "@s");
146 Priv
->Charset
= AT_CHARSET_HEX
;
147 error
= ATGEN_ParseReply(s
, "+CSCA: \"971555515515\",145",
148 "+CSCA: @p, @i", buffer
, BUFFER_SIZE
, &i
);
149 gammu_test_result(error
, "+CSCA: @p, @i");
150 test_result((strcmp(DecodeUnicodeString(buffer
), "971555515515") == 0));
151 error
= ATGEN_ParseReply(s
, "+CSCA: \"393731353535353135353135\",145",
152 "+CSCA: @p, @i", buffer
, BUFFER_SIZE
, &i
);
153 gammu_test_result(error
, "+CSCA: @p, @i");
154 test_result((strcmp(DecodeUnicodeString(buffer
), "971555515515") == 0));
155 error
= ATGEN_ParseReply(s
, "+CSCA: \"+971555515515\",145",
156 "+CSCA: @p, @i", buffer
, BUFFER_SIZE
, &i
);
157 gammu_test_result(error
, "+CSCA: @p, @i");
158 test_result((strcmp(DecodeUnicodeString(buffer
), "+971555515515") == 0));
159 error
= ATGEN_ParseReply(s
, "+CSCA: \"2b393731353535353135353135\",145",
160 "+CSCA: @p, @i", buffer
, BUFFER_SIZE
, &i
);
161 gammu_test_result(error
, "+CSCA: @p, @i");
162 test_result((strcmp(DecodeUnicodeString(buffer
), "+971555515515") == 0));
164 error
= ATGEN_ParseReply(s
,
165 "+SPBR:\"1\",\"Алина\",\"+79164108633\"",
169 buffer
, BUFFER_SIZE
);
170 gammu_test_result(error
, "+SPBR: @ni, @u, @e");
171 test_result((strcmp(DecodeUnicodeString(buffer
), "+79164108633") == 0));
173 Priv
->Charset
= AT_CHARSET_UCS2
;
174 error
= ATGEN_ParseReply(s
,
175 "+CPBR: 2,\"*100#\",129,\"gg get balance\",0",
176 "+CPBR: @i, @p, @I, @e, @i",
182 gammu_test_result(error
, "+CPBR: @i, @p, @I, @e, @i");
183 test_result((strcmp(DecodeUnicodeString(buffer
), "gg get balance") == 0));
185 /* Free state machine */
186 GSM_FreeStateMachine(s
);
191 /* Editor configuration
192 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: