File indexing completed on 2024-04-14 15:50:44

0001 /*****************************************************************************
0002  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0003  *                                                                           *
0004  *   This program is free software; you can redistribute it and/or modify    *
0005  *   it under the terms of the GNU Lesser General Public License as          *
0006  *   published by the Free Software Foundation; either version 2.1 of the    *
0007  *   License, or (at your option) version 3, or any later version accepted   *
0008  *   by the membership of KDE e.V. (or its successor approved by the         *
0009  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0010  *   Section 6 of version 3 of the license.                                  *
0011  *                                                                           *
0012  *   This program is distributed in the hope that it will be useful,         *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0015  *   Lesser General Public License for more details.                         *
0016  *                                                                           *
0017  *   You should have received a copy of the GNU Lesser General Public        *
0018  *   License along with this library. If not,                                *
0019  *   see <http://www.gnu.org/licenses/>.                                     *
0020  *****************************************************************************/
0021 
0022 #include <qtcurve-utils/utils.h>
0023 #include <assert.h>
0024 
0025 static int default1_times = 0;
0026 
0027 static int
0028 default1()
0029 {
0030     default1_times++;
0031     return -20;
0032 }
0033 
0034 static int default2_times = 0;
0035 
0036 static int
0037 default2()
0038 {
0039     default2_times++;
0040     return 15;
0041 }
0042 
0043 static int value_times = 0;
0044 
0045 static int
0046 value()
0047 {
0048     value_times++;
0049     return 1;
0050 }
0051 
0052 static int
0053 f(int i, int j)
0054 {
0055     return i + j;
0056 }
0057 
0058 #define f(i, j)                                                 \
0059     (f)(QTC_DEFAULT(i, default1()), QTC_DEFAULT(j, default2()))
0060 
0061 #define ARG_MACRO (1)
0062 #define ARG_MACRO1 ARG_MACRO
0063 #define ARG_MACRO2 ARG_MACRO1
0064 #define ARG_MACRO3 ARG_MACRO2
0065 #define ARG_MACRO4 ARG_MACRO3
0066 #define ARG_MACRO5 ARG_MACRO4
0067 #define ARG_MACRO6 ARG_MACRO5
0068 #define ARG_MACRO7 ARG_MACRO6
0069 #define ARG_MACRO8 ARG_MACRO7
0070 
0071 int
0072 main()
0073 {
0074     assert(f(,) == -5);
0075     assert(f(value(),) == 16);
0076     assert(f(, value()) == -19);
0077     assert(f(value(), value()) == 2);
0078     assert(default1_times == 2);
0079     assert(default2_times == 2);
0080     assert(value_times == 4);
0081     assert(f((1), (1)) == 2);
0082     assert(f(ARG_MACRO, ARG_MACRO) == 2);
0083     assert(f(ARG_MACRO1, ARG_MACRO1) == 2);
0084     assert(f(ARG_MACRO2, ARG_MACRO2) == 2);
0085     assert(f(ARG_MACRO3, ARG_MACRO3) == 2);
0086     assert(f(ARG_MACRO4, ARG_MACRO4) == 2);
0087     assert(f(ARG_MACRO5, ARG_MACRO5) == 2);
0088     assert(f(ARG_MACRO6, ARG_MACRO6) == 2);
0089     assert(f(ARG_MACRO7, ARG_MACRO7) == 2);
0090     assert(f(ARG_MACRO8, ARG_MACRO8) == 2);
0091     return 0;
0092 }