Rename debug in testcases to trace

To remove D specific keyword rename
This commit is contained in:
William S Fulton 2022-08-20 15:09:23 +01:00
parent 48c644ea6e
commit 0ba11023ac
13 changed files with 61 additions and 81 deletions

View File

@ -1,9 +1,5 @@
%module cpp11_move_only
#if defined(SWIGD)
%rename(trace) debug;
#endif
%include "cpp11_move_only_helper.i"
%ignore MoveOnly::operator=;
@ -13,22 +9,22 @@
#include <iostream>
using namespace std;
bool debug = false;
bool trace = false;
struct MoveOnly {
MoveOnly(int i = 0) { if (debug) cout << "MoveOnly(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MoveOnly(int i = 0) { if (trace) cout << "MoveOnly(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MoveOnly(const MoveOnly &other) = delete;
MoveOnly & operator=(const MoveOnly &other) = delete;
MoveOnly(MoveOnly &&other) noexcept { if (debug) cout << "MoveOnly(MoveOnly &&)" << " " << this << endl; Counter::move_constructor++; }
MoveOnly & operator=(MoveOnly &&other) noexcept { if (debug) cout << "operator=(MoveOnly &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MoveOnly() { if (debug) cout << "~MoveOnly()" << " " << this << endl; Counter::destructor++; }
MoveOnly(MoveOnly &&other) noexcept { if (trace) cout << "MoveOnly(MoveOnly &&)" << " " << this << endl; Counter::move_constructor++; }
MoveOnly & operator=(MoveOnly &&other) noexcept { if (trace) cout << "operator=(MoveOnly &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MoveOnly() { if (trace) cout << "~MoveOnly()" << " " << this << endl; Counter::destructor++; }
static MoveOnly create() { return MoveOnly(111); }
// static const MoveOnly createConst() { return MoveOnly(111); } // not supported by default
// static void take(MoveOnly mo) { if (debug) cout << "take(MoveOnly)" << " " << &mo << endl; }
// static void take(MoveOnly mo) { if (trace) cout << "take(MoveOnly)" << " " << &mo << endl; }
};
%}
@ -39,18 +35,18 @@ struct MoveOnly {
%inline %{
// Movable and Copyable
struct MovableCopyable {
MovableCopyable(int i = 0) { if (debug) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(int i = 0) { if (trace) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(const MovableCopyable &other) { if (debug) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (debug) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
MovableCopyable(const MovableCopyable &other) { if (trace) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (trace) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
MovableCopyable(MovableCopyable &&other) noexcept { if (debug) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (debug) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MovableCopyable() { if (debug) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
MovableCopyable(MovableCopyable &&other) noexcept { if (trace) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (trace) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MovableCopyable() { if (trace) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
static MovableCopyable create() { return MovableCopyable(111); }
static const MovableCopyable createConst() { return MovableCopyable(111); }
static void take(MovableCopyable mc) { if (debug) cout << "take(MovableCopyable)" << " " << &mc << endl; }
static void take(MovableCopyable mc) { if (trace) cout << "take(MovableCopyable)" << " " << &mc << endl; }
};
%}

View File

@ -37,26 +37,22 @@ namespace std {
#endif
%}
#if defined(SWIGD)
%rename(trace) debug;
#endif
%include "cpp11_move_only_helper.i"
%valuewrapper XXX;
%ignore XXX::operator=;
%inline %{
bool debug = false;
bool trace = false;
struct XXX {
XXX(int i = 0) { if (debug) cout << "XXX(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
XXX(const XXX &other) { if (debug) cout << "XXX(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
XXX & operator=(const XXX &other) { if (debug) cout << "operator=(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
XXX(int i = 0) { if (trace) cout << "XXX(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
XXX(const XXX &other) { if (trace) cout << "XXX(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
XXX & operator=(const XXX &other) { if (trace) cout << "operator=(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
#if defined(__cplusplus) && __cplusplus >= 201103L
XXX(XXX &&other) noexcept { if (debug) cout << "XXX(XXX &&)" << " " << this << endl; Counter::move_constructor++; }
XXX & operator=(XXX &&other) noexcept { if (debug) cout << "operator=(XXX &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
XXX(XXX &&other) noexcept { if (trace) cout << "XXX(XXX &&)" << " " << this << endl; Counter::move_constructor++; }
XXX & operator=(XXX &&other) noexcept { if (trace) cout << "operator=(XXX &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
#endif
~XXX() { if (debug) cout << "~XXX()" << " " << this << endl; Counter::destructor++; }
~XXX() { if (trace) cout << "~XXX()" << " " << this << endl; Counter::destructor++; }
};
bool has_cplusplus11() {
@ -73,7 +69,7 @@ void cleanup(std::unique_ptr<XXX>* p);
%{
std::unique_ptr<XXX> makeUniqueXXX() {
if (debug) cout << "makeUniqueXXX()" << endl;
if (trace) cout << "makeUniqueXXX()" << endl;
return std::unique_ptr<XXX>(new XXX(11));
}
void cleanup(std::unique_ptr<XXX>* p) {
@ -84,15 +80,15 @@ typedef XXX UUU;
%inline %{
XXX createXXX() {
if (debug) cout << "createXXX()" << endl;
if (trace) cout << "createXXX()" << endl;
return XXX(111);
}
XXX createXXX2() {
if (debug) cout << "createXXX2()" << endl;
if (trace) cout << "createXXX2()" << endl;
return XXX(222);
}
UUU createUnknownType() {
if (debug) cout << "createXXX2()" << endl;
if (trace) cout << "createXXX2()" << endl;
return XXX(222);
}
struct YYY {};

View File

@ -2,10 +2,6 @@
// Testcase for testing rvalue reference input typemaps which assume the object is moved during a function call
#if defined(SWIGD)
%rename(trace) debug;
#endif
%include "cpp11_move_only_helper.i"
%rename(MoveAssign) MovableCopyable::operator=(MovableCopyable &&);
@ -16,18 +12,18 @@
#include <iostream>
using namespace std;
bool debug = false;
bool trace = false;
class MovableCopyable {
public:
MovableCopyable(int i = 0) { if (debug) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(int i = 0) { if (trace) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(const MovableCopyable &other) { if (debug) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (debug) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
MovableCopyable(const MovableCopyable &other) { if (trace) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (trace) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
MovableCopyable(MovableCopyable &&other) noexcept { if (debug) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (debug) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MovableCopyable() { if (debug) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
MovableCopyable(MovableCopyable &&other) noexcept { if (trace) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (trace) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MovableCopyable() { if (trace) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
static void movein(MovableCopyable &&mcin) {
MovableCopyable mc = std::move(mcin);

View File

@ -30,7 +30,7 @@ public class runme
static private void check_equal(string a, string b)
{
if (li_std_wstring.debug) {
if (li_std_wstring.trace) {
Console.WriteLine("check_equal {0} {1}", a, b);
display_bytes(a);
display_bytes(b);
@ -150,7 +150,7 @@ public class runme
foreach (string expected in test_strings)
{
if (li_std_wstring.debug)
if (li_std_wstring.trace)
Console.WriteLine("expected (C#): " + expected);
string received = li_std_wstring.test_value(expected);
check_equal(received, expected);

View File

@ -4,11 +4,11 @@ using typemap_out_optimalNamespace;
public class typemap_out_optimal_runme {
public static void Main() {
XX.debug = false;
if (XX.debug)
XX.trace = false;
if (XX.trace)
Console.WriteLine("calling create()");
using (XX x = XX.create()) { }
if (XX.debug)
if (XX.trace)
Console.WriteLine("calling createConst()");
using (XX x = XX.createConst()) { }
}

View File

@ -1,9 +1,5 @@
%module(directors="1") director_pass_by_value
#if defined(SWIGD)
%rename(trace) debug;
#endif
%director DirectorPassByValueAbstractBase;
%include "cpp11_move_only_helper.i"
@ -14,17 +10,17 @@
%inline %{
#include <iostream>
using namespace std;
int debug = false;
int trace = false;
struct PassedByValue {
PassedByValue(int v = 0x12345678) { val = v; if (debug) cout << "PassedByValue(0x" << hex << val << ")" << " " << this << endl; Counter::normal_constructor++; }
PassedByValue(int v = 0x12345678) { val = v; if (trace) cout << "PassedByValue(0x" << hex << val << ")" << " " << this << endl; Counter::normal_constructor++; }
PassedByValue(const PassedByValue &other) { val = other.val; if (debug) cout << "PassedByValue(const PassedByValue &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
PassedByValue & operator=(const PassedByValue &other) { val = other.val; if (debug) cout << "operator=(const PassedByValue &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
PassedByValue(const PassedByValue &other) { val = other.val; if (trace) cout << "PassedByValue(const PassedByValue &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
PassedByValue & operator=(const PassedByValue &other) { val = other.val; if (trace) cout << "operator=(const PassedByValue &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
#if __cplusplus >= 201103L
PassedByValue(PassedByValue &&other) noexcept { val = other.val; if (debug) cout << "PassedByValue(PassedByValue &&)" << " " << this << endl; Counter::move_constructor++; }
PassedByValue & operator=(PassedByValue &&other) noexcept { val = other.val; if (debug) cout << "operator=(PassedByValue &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~PassedByValue() { if (debug) cout << "~PassedByValue()" << " " << this << endl; Counter::destructor++; }
PassedByValue(PassedByValue &&other) noexcept { val = other.val; if (trace) cout << "PassedByValue(PassedByValue &&)" << " " << this << endl; Counter::move_constructor++; }
PassedByValue & operator=(PassedByValue &&other) noexcept { val = other.val; if (trace) cout << "operator=(PassedByValue &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~PassedByValue() { if (trace) cout << "~PassedByValue()" << " " << this << endl; Counter::destructor++; }
#endif
int getVal() { return val; }

View File

@ -3,7 +3,7 @@ package main
import . "swigtests/typemap_out_optimal"
func main() {
SetXXDebug(false)
SetXXTrace(false)
_ = XXCreate()
_ = XXCreateConst()
}

View File

@ -13,7 +13,7 @@ public class typemap_out_optimal_runme {
}
public static void main(String argv[]) {
XX.setDebug(false);
XX.setTrace(false);
{
XX x = XX.create();
x.delete();

View File

@ -23,7 +23,7 @@
#include <string>
#include <iostream>
bool debug = false;
bool trace = false;
void show_wstring_bytes(const std::wstring &s) {
unsigned char *p = (unsigned char *)s.data();
@ -59,7 +59,7 @@ wchar_t* test_wchar_overload(wchar_t *x) {
}
std::wstring test_value(std::wstring x) {
if (debug) {
if (trace) {
std::wcout << "received(C++): " /*<< x */<< std::endl;
show_wstring_bytes(x);
}
@ -80,7 +80,7 @@ void test_reference(std::wstring &x) {
}
bool test_equal(const wchar_t *wcs, const std::wstring& s) {
if (debug) {
if (trace) {
show_wstring_bytes(wcs);
show_wstring_bytes(s);
}

View File

@ -8,13 +8,13 @@ def check(p):
if msg != "hi there":
raise RuntimeError("Bad, got: " + msg)
python_pickle.cvar.debug = False
python_pickle.cvar.trace = False
p = python_pickle.PickleMe("hi there")
check(p)
r = p.__reduce__()
if python_pickle.cvar.debug:
if python_pickle.cvar.trace:
print("__reduce__ returned: {}".format(r))
pickle_string = pickle.dumps(p)
newp = pickle.loads(pickle_string)

View File

@ -1,6 +1,6 @@
from typemap_out_optimal import *
cvar.XX_debug = False
cvar.XX_trace = False
x = XX.create()
del x
x = XX.createConst()

View File

@ -14,7 +14,7 @@ def __reduce__(self):
#else
// Equivalent to Python code above
PyObject *__reduce__() {
if (debug)
if (trace)
std::cout << "In C++ __reduce__" << std::endl;
PyObject *args = PyTuple_New(1);
PyTuple_SetItem(args, 0, SWIG_From_std_string(self->msg));
@ -39,12 +39,12 @@ def __reduce__(self):
%inline %{
#include <iostream>
bool debug = false;
bool trace = false;
struct PickleMe {
std::string msg;
PickleMe(const std::string& msg) : msg(msg) {
if (debug)
if (trace)
std::cout << "In C++ constructor " << " [" << msg << "]" << std::endl;
}
};

View File

@ -18,20 +18,16 @@
%ignore XX::operator=;
#ifdef SWIGD
%rename(trace) XX::debug;
#endif
%inline %{
#include <iostream>
using namespace std;
struct XX {
XX() { if (debug) cout << "XX()" << endl; }
XX(int i) { if (debug) cout << "XX(" << i << ")" << endl; }
XX(const XX &other) { if (debug) cout << "XX(const XX &)" << endl; }
XX& operator =(const XX &other) { if (debug) cout << "operator=(const XX &)" << endl; return *this; }
~XX() { if (debug) cout << "~XX()" << endl; }
XX() { if (trace) cout << "XX()" << endl; }
XX(int i) { if (trace) cout << "XX(" << i << ")" << endl; }
XX(const XX &other) { if (trace) cout << "XX(const XX &)" << endl; }
XX& operator =(const XX &other) { if (trace) cout << "operator=(const XX &)" << endl; return *this; }
~XX() { if (trace) cout << "~XX()" << endl; }
// Note: best observed RVO for C#, Java and Python with g++-6 to g++-10 (just one constructor and one destructor call)
static XX create() {
@ -40,8 +36,8 @@ struct XX {
static const XX createConst() {
return XX(456);
}
static bool debug;
static bool trace;
};
bool XX::debug = true;
bool XX::trace = true;
%}