2 * [iv]Calendar parser testing.
4 * First parameter is location of [iv]Calendar, second location of Gammu backup
5 * how it should be parsed.
7 * Optional third parameter can be used to generate template backup
17 int main(int argc
, char **argv
)
21 GSM_CalendarEntry cal
;
26 gboolean generate
= FALSE
;
29 GSM_Debug_Info
*debug_info
;
30 gboolean skipcal
, skiptodo
;
31 gboolean check_map
[MAX(GSM_CALENDAR_ENTRIES
, GSM_TODO_ENTRIES
)];
33 /* Configure debugging */
34 debug_info
= GSM_GetGlobalDebug();
35 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
36 GSM_SetDebugLevel("textall", debug_info
);
38 /* Check parameters */
39 if (argc
!= 3 && argc
!= 4) {
40 printf("Not enough parameters!\nUsage: cal-read file.[vi]cs file.backup\n");
44 /* Check for generating option */
45 if (argc
== 4 && strcmp(argv
[3], "generate") == 0) {
50 f
= fopen(argv
[1], "r");
51 test_result(f
!= NULL
);
54 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
57 /* Zero terminate string */
60 /* We don't need file any more */
68 /* Parse [iv]Calendar */
69 if (strstr(argv
[1], ".ics") != NULL
) {
70 error
= GSM_DecodeVCALENDAR_VTODO(NULL
, buffer
, &pos
, &cal
, &todo
, Mozilla_iCalendar
, Mozilla_VToDo
);
72 error
= GSM_DecodeVCALENDAR_VTODO(NULL
, buffer
, &pos
, &cal
, &todo
, SonyEricsson_VCalendar
, SonyEricsson_VToDo
);
74 gammu_test_result(error
, "GSM_DecodeVCALENDAR_VTODO");
76 /* Generate file if we should */
78 GSM_ClearBackup(&backup
);
79 strcpy(backup
.Creator
, "[iv]Calendar tester");
80 if (cal
.EntriesNum
!= 0) {
81 backup
.Calendar
[0] = &cal
;
82 backup
.Calendar
[1] = NULL
;
84 backup
.Calendar
[0] = NULL
;
86 if (todo
.EntriesNum
!= 0) {
87 backup
.ToDo
[0] = &todo
;
88 backup
.ToDo
[1] = NULL
;
90 backup
.ToDo
[0] = NULL
;
92 error
= GSM_SaveBackupFile(argv
[2], &backup
, TRUE
);
93 gammu_test_result(error
, "GSM_SaveBackupFile");
96 /* Read file content */
97 GSM_ClearBackup(&backup
);
98 error
= GSM_ReadBackupFile(argv
[2], &backup
, GSM_Backup_GammuUCS2
);
99 gammu_test_result(error
, "GSM_ReadBackupFile");
101 /* Did we read something? */
103 if (cal
.EntriesNum
== 0 && backup
.Calendar
[0] == NULL
) {
107 if (todo
.EntriesNum
== 0 && backup
.ToDo
[0] == NULL
) {
112 if (!skipcal
&& cal
.EntriesNum
!= backup
.Calendar
[0]->EntriesNum
) {
113 printf("Different number of entries!\n");
116 if (!skiptodo
&& todo
.EntriesNum
!= backup
.ToDo
[0]->EntriesNum
) {
117 printf("Different number of entries!\n");
121 for (i
= 0; i
< (int)(sizeof(check_map
) / sizeof(gboolean
)); i
++) {
122 check_map
[i
] = FALSE
;
125 /* Compare content */
127 for (i
= 0; i
< cal
.EntriesNum
; i
++) {
128 printf("field:%d\nn", cal
.Entries
[i
].EntryType
);
129 for (j
= 0; j
< backup
.Calendar
[0]->EntriesNum
; j
++) {
130 if (check_map
[j
] == FALSE
&& cal
.Entries
[i
].EntryType
== backup
.Calendar
[0]->Entries
[j
].EntryType
) {
135 test_result(j
< backup
.Calendar
[0]->EntriesNum
);
136 test_result(cal
.Entries
[i
].EntryType
== backup
.Calendar
[0]->Entries
[j
].EntryType
);
137 switch (cal
.Entries
[i
].EntryType
) {
139 case CAL_DESCRIPTION
:
143 if (!mywstrncmp(cal
.Entries
[i
].Text
, backup
.Calendar
[0]->Entries
[j
].Text
, 0)) {
144 printf("Calendar field %d is not the same!\n", i
);
145 printf("vc: '%s'\n", DecodeUnicodeConsole(cal
.Entries
[i
].Text
));
146 printf("bak: '%s'\n", DecodeUnicodeConsole(backup
.Calendar
[0]->Entries
[j
].Text
));
150 case CAL_START_DATETIME
:
151 case CAL_END_DATETIME
:
152 case CAL_TONE_ALARM_DATETIME
:
153 case CAL_SILENT_ALARM_DATETIME
:
156 case CAL_REPEAT_DAYOFWEEK
:
158 case CAL_REPEAT_DAYOFYEAR
:
159 case CAL_REPEAT_WEEKOFMONTH
:
160 case CAL_REPEAT_MONTH
:
161 case CAL_REPEAT_FREQUENCY
:
162 case CAL_REPEAT_STARTDATE
:
163 case CAL_REPEAT_STOPDATE
:
164 case CAL_REPEAT_COUNT
:
165 case CAL_LAST_MODIFIED
:
171 for (i
= 0; i
< todo
.EntriesNum
; i
++) {
172 printf("%d,%d\n", todo
.Entries
[i
].EntryType
, backup
.ToDo
[0]->Entries
[i
].EntryType
);
173 switch (todo
.Entries
[i
].EntryType
) {
175 case TODO_DESCRIPTION
:
179 if (!mywstrncmp(todo
.Entries
[i
].Text
, backup
.ToDo
[0]->Entries
[i
].Text
, 0)) {
180 printf("Todo field %d is not the same!\n", i
);
184 case TODO_END_DATETIME
:
185 case TODO_START_DATETIME
:
186 case TODO_COMPLETED_DATETIME
:
187 case TODO_ALARM_DATETIME
:
188 case TODO_SILENT_ALARM_DATETIME
:
193 case TODO_LAST_MODIFIED
:
200 GSM_FreeBackup(&backup
);
206 /* Editor configuration
207 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: