File: errors.c

package info (click to toggle)
eztrace 2.0%2Brepack-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,132 kB
  • sloc: ansic: 23,501; perl: 910; sh: 857; cpp: 771; makefile: 696; fortran: 327; f90: 320; python: 57
file content (46 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (12)
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
/* -*- c-file-style: "GNU" -*- */
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 *
 *
 * errors.c -- test of errors function (errors.h)
 *
 *  Created on: 4 Aug. 2011
 *      Author: Damien Martin-Guillerez <damien.martin-guillerez@inria.fr>
 */

#include <errors.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

int test_pptrace_error_reporting() {
  pptrace_clear_error();
  const char *err = pptrace_get_error();
  if (err != NULL)
    return -__LINE__;

  pptrace_report_error("ERROR");
  err = pptrace_get_error();
  if (err == NULL || strcmp(err, "ERROR"))
    return -__LINE__;

  pptrace_report_error("ERROR %d", 1);
  err = pptrace_get_error();
  if (err == NULL || strcmp(err, "ERROR 1"))
    return -__LINE__;

  pptrace_clear_error();
  malloc(-1); // Force error
  err = pptrace_get_error();
  if (errno) {
    return err != NULL && (strcmp(strerror(errno), err) == 0) ? 0 : -__LINE__;
  }
  return err == NULL ? 0 : -__LINE__;
}

int main() {
  return test_pptrace_error_reporting();
}