Translation update done using Pootle.
[gammu.git] / tests / obex-vcard-split.c
blob76d601aa1b6312c0f2eb7a6aebf5465bec64b7de
1 /* Test for vcard LUID and index parsing of OBEX driver */
3 #include <gammu.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <unistd.h>
10 #include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
11 #include "../libgammu/gsmstate.h" /* Needed for state machine internals */
12 #include "../libgammu/gsmphones.h" /* Phone data */
14 #include "common.h"
16 extern GSM_Error OBEXGEN_InitLUID(GSM_StateMachine *s, const char *Name,
17 const gboolean Recalculate,
18 const char *Header,
19 char **Data, int **Offsets, int *Count,
20 char ***LUIDStorage, int *LUIDCount,
21 int **IndexStorage, int *IndexCount);
23 int main(int argc, char **argv)
25 GSM_Debug_Info *debug_info;
26 char *buffer;
27 struct stat sb;
28 FILE *f;
29 size_t len;
30 GSM_StateMachine *s;
31 GSM_Error error;
32 int *Offsets;
33 int Count;
34 char **LUIDStorage;
35 int LUIDCount;
36 int *IndexStorage;
37 int IndexCount;
39 /* Check parameters */
40 if (argc != 3) {
41 printf("Not enough parameters!\nUsage: obex-vcard-split data num-entries\n");
42 return 1;
45 if (stat(argv[1], &sb) != 0) {
46 printf("Could not stat %s\n", argv[1]);
47 return 1;
50 buffer = malloc(sb.st_size + 1);
51 if (buffer == NULL) {
52 printf("Failed to malloc %ld bytes\n", (long)sb.st_size);
53 return 1;
56 /* Open file */
57 f = fopen(argv[1], "r");
58 if (f == NULL) {
59 printf("Could not open %s\n", argv[1]);
60 return 1;
63 /* Read data */
64 len = fread(buffer, 1, sb.st_size + 1, f);
65 if (!feof(f)) {
66 printf("Could not read whole file %s\n", argv[1]);
67 fclose(f);
68 return 1;
70 /* Zero terminate data */
71 buffer[len] = 0;
73 /* Close file */
74 fclose(f);
76 /* Configure state machine */
77 debug_info = GSM_GetGlobalDebug();
78 GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
79 GSM_SetDebugLevel("textall", debug_info);
81 /* Allocates state machine */
82 s = GSM_AllocStateMachine();
83 test_result(s != NULL);
84 debug_info = GSM_GetDebug(s);
85 GSM_SetDebugGlobal(TRUE, debug_info);
87 /* Parse data */
88 error = OBEXGEN_InitLUID(s, "", TRUE, "BEGIN:VCARD", &buffer, &Offsets, &Count, &LUIDStorage, &LUIDCount, &IndexStorage, &IndexCount);
90 /* Free state machine */
91 GSM_FreeStateMachine(s);
93 free(buffer);
95 gammu_test_result(error, "OBEXGEN_InitLUID");
96 test_result(atoi(argv[2]) == Count);
98 return 0;
101 /* Editor configuration
102 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: