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
15 #include "../helper/memory-display.h"
19 char buffer
[65536000];
20 char vcard_buffer
[65536000];
22 int main(int argc
, char **argv
)
29 gboolean generate
= FALSE
;
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");
45 /* Check for generating option */
46 if (argc
== 4 && strcmp(argv
[3], "generate") == 0) {
51 f
= fopen(argv
[1], "r");
52 test_result(f
!= NULL
);
55 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
58 /* Zero terminate string */
61 /* We don't need file any more */
65 error
= GSM_DecodeVCARD(NULL
, buffer
, &pos
, &pbk
, SonyEricsson_VCard21
);
66 gammu_test_result(error
, "GSM_DecodeVCARD");
68 /* Encode vCard back */
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 */
81 GSM_ClearBackup(&backup
);
82 strcpy(backup
.Creator
, "vCard tester");
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");
96 test_result(pbk
.EntriesNum
== backup
.PhonePhonebook
[0]->EntriesNum
);
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
:
106 case PBK_Number_Pager
:
107 case PBK_Number_Other
:
108 case PBK_Number_Messaging
:
109 case PBK_Number_Video
:
111 case PBK_Text_Postal
:
113 case PBK_Text_Email2
:
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
:
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
:
143 test_result(mywstrncmp(pbk
.Entries
[i
].Text
, backup
.PhonePhonebook
[0]->Entries
[i
].Text
, 0) == TRUE
);
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
);
152 case PBK_LastModified
:
159 case PBK_Caller_Group
:
160 test_result(pbk
.Entries
[i
].Number
== backup
.PhonePhonebook
[0]->Entries
[i
].Number
);
165 error
= PrintMemoryEntry(&pbk
, NULL
);
166 gammu_test_result(error
, "PrintMemoryEntry");
169 GSM_FreeBackup(&backup
);
175 /* Editor configuration
176 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: