1 /* Basic test for the TEST_COMPARE macro.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <support/check.h>
21 #include <support/capture_subprocess.h>
24 subprocess (void *closure
)
27 /* These tests should fail. */
28 TEST_COMPARE (ch
, -1); /* Line 28. */
29 TEST_COMPARE (2LL, -2LL); /* Line 29. */
30 TEST_COMPARE (3LL, (short) -3); /* Line 30. */
40 unsigned int u31
: 31 ;
41 long long int i63
: 63;
42 unsigned long long int u63
: 63;
48 /* This should succeed. */
50 TEST_COMPARE (2LL, 2U);
53 unsigned short u16
= 3;
54 TEST_COMPARE (i8
, u16
);
57 struct bitfield bitfield
= { 0 };
58 TEST_COMPARE (bitfield
.i2
, bitfield
.i3
);
59 TEST_COMPARE (bitfield
.u2
, bitfield
.u3
);
60 TEST_COMPARE (bitfield
.u2
, bitfield
.i3
);
61 TEST_COMPARE (bitfield
.u3
, bitfield
.i3
);
62 TEST_COMPARE (bitfield
.i2
, bitfield
.u3
);
63 TEST_COMPARE (bitfield
.i3
, bitfield
.u2
);
64 TEST_COMPARE (bitfield
.i63
, bitfield
.i63
);
65 TEST_COMPARE (bitfield
.u63
, bitfield
.u63
);
66 TEST_COMPARE (bitfield
.i31
, bitfield
.i63
);
67 TEST_COMPARE (bitfield
.i63
, bitfield
.i31
);
69 struct support_capture_subprocess proc
= support_capture_subprocess
72 /* Discard the reported error. */
73 support_record_failure_reset ();
75 puts ("info: *** subprocess output starts ***");
76 fputs (proc
.out
.buffer
, stdout
);
77 puts ("info: *** subprocess output ends ***");
80 (strcmp (proc
.out
.buffer
,
81 "tst-test_compare.c:28: numeric comparison failure\n"
82 " left: 1 (0x1); from: ch\n"
83 " right: -1 (0xffffffff); from: -1\n"
84 "tst-test_compare.c:29: numeric comparison failure\n"
85 " left: 2 (0x2); from: 2LL\n"
86 " right: -2 (0xfffffffffffffffe); from: -2LL\n"
87 "tst-test_compare.c:30: numeric comparison failure"
88 " (widths 64 and 32)\n"
89 " left: 3 (0x3); from: 3LL\n"
90 " right: -3 (0xfffffffd); from: (short) -3\n") == 0);
92 /* Check that there is no output on standard error. */
93 support_capture_subprocess_check (&proc
, "TEST_COMPARE", 0, sc_allow_stdout
);
98 #include <support/test-driver.c>