File indexing completed on 2024-04-14 05:40:39
0001 /***************************************************************************** 0002 * Copyright 2014 - 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 (*func_int)(int a) = nullptr; 0026 static void (*func_void)() = nullptr; 0027 0028 static int arg_int_times = 0; 0029 0030 static int 0031 arg_int() 0032 { 0033 arg_int_times++; 0034 return 10; 0035 } 0036 0037 static int 0038 real_func_int(int a) 0039 { 0040 return a; 0041 } 0042 0043 static int real_func_void_times = 0; 0044 0045 static void 0046 real_func_void() 0047 { 0048 real_func_void_times++; 0049 } 0050 0051 #ifdef __cplusplus 0052 // Functions with structs as return type only works for c++ (for now). 0053 typedef struct { 0054 int i; 0055 int j; 0056 } TestStruct; 0057 0058 static TestStruct (*func_struct)() = nullptr; 0059 #endif 0060 0061 int 0062 main() 0063 { 0064 qtcCall(func_void); 0065 assert(qtcCall(func_int, arg_int()) == 0); 0066 assert(arg_int_times == 0); 0067 func_int = real_func_int; 0068 assert(qtcCall(func_int, arg_int()) == 10); 0069 assert(arg_int_times == 1); 0070 func_void = real_func_void; 0071 qtcCall(func_void); 0072 assert(real_func_void_times == 1); 0073 #ifdef __cplusplus 0074 qtcCall(func_struct); 0075 #endif 0076 return 0; 0077 }