propagate from branch 'com.redhat.elfutils.roland.pending' (head 4f8fc821345feef58624...
[platform/upstream/elfutils.git] / tests / msg_tst.c
1 /* Copyright (C) 2002, 2005 Red Hat, Inc.
2    This file is part of Red Hat elfutils.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
5    Red Hat elfutils is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by the
7    Free Software Foundation; version 2 of the License.
8
9    Red Hat elfutils is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License along
15    with Red Hat elfutils; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17
18    Red Hat elfutils is an included package of the Open Invention Network.
19    An included package of the Open Invention Network is a package for which
20    Open Invention Network licensees cross-license their patents.  No patent
21    license is granted, either expressly or impliedly, by designation as an
22    included package.  Should you wish to participate in the Open Invention
23    Network licensing program, please visit www.openinventionnetwork.com
24    <http://www.openinventionnetwork.com>.  */
25
26 #include <config.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include <libelfP.h>
33
34 static struct
35 {
36   int id;
37   const char *expected;
38 } libelf_msgs[ELF_E_NUM] =
39   {
40     { ELF_E_NOERROR, "no error" },
41     { ELF_E_UNKNOWN_ERROR, "unknown error" },
42     { ELF_E_UNKNOWN_VERSION, "unknown version" },
43     { ELF_E_UNKNOWN_TYPE, "unknown type" },
44     { ELF_E_INVALID_HANDLE, "invalid `Elf' handle" },
45     { ELF_E_SOURCE_SIZE, "invalid size of source operand" },
46     { ELF_E_DEST_SIZE, "invalid size of destination operand" },
47     { ELF_E_INVALID_ENCODING, "invalid encoding" },
48     { ELF_E_NOMEM, "out of memory" },
49     { ELF_E_INVALID_FILE, "invalid file descriptor" },
50     { ELF_E_INVALID_OP, "invalid operation" },
51     { ELF_E_NO_VERSION, "ELF version not set" },
52     { ELF_E_INVALID_CMD, "invalid command" },
53     { ELF_E_RANGE, "offset out of range" },
54     { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
55     { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
56     { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
57     { ELF_E_NO_INDEX, "no index available" },
58     { ELF_E_READ_ERROR, "cannot read data from file" },
59     { ELF_E_WRITE_ERROR, "cannot write data to file" },
60     { ELF_E_INVALID_CLASS, "invalid binary class" },
61     { ELF_E_INVALID_INDEX, "invalid section index" },
62     { ELF_E_INVALID_OPERAND, "invalid operand" },
63     { ELF_E_INVALID_SECTION, "invalid section" },
64     { ELF_E_INVALID_COMMAND, "invalid command" },
65     { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
66     { ELF_E_FD_DISABLED, "file descriptor disabled" },
67     { ELF_E_FD_MISMATCH, "archive/member fildes mismatch" },
68     { ELF_E_OFFSET_RANGE, "offset out of range" },
69     { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
70     { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
71     { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
72     { ELF_E_INVALID_DATA, "invalid data" },
73     { ELF_E_DATA_ENCODING, "unknown data encoding" },
74     { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
75     { ELF_E_INVALID_ALIGN, "invalid section alignment" },
76     { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
77     { ELF_E_UPDATE_RO, "update() for write on read-only file" },
78     { ELF_E_NOFILE, "no such file" },
79     { ELF_E_GROUP_NOT_REL,
80       "only relocatable files can contain section groups" },
81     { ELF_E_INVALID_PHDR,
82       "program header only allowed in executables and shared objects" },
83     { ELF_E_NO_PHDR, "file has no program header" },
84     { ELF_E_INVALID_OFFSET, "invalid offset" }
85   };
86
87
88 int
89 main (void)
90 {
91   size_t cnt;
92   int result = EXIT_SUCCESS;
93
94   /* Clear the error state.  */
95   (void) elf_errno ();
96
97   /* Check all the messages of libelf.  */
98   for (cnt = 1; cnt < ELF_E_NUM; ++cnt)
99     {
100       const char *str = elf_errmsg (libelf_msgs[cnt].id);
101
102       if (strcmp (str, libelf_msgs[cnt].expected) != 0)
103         {
104           printf ("libelf msg %zu: expected \"%s\", got \"%s\"\n",
105                   cnt, libelf_msgs[cnt].expected, str);
106           result = EXIT_FAILURE;
107         }
108     }
109
110   return result;
111 }