This file is indexed.

/usr/include/sofia-sip-1.12/sofia-sip/tstdef.h is in libsofia-sip-ua-dev 1.12.11+20110422.1-2.1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@file sofia-sip/tstdef.h Macros for unit tests
 *
 * The macros defined here can be used by unit test programs. When a test
 * fails, the TEST macros print the offending file name and line number.
 * They use format that is accepted by Emacs and other fine editors so you
 * can directly go to the source code of the failed test with next-error.
 *
 * @note There is no protection agains multiple inclusion.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Wed Aug 22 13:53:24 2001 ppessi
 *
 * @par Example Program
 *
 * You should define the macro TSTFLAGS to a int variable possibly
 * containing a flag #tst_verbatim. As a convention, the int variable should
 * be set when your test program is run with @c -v or @c --verbatim command
 * line option. If the (TSTFLAGS & tst_verbatim) is true, the test macros
 * log the test before executing it and the result of successful tests, too.
 *
 * You should typedef longlong to integer type at least 64 bit wide before
 * including <sofia-sip/tstdef.h>, too.
 *
 * As an example, we provide a test program making sure that inet_ntop() and
 * inet_pton() behave as expected and that we can create UDP/IPv4 sockets
 * with @b su library:
 *
 * @code
 * #include "config.h"
 *
 * #include <stdio.h>
 * #include <limits.h>
 *
 * #include <sofia-sip/su.h>
 *
 * #define TSTFLAGS tstflags
 *
 * #include <stdlib.h>
 * #include <sofia-sip/tstdef.h>
 *
 * static int tstflags = 0;
 *
 * void usage(void)
 * {
 *   fprintf(stderr, "usage: %s [-v|--verbatim]\n", name);
 *   exit(2);
 * }
 *
 * static int socket_test(void);
 *
 * int main(int argc, char *argv[])
 * {
 *   int retval = 0, i;
 *
 *   for (i = 1; argv[i]; i++) {
 *     if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbatim") == 0)
 *       tstflags |= tst_verbatim;
 *     else
 *       usage();
 *   }
 *
 *   retval |= socket_test(); fflush(stdout);
 *
 *   return retval;
 * }
 *
 * double max_bandwidth()
 *
 * int socket_test(void)
 * {
 *   su_socket_t s;
 *   char buf[64];
 *   unsigned long localhost = htonl(0x7f000001);
 *   unsigned long addr;
 *
 *   BEGIN();
 *
 *   // Check inet_ntop() return value (Tests equality of integral values)
 *   TEST(inet_ntop(AF_INET, &localhost, buf, sizeof buf), buf);
 *
 *   // Check inet_ntop() result (Tests equality of strings)
 *   TEST_S(buf, "127.0.0.1");
 *
 *   // Check inet_pton() argument validation (Tests equality of ints)
 *   TEST(inet_pton(0, buf, &addr), -1);
 *
 *   // Check inet_pton() return value (Tests for true value (non-zero))
 *   TEST_1(inet_pton(AF_INET, buf, &addr) > 0);
 *
 *   // Check inet_pton() result (Tests equality of memory areas)
 *   TEST_M(&addr, &localhost, sizeof(addr));
 *
 *   // Test to create UDP socket (Test for true value)
 *   TEST_1((s = su_socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET);
 *
 *   // Check max bandwidth
 *   TEST_D(max_bandwidth(), DBL_MAX);
 *
 *   END();
 * }
 * @endcode
 */

#ifndef SU_TYPES_H
#include <sofia-sip/su_types.h>
#endif

SOFIA_BEGIN_DECLS

#if HAVE_FUNC
#define TSTNAME name, __func__, "() "
#elif HAVE_FUNCTION
#define TSTNAME name, __FUNCTION__, "() "
#else
#define TSTNAME name, "", ""
#endif

enum {
  /** If (TSTFLAGS & tst_verbatim) is non-zero, be verbatim. */
  tst_verbatim = 1,
  /** If (TSTFLAGS & tst_abort) is non-zero, abort() when failed. */
  tst_abort = 2,
  /** If (TSTFLAGS & tst_log) is non-zero, log intermediate results. */
  tst_log = 4
};

#ifndef TSTFLAGS
#error <TSTFLAGS is not defined>
#endif

/** Begin a test function. @HIDE */
#define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
/** End a test function. @HIDE */
#define END() (void) tstdef_dummy; } END_(TSTFLAGS)
/**Test that @a suite returns a nonzero value.
 * @deprecated Use TEST_1()
 * @HIDE */
#define TEST0(suite) TEST_1_(TSTFLAGS, suite)
/** Test that @a suite returns a nonzero value. @HIDE */
#define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
/** Test a void suite. @HIDE */
#define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
/** Test that @a suite is equal to @a expected. @HIDE */
#define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
/** Test that @a suite is same pointer as @a expected. @HIDE */
#define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
/** Test that 64-bit @a suite is equal to @a expect. @HIDE */
#define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
/** Test that @a suite is same double as @a expected. @HIDE */
#define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
/** Test that @a suite is same string as @a expected. @HIDE */
#define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
/** Test that @a suite is results as identical memory as @a expected. @HIDE */
#define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
/** Test that @a suite has same size as @a expected. @HIDE */
#define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)

/** Print in torture test with -l option */
#define TEST_LOG(x)		       \
  do {				       \
    if (tstflags & tst_log)	       \
      printf x;			       \
  } while(0)

#define TEST_FAILED(flags) \
  (((flags) & tst_abort) || getenv("SOFIA_SIP_TEST_ABORT"))	\
  ? abort() : (void)0; return 1

/** @HIDE */
#define TEST_1_(flags, suite) do { \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
    fflush(stdout); } \
  if ((suite)) { if (flags & tst_verbatim) \
  printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
  fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
          __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
  TEST_FAILED(flags); }						\
  while(0)

