Translation update done using Pootle.
[gammu.git] / tests / smsbackup.c
bloba9944d2b30a71ef38bcbc793c269c21f0f2e3d8e
1 /**
2 * SMS backup testing program.
3 */
5 #include <gammu.h>
6 #include <stdlib.h>
7 #include <stdio.h>
9 #include "../helper/message-display.h"
11 #include "common.h"
13 int main(int argc UNUSED, char **argv UNUSED)
15 GSM_Debug_Info *debug_info;
16 GSM_Error error;
17 GSM_SMS_Backup Backup;
18 GSM_MultiSMSMessage **SortedSMS, **InputSMS;
19 int i, count;
21 /* Check parameters */
22 if (argc != 2) {
23 printf("Not enough parameters!\nUsage: smsbackup file.smsbackup\n");
24 return 1;
27 debug_info = GSM_GetGlobalDebug();
28 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
29 GSM_SetDebugLevel("textall", debug_info);
31 /* Read the backup */
32 error = GSM_ReadSMSBackupFile(argv[1], &Backup);
33 gammu_test_result(error, "GSM_ReadSMSBackupFile");
35 /* Calculate number of messages */
36 count = 0;
37 while (Backup.SMS[count] != NULL) {
38 count++;
41 /* Allocate memory for sorted ones */
42 SortedSMS = (GSM_MultiSMSMessage **) malloc((count + 1) * sizeof(GSM_MultiSMSMessage *));
43 InputSMS = (GSM_MultiSMSMessage **) malloc((count + 1) * sizeof(GSM_MultiSMSMessage *));
45 /* Copy messages to multi message buffers */
46 for (i = 0; i < count; i++) {
47 InputSMS[i] = (GSM_MultiSMSMessage *) malloc(sizeof(GSM_MultiSMSMessage));
48 InputSMS[i]->Number = 1;
49 InputSMS[i]->SMS[0] = *Backup.SMS[i];
51 InputSMS[i] = NULL;
53 /* Sort linked messages */
54 error = GSM_LinkSMS(debug_info, InputSMS, SortedSMS, TRUE);
55 gammu_test_result(error, "GSM_LinkSMS");
57 /* Free memory */
58 for (i = 0; i < count; i++) {
59 free(InputSMS[i]);
62 /* Display messages */
63 for (i = 0; SortedSMS[i] != NULL; i++) {
64 DisplayMultiSMSInfo(SortedSMS[i], TRUE, TRUE, NULL, NULL);
65 free(SortedSMS[i]);
68 /* We don't need this anymore */
69 GSM_FreeSMSBackup(&Backup);
70 free(InputSMS);
71 free(SortedSMS);
73 return 0;
76 /* Editor configuration
77 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: