File: tst-parse-error.c

package info (click to toggle)
libeconf 0.7.7%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,636 kB
  • sloc: ansic: 7,440; python: 1,204; cs: 651; sh: 214; xml: 182; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 2,853 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#include <stdio.h>
#include <string.h>

#include "libeconf.h"

/* Test case:
   Reporting parsing errors.
*/

int
main(void)
{
  econf_file *key_file = NULL;
  econf_err error;
  char *filename = NULL;
  uint64_t line_nr = 0;

  error = econf_readDirs (&key_file,
			  TESTSDIR"tst-parse-error/usr/etc",
			  TESTSDIR"tst-parse-error/etc",
			  "missing_bracket", "conf", "=", "#");
  econf_free (key_file);
  key_file = NULL;

  if (error != ECONF_MISSING_BRACKET)
  {
    fprintf (stderr, "wrong return value for missing brackets: %s\n",
	     econf_errString(error));
    return 1;
  }
  econf_errLocation( &filename, &line_nr);
  if (strcmp(filename,TESTSDIR"tst-parse-error/etc/missing_bracket.conf.d/missing_bracket.conf")!=0 || line_nr != 4)
  {
    fprintf (stderr, "wrong error info for parsing a text with missing bracket: %s: %d\n", filename, (int) line_nr);
    free(filename);
    return 1;
  }
  free(filename);

  error = econf_readFile(&key_file, TESTSDIR"tst-parse-error/missing_delim.conf", "=", "#");
  econf_free (key_file);
  if (error != ECONF_MISSING_DELIMITER)
  {
    fprintf (stderr, "wrong return value for missing delimiters: %s\n",
	     econf_errString(error));
    return 1;
  }
  econf_errLocation( &filename, &line_nr);
  if (strcmp(filename,TESTSDIR"tst-parse-error/missing_delim.conf")!=0 || line_nr != 3)
  {
    fprintf (stderr, "wrong error info for parsing a text with missing delimiters: %s: %d\n", filename, (int) line_nr);
    free(filename);
    return 1;
  }
  free(filename);

  error = econf_readFile(&key_file, TESTSDIR"tst-parse-error/empty_section.conf", "=", "#");
  econf_free (key_file);
  if (error != ECONF_EMPTY_SECTION_NAME)
  {
    fprintf (stderr, "wrong return value for empty section names: %s\n",
	     econf_errString(error));
    return 1;
  }
  econf_errLocation( &filename, &line_nr);
  if (strcmp(filename,TESTSDIR"tst-parse-error/empty_section.conf")!=0 || line_nr != 4)
  {
    fprintf (stderr, "wrong error info for parsing a text after an empty section: %s: %d\n", filename, (int) line_nr);
    free(filename);
    return 1;
  }
  free(filename);

  error = econf_readFile(&key_file, TESTSDIR"tst-parse-error/text_after_section.conf", "=", "#");
  econf_free (key_file);
  if (error != ECONF_TEXT_AFTER_SECTION)
  {
    fprintf (stderr, "wrong return value for parsing a text after a section: %s\n",
	     econf_errString(error));
    return 1;
  }
  econf_errLocation( &filename, &line_nr);
  if (strcmp(filename,TESTSDIR"tst-parse-error/text_after_section.conf")!=0 || line_nr != 4)
  {
    fprintf (stderr, "wrong error info for parsing a text after a section: %s: %d\n", filename, (int) line_nr);
    free(filename);
    return 1;
  }
  free(filename);

  return 0;
}