Translation update done using Pootle.
[gammu.git] / tests / ldif-read.c
blobdc2d3442f3af08128423d00b79d2358d3d46ff9a
1 /**
2 * LDIF parser testing.
4 * First parameter is location of LDIF, second location of Gammu backup
5 * how it should be parsed.
7 * Optional third parameter can be used to generate template backup
8 * file.
9 */
10 #include <gammu.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
15 #include "../helper/memory-display.h"
17 #include "common.h"
19 #include "../libgammu/service/backup/backldif.h"
21 int main(int argc, char **argv)
23 size_t pos = 0;
24 GSM_MemoryEntry pbk;
25 GSM_Error error;
26 char buffer[65536];
27 FILE *f;
28 size_t len;
29 gboolean generate = FALSE;
30 GSM_Backup backup;
31 int i;
32 GSM_Debug_Info *debug_info;
34 /* Configure debugging */
35 debug_info = GSM_GetGlobalDebug();
36 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
37 GSM_SetDebugLevel("textall", debug_info);
39 /* Check parameters */
40 if (argc != 3 && argc != 4) {
41 printf("Not enough parameters!\nUsage: ldif-read file.ldif file.backup\n");
42 return 1;
45 /* Check for generating option */
46 if (argc == 4 && strcmp(argv[3], "generate") == 0) {
47 generate = TRUE;
50 /* Open file */
51 f = fopen(argv[1], "r");
52 test_result(f != NULL);
54 /* Read data */
55 len = fread(buffer, 1, sizeof(buffer) - 1, f);
56 test_result(feof(f));
58 /* Zero terminate string */
59 buffer[len] = 0;
61 /* We don't need file any more */
62 fclose(f);
64 /* Parse LDIF */
65 error = GSM_DecodeLDIFEntry(buffer, &pos, &pbk);
66 gammu_test_result(error, "GSM_DecodeLDIFEntry");
68 /* Generate file if we should */
69 if (generate) {
70 GSM_ClearBackup(&backup);
71 strcpy(backup.Creator, "LDIF tester");
72 pbk.Location = 0;
73 backup.PhonePhonebook[0] = &pbk;
74 backup.PhonePhonebook[1] = NULL;
75 error = GSM_SaveBackupFile(argv[2], &backup, TRUE);
76 gammu_test_result(error, "GSM_SaveBackupFile");
79 /* Read file content */
80 GSM_ClearBackup(&backup);
81 error = GSM_ReadBackupFile(argv[2], &backup, GSM_Backup_GammuUCS2);
82 gammu_test_result(error, "GSM_ReadBackupFile");
84 /* Compare size */
85 test_result(pbk.EntriesNum == backup.PhonePhonebook[0]->EntriesNum);
87 /* Compare content */
88 for (i = 0; i < pbk.EntriesNum; i++) {
89 test_result(pbk.Entries[i].EntryType == backup.PhonePhonebook[0]->Entries[i].EntryType);
90 printf("Entry type: %d\n", pbk.Entries[i].EntryType);
91 switch (pbk.Entries[i].EntryType) {
92 case PBK_Number_General:
93 case PBK_Number_Mobile:
94 case PBK_Number_Fax:
95 case PBK_Number_Pager:
96 case PBK_Number_Other:
97 case PBK_Number_Messaging:
98 case PBK_Number_Video:
99 case PBK_Text_Note:
100 case PBK_Text_Postal:
101 case PBK_Text_Email:
102 case PBK_Text_Email2:
103 case PBK_Text_URL:
104 case PBK_Text_LUID:
105 case PBK_Text_Name:
106 case PBK_Text_LastName:
107 case PBK_Text_FirstName:
108 case PBK_Text_SecondName:
109 case PBK_Text_FormalName:
110 case PBK_Text_NamePrefix:
111 case PBK_Text_NameSuffix:
112 case PBK_Text_NickName:
113 case PBK_Text_Company:
114 case PBK_Text_JobTitle:
115 case PBK_Text_StreetAddress:
116 case PBK_Text_City:
117 case PBK_Text_State:
118 case PBK_Text_Zip:
119 case PBK_Text_Country:
120 case PBK_Text_Custom1:
121 case PBK_Text_Custom2:
122 case PBK_Text_Custom3:
123 case PBK_Text_Custom4:
124 case PBK_Text_UserID:
125 case PBK_Text_PictureName:
126 case PBK_PushToTalkID:
127 case PBK_Text_VOIP:
128 case PBK_Text_SWIS:
129 case PBK_Text_WVID:
130 case PBK_Text_SIP:
131 case PBK_Text_DTMF:
132 test_result(mywstrncmp(pbk.Entries[i].Text, backup.PhonePhonebook[0]->Entries[i].Text, 0) == TRUE);
133 break;
134 case PBK_Photo:
135 test_result((pbk.Entries[i].Picture.Length ==
136 backup.PhonePhonebook[0]->Entries[i].Picture.Length) &&
137 memcmp(pbk.Entries[i].Picture.Buffer, backup.PhonePhonebook[0]->Entries[i].Picture.Buffer, pbk.Entries[i].Picture.Length) == 0);
138 free(pbk.Entries[i].Picture.Buffer);
139 break;
140 case PBK_Date:
141 case PBK_LastModified:
142 break;
143 case PBK_Category:
144 case PBK_Private:
145 case PBK_RingtoneID:
146 case PBK_PictureID:
147 case PBK_CallLength:
148 case PBK_Caller_Group:
149 test_result(pbk.Entries[i].Number == backup.PhonePhonebook[0]->Entries[i].Number);
150 break;
154 error = PrintMemoryEntry(&pbk, NULL);
155 gammu_test_result(error, "PrintMemoryEntry");
157 /* Free data */
158 GSM_FreeBackup(&backup);
160 /* We're done */
161 return 0;
164 /* Editor configuration
165 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: