1 /*****************************************************************************
2  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
3  *                                                                           *
4  *   This program is free software; you can redistribute it and/or modify    *
5  *   it under the terms of the GNU Lesser General Public License as          *
6  *   published by the Free Software Foundation; either version 2.1 of the    *
7  *   License, or (at your option) version 3, or any later version accepted   *
8  *   by the membership of KDE e.V. (or its successor approved by the         *
9  *   membership of KDE e.V.), which shall act as a proxy defined in          *
10  *   Section 6 of version 3 of the license.                                  *
11  *                                                                           *
12  *   This program is distributed in the hope that it will be useful,         *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
15  *   Lesser General Public License for more details.                         *
16  *                                                                           *
17  *   You should have received a copy of the GNU Lesser General Public        *
18  *   License along with this library. If not,                                *
19  *   see <http://www.gnu.org/licenses/>.                                     *
20  *****************************************************************************/
21 
22 #include <qtcurve-utils/utils.h>
23 #include <assert.h>
24 
25 static int default1_times = 0;
26 
27 static int
default1(int val)28 default1(int val)
29 {
30     default1_times++;
31     return val;
32 }
33 
34 static int default2_times = 0;
35 
36 static int
default2(int val)37 default2(int val)
38 {
39     default2_times++;
40     return val;
41 }
42 
43 static int value_times = 0;
44 
45 static int
value()46 value()
47 {
48     value_times++;
49     return 1;
50 }
51 
52 static int
f(int i,int j)53 f(int i, int j)
54 {
55     return i + j;
56 }
57 
58 int
main()59 main()
60 {
61     int def1 = -20;
62     int def2 = 15;
63 #define f(i, j)                                                         \
64     (f)(qtcDefault(i, default1(def1)), qtcDefault(j, default2(def2)))
65     assert(f(0, 0) == -5);
66     assert(f(value(), 0) == 16);
67     assert(f(0, value()) == -19);
68     assert(f(value(), value()) == 2);
69     assert(default1_times == 2);
70     assert(default2_times == 2);
71     assert(value_times == 4);
72     return 0;
73 }
74