Translation update done using Pootle.
[gammu.git] / tests / vcard-read.c
blob27d5cfb170097b73b2184c4831bcc2a9c70f3a1f
1 /**
2 * vCard parser testing.
4 * First parameter is location of vCard, 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 char buffer[65536000];
20 char vcard_buffer[65536000];
22 int main(int argc, char **argv)
24 size_t pos = 0;
25 GSM_MemoryEntry pbk;
26 GSM_Error error;
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: vcard-read file.vcf 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 vCard */
65 error = GSM_DecodeVCARD(NULL, buffer, &pos, &pbk, SonyEricsson_VCard21);
66 gammu_test_result(error, "GSM_DecodeVCARD");
68 /* Encode vCard back */
69 pos = 0;
70 error = GSM_EncodeVCARD(NULL, vcard_buffer, sizeof(vcard_buffer), &pos, &pbk, TRUE, SonyEricsson_VCard21);
71 gammu_test_result(error, "GSM_EncodeVCARD");
74 * Best would be to compare here, but we never can get
75 * absolutely same as original.
77 printf("ORIGINAL:\n%s\n----\nENCODED:\n%s\n", buffer, vcard_buffer);
79 /* Generate file if we should */
80 if (generate) {
81 GSM_ClearBackup(&backup);
82 strcpy(backup.Creator, "vCard tester");
83 pbk.Location = 0;
84 backup.PhonePhonebook[0] = &pbk;
85 backup.PhonePhonebook[1] = NULL;
86 error = GSM_SaveBackupFile(argv[2], &backup, TRUE);
87 gammu_test_result(error, "GSM_SaveBackupFile");
90 /* Read file content */
91 GSM_ClearBackup(&backup);
92 error = GSM_ReadBackupFile(argv[2], &backup, GSM_Backup_GammuUCS2);
93 gammu_test_result(error, "GSM_ReadBackupFile");
95 /* Compare size */
96 test_result(pbk.EntriesNum == backup.PhonePhonebook[0]->EntriesNum);
98 /* Compare content */
99 for (i = 0; i < pbk.EntriesNum; i++) {
100 test_result(pbk.Entries[i].EntryType == backup.PhonePhonebook[0]->Entries[i].EntryType);
101 printf("Entry type: %d\n", pbk.Entries[i].EntryType);
102 switch (pbk.Entries[i].EntryType) {
103 case PBK_Number_General:
104 case PBK_Number_Mobile:
105 case PBK_Number_Fax:
106 case PBK_Number_Pager:
107 case PBK_Number_Other:
108 case PBK_Number_Messaging:
109 case PBK_Number_Video:
110 case PBK_Text_Note:
111 case PBK_Text_Postal:
112 case PBK_Text_Email:
113 case PBK_Text_Email2:
114 case PBK_Text_URL:
115 case PBK_Text_LUID:
116 case PBK_Text_Name:
117 case PBK_Text_LastName:
118 case PBK_Text_FirstName:
119 case PBK_Text_SecondName:
120 case PBK_Text_FormalName:
121 case PBK_Text_NamePrefix:
122 case PBK_Text_NameSuffix:
123 case PBK_Text_NickName:
124 case PBK_Text_Company:
125 case PBK_Text_JobTitle:
126 case PBK_Text_StreetAddress:
127 case PBK_Text_City:
128 case PBK_Text_State:
129 case PBK_Text_Zip:
130 case PBK_Text_Country:
131 case PBK_Text_Custom1:
132 case PBK_Text_Custom2:
133 case PBK_Text_Custom3:
134 case PBK_Text_Custom4:
135 case PBK_Text_UserID:
136 case PBK_Text_PictureName:
137 case PBK_PushToTalkID:
138 case PBK_Text_VOIP:
139 case PBK_Text_SWIS:
140 case PBK_Text_WVID:
141 case PBK_Text_SIP:
142 case PBK_Text_DTMF:
143 test_result(mywstrncmp(pbk.Entries[i].Text, backup.PhonePhonebook[0]->Entries[i].Text, 0) == TRUE);
144 break;
145 case PBK_Photo:
146 test_result((pbk.Entries[i].Picture.Length ==
147 backup.PhonePhonebook[0]->Entries[i].Picture.Length) &&
148 memcmp(pbk.Entries[i].Picture.Buffer, backup.PhonePhonebook[0]->Entries[i].Picture.Buffer, pbk.Entries[i].Picture.Length) == 0);
149 free(pbk.Entries[i].Picture.Buffer);
150 break;
151 case PBK_Date:
152 case PBK_LastModified:
153 break;
154 case PBK_Category:
155 case PBK_Private:
156 case PBK_RingtoneID:
157 case PBK_PictureID:
158 case PBK_CallLength:
159 case PBK_Caller_Group:
160 test_result(pbk.Entries[i].Number == backup.PhonePhonebook[0]->Entries[i].Number);
161 break;
165 error = PrintMemoryEntry(&pbk, NULL);
166 gammu_test_result(error, "PrintMemoryEntry");
168 /* Free data */
169 GSM_FreeBackup(&backup);
171 /* We're done */
172 return 0;
175 /* Editor configuration
176 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: