1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include "injectcode.h"
30 #include <sstream>
31 
32 using namespace std;
33 
InjectCode()34 InjectCode::InjectCode()
35 {
36 }
37 
~InjectCode()38 InjectCode::~InjectCode()
39 {
40 }
41 
42 template<typename T>
toStr(const T & value)43 const char* InjectCode::toStr(const T& value)
44 {
45     std::ostringstream s;
46     s << value;
47     m_valueHolder = s.str();
48     return m_valueHolder.c_str();
49 }
50 
simpleMethod1(int arg0,int arg1)51 const char* InjectCode::simpleMethod1(int arg0, int arg1)
52 {
53     return toStr(arg0 + arg1);
54 }
55 
simpleMethod2()56 const char* InjectCode::simpleMethod2()
57 {
58     return "_";
59 }
60 
simpleMethod3(int argc,char ** argv)61 const char* InjectCode::simpleMethod3(int argc, char** argv)
62 {
63     for (int i = 0; i < argc; ++i)
64         m_valueHolder += argv[i];
65     return m_valueHolder.c_str();
66 }
67 
overloadedMethod(int arg0,bool arg1)68 const char* InjectCode::overloadedMethod(int arg0, bool arg1)
69 {
70     toStr(arg0);
71     m_valueHolder += arg1 ? "true" : "false";
72     return m_valueHolder.c_str();
73 }
74 
overloadedMethod(int arg0,double arg1)75 const char* InjectCode::overloadedMethod(int arg0, double arg1)
76 {
77     return toStr(arg0 + arg1);
78 }
79 
overloadedMethod(int argc,char ** argv)80 const char* InjectCode::overloadedMethod(int argc, char** argv)
81 {
82     return simpleMethod3(argc, argv);
83 }
84 
virtualMethod(int arg)85 const char* InjectCode::virtualMethod(int arg)
86 {
87     return toStr(arg);
88 }
89 
arrayMethod(int count,int * values) const90 int InjectCode::arrayMethod(int count, int *values) const
91 {
92     int ret = 0;
93     for (int i=0; i < count; i++)
94         ret += values[i];
95     return ret;
96 }
97 
sumArrayAndLength(int * values) const98 int InjectCode::sumArrayAndLength(int* values) const
99 {
100     int sum = 0;
101 
102     while(*values) {
103         sum = sum + *values + 1;
104         values++;
105     }
106 
107     return sum;
108 }
109