/** @HIDE */
#define TEST_VOID_(flags, suite) do { \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
    fflush(stdout); } \
  (suite); } while(0)

/** @HIDE */
#define TEST_(flags, suite, expect) do {				\
    uintptr_t _value, _expect;						\
    if (flags & tst_verbatim) {						\
      printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);	\
      fflush(stdout); }							\
    _value = (uintptr_t)(suite);					\
    _expect = (uintptr_t)(expect);					\
    if (_value == _expect) {						\
      if (flags & tst_verbatim)						\
	printf("%s: %s%sok: %s == %s \n",				\
	       TSTNAME, #suite, #expect);				\
      break;								\
    }									\
    fprintf(stderr, "%s:%u: %s %s%sFAILED: "				\
	    "%s != %s or "MOD_ZU" != "MOD_ZU"\n",			\
	    __FILE__, __LINE__, TSTNAME,				\
	    #suite, #expect, (size_t)_value, (size_t)_expect);		\
    fflush(stderr);							\
    TEST_FAILED(flags);							\
  } while(0)

/** @HIDE */
#define TEST_P_(flags, suite, expect) do {				\
    void const * _value, * _expect;					\
  if (flags & tst_verbatim) {						\
    printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);	\
    fflush(stdout); }							\
  if ((_value = (suite)) == (_expect = (expect))) {			\
    if (flags & tst_verbatim)						\
      printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);	\
    break;								\
  }									\
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n",	\
	  __FILE__, __LINE__, TSTNAME,					\
	  #suite, #expect, _value, _expect); fflush(stderr);		\
  TEST_FAILED(flags);							\
  } while(0)

/** @HIDE */
#define TEST_SIZE_(flags, suite, expect) do {	\
  size_t _value, _expect; \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
    fflush(stdout); } \
  if ((_value = (size_t)(suite)) == \
      (_expect = (size_t)(expect))) \
  { if (flags & tst_verbatim) \
  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
	 __FILE__, __LINE__, TSTNAME, \
	  #suite, #expect, _value, _expect); fflush(stderr);		\
  TEST_FAILED(flags);							\
  } while(0)


/** @HIDE */
#define TEST64_(flags, suite, expect) do { \
  uint64_t _value, _expect; \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
    fflush(stdout); } \
  if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
  { if (flags & tst_verbatim) \
  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
	 __FILE__, __LINE__, TSTNAME, \
	  #suite, #expect, (unsigned longlong)_value,	\
	 (unsigned longlong)_expect); fflush(stderr);	\
  TEST_FAILED(flags);					\
  } while(0)

/** @HIDE */
#define TEST_D_(flags, suite, expect) do { \
  double _value, _expect; \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
    fflush(stdout); } \
  if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
  { if (flags & tst_verbatim) \
  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
	 __FILE__, __LINE__, TSTNAME, \
         #suite, #expect, _value, _expect); fflush(stderr); \
  TEST_FAILED(flags);					    \
  } while(0)

/** @HIDE */
#define TEST_S_(flags, suite, expect) do { \
  char const * _value, * _expect; \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
    fflush(stdout); } \
  _value = (suite); \
  _expect = (expect); \
  if (((_value == NULL || _expect == NULL) && _value == _expect) || \
      (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
  { if (flags & tst_verbatim) \
  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
	 __FILE__, __LINE__, TSTNAME, \
	  #suite, #expect, \
	  _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
	  _expect); fflush(stderr);					\
  TEST_FAILED(flags);							\
  } while(0)

/** @HIDE */
#define TEST_M_(flags, suite, expect, len) do { \
  void const * _value, * _expect; \
  size_t _len; \
  if (flags & tst_verbatim) { \
    printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
    fflush(stdout); } \
  _value = (suite); \
  _expect = (expect); \
  _len = (size_t)(len); \
  if (((_value == NULL || _expect == NULL) && _value == _expect) || \
      memcmp(_value, _expect, _len) == 0) \
  { if (flags & tst_verbatim) \
  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
                  "or \"%.*s\" != \"%.*s\"\n", \
	 __FILE__, __LINE__, TSTNAME, \
	  #suite, #expect, (int)_len, \
          (char *)_value, (int)_len, (char *)_expect); \
  fflush(stderr);							\
  TEST_FAILED(flags);							\
  } while(0)

/** @HIDE */
#define BEGIN_(flags) \
  if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)

/** @HIDE */
#define END_(flags) \
  if (flags & tst_verbatim) \
    printf("%s: %s%sfinished fully successful\n", TSTNAME); \
  return 0

SOFIA_END_DECLS