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 int main(int argc
, char **argv
)
25 char vcard_buffer
[65536];
28 gboolean generate
= FALSE
;
31 GSM_Debug_Info
*debug_info
;
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: vcard-read file.vcf 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 */
64 error
= GSM_DecodeVCARD(NULL
, buffer
, &pos
, &pbk
, SonyEricsson_VCard21
);
65 gammu_test_result(error
, "GSM_DecodeVCARD");
67 /* Encode vCard back */
69 error
= GSM_EncodeVCARD(NULL
, vcard_buffer
, sizeof(vcard_buffer
), &pos
, &pbk
, TRUE
, SonyEricsson_VCard21
);
70 gammu_test_result(error
, "GSM_EncodeVCARD");
73 * Best would be to compare here, but we never can get
74 * absolutely same as original.
76 printf("ORIGINAL:\n%s\n----\nENCODED:\n%s\n", buffer
, vcard_buffer
);
78 /* Generate file if we should */
80 GSM_ClearBackup(&backup
);
81 strcpy(backup
.Creator
, "vCard tester");
83 backup
.PhonePhonebook
[0] = &pbk
;
84 backup
.PhonePhonebook
[1] = NULL
;
85 error
= GSM_SaveBackupFile(argv
[2], &backup
, TRUE
);
86 gammu_test_result(error
, "GSM_SaveBackupFile");
89 /* Read file content */
90 GSM_ClearBackup(&backup
);
91 error
= GSM_ReadBackupFile(argv
[2], &backup
, GSM_Backup_GammuUCS2
);
92 gammu_test_result(error
, "GSM_ReadBackupFile");
95 test_result(pbk
.EntriesNum
== backup
.PhonePhonebook
[0]->EntriesNum
);
98 for (i
= 0; i
< pbk
.EntriesNum
; i
++) {
99 test_result(pbk
.Entries
[i
].EntryType
== backup
.PhonePhonebook
[0]->Entries
[i
].EntryType
);
100 printf("Entry type: %d\n", pbk
.Entries
[i
].EntryType
);
101 switch (pbk
.Entries
[i
].EntryType
) {
102 case PBK_Number_General
:
103 case PBK_Number_Mobile
:
105 case PBK_Number_Pager
:
106 case PBK_Number_Other
:
107 case PBK_Number_Messaging
:
108 case PBK_Number_Video
:
110 case PBK_Text_Postal
:
112 case PBK_Text_Email2
:
116 case PBK_Text_LastName
:
117 case PBK_Text_FirstName
:
118 case PBK_Text_SecondName
:
119 case PBK_Text_FormalName
:
120 case PBK_Text_NamePrefix
:
121 case PBK_Text_NameSuffix
:
122 case PBK_Text_NickName
:
123 case PBK_Text_Company
:
124 case PBK_Text_JobTitle
:
125 case PBK_Text_StreetAddress
:
129 case PBK_Text_Country
:
130 case PBK_Text_Custom1
:
131 case PBK_Text_Custom2
:
132 case PBK_Text_Custom3
:
133 case PBK_Text_Custom4
:
134 case PBK_Text_UserID
:
135 case PBK_Text_PictureName
:
136 case PBK_PushToTalkID
:
142 test_result(mywstrncmp(pbk
.Entries
[i
].Text
, backup
.PhonePhonebook
[0]->Entries
[i
].Text
, 0) == TRUE
);
145 test_result((pbk
.Entries
[i
].Picture
.Length
==
146 backup
.PhonePhonebook
[0]->Entries
[i
].Picture
.Length
) &&
147 memcmp(pbk
.Entries
[i
].Picture
.Buffer
, backup
.PhonePhonebook
[0]->Entries
[i
].Picture
.Buffer
, pbk
.Entries
[i
].Picture
.Length
) == 0);
148 free(pbk
.Entries
[i
].Picture
.Buffer
);
151 case PBK_LastModified
:
158 case PBK_Caller_Group
:
159 test_result(pbk
.Entries
[i
].Number
== backup
.PhonePhonebook
[0]->Entries
[i
].Number
);
164 error
= PrintMemoryEntry(&pbk
, NULL
);
165 gammu_test_result(error
, "PrintMemoryEntry");
168 GSM_FreeBackup(&backup
);
174 /* Editor configuration
175 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: