Translation update done using Pootle.
[gammu.git] / tests / at-charset.c
blob36d61c61288fe1b623535aa1e240e65138f00eb3
1 /* Test for decoding SMS on 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 #define BUFFER_SIZE ((size_t)16384)
15 unsigned char latin1text[] =
16 { 0x00, 0xed, 0x00, 0xed, 0x00, 0xed, 0x00, 0xe1, 0x00, 0xe1, 0x00, 0xe1, 0x00, 0xe1, 0x00, 0xe1, 0x00, 0xe9, 0x00, 0xe9, 0x00, 0xe9, 0x00, 0xe9, 0x00, 0xe9, 0x00, 0x00 };
17 unsigned char latin1ucs[] = "00ED00ED00ED00E100E100E100E100E100E900E900E900E900E9";
18 char latin1utf8[] = "íííáááááééééé";
20 unsigned char latin2text[] =
21 { 0x00, 0xed, 0x01, 0x1b, 0x00, 0xe1, 0x01, 0x61, 0x00, 0xfd, 0x01, 0x59, 0x01, 0x0d, 0x00, 0xfd, 0x00, 0xed, 0x01, 0x0d, 0x01, 0x59, 0x01, 0x1b, 0x00, 0x00 };
22 unsigned char latin2ucs[] = "00ED011B00E1016100FD0159010D00FD00ED010D0159011B";
23 char latin2utf8[] = "íěášýřčýíčřě";
25 #ifdef ICONV_FOUND
26 char latin1cp437[] = { 0xa1, 0xa1, 0xa1, 0xa0, 0xa0, 0xa0, 0xa0, 0xa0, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00 };
27 char latin1iso88591[] = { 0xed, 0xed, 0xed, 0xe1, 0xe1, 0xe1, 0xe1, 0xe1, 0xe9, 0xe9, 0xe9, 0xe9, 0xe9, 0x00 };
28 char latin2iso88592[] = { 0xed, 0xec, 0xe1, 0xb9, 0xfd, 0xf8, 0xe8, 0xfd, 0xed, 0xe8, 0xf8, 0xec, 0x00 };
29 #endif
31 #define strconv_test_result(expected, current, length) \
32 { \
33 int val;\
34 val = strncmp(expected, current, length); \
35 if (val != 0) {\
36 fprintf(stderr, "Test \"%s\" failed ('%s', '%s')!\n", ""#expected, expected, current); \
37 exit(2); \
38 } \
39 val = strcmp(expected, current); \
40 if (val != 0) {\
41 fprintf(stderr, "Test \"%s\" failed ('%s', '%s')!\n", ""#expected, expected, current); \
42 exit(2); \
43 } \
46 int main(int argc UNUSED, char **argv UNUSED)
48 GSM_Debug_Info *debug_info;
49 GSM_Phone_ATGENData *Priv;
50 GSM_Phone_Data *Data;
51 char buffer[BUFFER_SIZE];
52 unsigned char ubuffer[BUFFER_SIZE * 2];
53 size_t result;
54 GSM_StateMachine *s;
55 GSM_Error error;
57 /* Configure state machine */
58 debug_info = GSM_GetGlobalDebug();
59 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
60 GSM_SetDebugLevel("textall", debug_info);
62 /* Allocates state machine */
63 s = GSM_AllocStateMachine();
64 test_result(s != NULL);
65 debug_info = GSM_GetDebug(s);
66 GSM_SetDebugGlobal(TRUE, debug_info);
68 /* Initialize AT engine */
69 Data = &s->Phone.Data;
70 Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
71 Priv = &s->Phone.Data.Priv.ATGEN;
72 Priv->ReplyState = AT_Reply_OK;
73 Priv->SMSMode = SMS_AT_PDU;
74 Priv->Charset = AT_CHARSET_GSM;
76 /* Perform real tests */
77 Priv->Charset = AT_CHARSET_UTF8;
78 error = ATGEN_EncodeText(s, latin2text, sizeof(latin2text) / 2, buffer, sizeof(buffer), &result);
79 gammu_test_result(error, "Encode - 1");
80 strconv_test_result(latin2utf8, buffer, result);
82 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
83 gammu_test_result(error, "Decode - 1");
84 test_result(mywstrncmp(ubuffer, latin2text, sizeof(latin2text) / 2) == TRUE);
86 Priv->Charset = AT_CHARSET_UTF8;
87 error = ATGEN_EncodeText(s, latin1text, sizeof(latin1text) / 2, buffer, sizeof(buffer), &result);
88 gammu_test_result(error, "Encode - 2");
89 strconv_test_result(latin1utf8, buffer, result);
91 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
92 gammu_test_result(error, "Decode - 2");
93 test_result(mywstrncmp(ubuffer, latin1text, sizeof(latin1text) / 2) == TRUE);
95 #ifdef ICONV_FOUND
96 Priv->Charset = AT_CHARSET_PCCP437;
97 error = ATGEN_EncodeText(s, latin1text, sizeof(latin1text) / 2, buffer, sizeof(buffer), &result);
98 gammu_test_result(error, "Encode - 3");
99 strconv_test_result(latin1cp437, buffer, result);
101 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
102 gammu_test_result(error, "Decode - 3");
103 test_result(mywstrncmp(ubuffer, latin1text, sizeof(latin1text) / 2) == TRUE);
105 Priv->Charset = AT_CHARSET_ISO88591;
106 error = ATGEN_EncodeText(s, latin1text, sizeof(latin1text) / 2, buffer, sizeof(buffer), &result);
107 gammu_test_result(error, "Encode - 4");
108 strconv_test_result(latin1iso88591, buffer, result);
110 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
111 gammu_test_result(error, "Decode - 4");
112 test_result(mywstrncmp(ubuffer, latin1text, sizeof(latin1text) / 2) == TRUE);
114 Priv->Charset = AT_CHARSET_ISO88592;
115 error = ATGEN_EncodeText(s, latin2text, sizeof(latin2text) / 2, buffer, sizeof(buffer), &result);
116 gammu_test_result(error, "Encode - 5");
117 strconv_test_result(latin2iso88592, buffer, result);
119 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
120 gammu_test_result(error, "Decode - 5");
121 test_result(mywstrncmp(ubuffer, latin2text, sizeof(latin2text) / 2) == TRUE);
123 #endif
125 Priv->Charset = AT_CHARSET_UCS2;
126 error = ATGEN_EncodeText(s, latin2text, sizeof(latin2text) / 2, buffer, sizeof(buffer), &result);
127 gammu_test_result(error, "Encode - 6");
128 strconv_test_result(latin2ucs, buffer, result);
130 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
131 gammu_test_result(error, "Decode - 6");
132 test_result(mywstrncmp(ubuffer, latin2text, sizeof(latin2text) / 2) == TRUE);
134 Priv->Charset = AT_CHARSET_UCS2;
135 error = ATGEN_EncodeText(s, latin1text, sizeof(latin1text) / 2, buffer, sizeof(buffer), &result);
136 gammu_test_result(error, "Encode - 7");
137 strconv_test_result(latin1ucs, buffer, result);
139 error = ATGEN_DecodeText(s, buffer, result, ubuffer, sizeof(ubuffer), FALSE, FALSE);
140 gammu_test_result(error, "Decode - 7");
141 test_result(mywstrncmp(ubuffer, latin1text, sizeof(latin1text) / 2) == TRUE);
143 /* Free state machine */
144 GSM_FreeStateMachine(s);
146 return 0;
149 /* Editor configuration
150 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: