mirror of https://github.com/swig/swig
Remove wrapper aliases generation and use -namespace in the tests
The -namespace option provides a better way of using the wrapped API, so drop the optional wrapper generation, which is useless when this option is used and just generates many lines of unwanted junk in the header. Update the test suite and the examples to compensate to not rely on being able to define SWIG_DEFINE_WRAPPER_ALIASES and add -namespace option to all C++ tests, as it's done for C# test suite, and update them to use the correct prefix and also use the accessors for the global variables rather than using them directly, as this is impossible when namespace prefix is used (it would have been possible to define a preprocessor symbol corresponding to the real variable name, but it's arguably not worth it). fixup! Remove wrapper aliases generation and use -namespace in the tests
This commit is contained in:
parent
3ebf1c1769
commit
e8f9bdba80
|
@ -197,7 +197,7 @@ Wrapping C functions and variables is obviously performed in a straightforward w
|
|||
|
||||
|
||||
<p>
|
||||
For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is <tt>module_</tt>, i.e. the name of the SWIG module followed by underscore. If <tt>nspace</tt> feature is used, the prefix for a function defined in a namespace is <tt>namespace_</tt> -- note that it does <em>not</em> contain the module prefix, as it's not necessary to make a unique function name in this case. The wrapper function performs a call to the original function, and returns its result. For convenience, a <tt>#define func prefix_func</tt> can be provided in the generated header file to make it possible to call the function under its original name: predefine <tt>SWIG_DEFINE_WRAPPER_ALIASES</tt> before including the wrapper header to enable these defines, which are disabled by default to avoid accidental name clashes.
|
||||
For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is <tt>module_</tt>, i.e. the name of the SWIG module followed by underscore, by default. If <tt>-namespace</tt> option is used, the prefix corresponding to the given fixed namespace is used instead. If <tt>nspace</tt> feature is used, the prefix corresponding to the namespace in which the function is defined is used -- note that, unlike with <tt>-namespace</tt> option, this prefix can be different for different functions. The wrapper function performs a call to the original function, and returns its result.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -333,8 +333,10 @@ This section briefly covers the essential aspects of this wrapping.
|
|||
<H3><a name="C_enums"></a>36.3.3 Enums</H3>
|
||||
|
||||
<p>
|
||||
C enums are simply copied to the generated code and keep the same name as in
|
||||
the original code.
|
||||
C enums and unscoped C++ enums are simply copied to the generated code and both the enum itself and its elements keep the same name as in the original code unless <tt>-namespace</tt> option is used or <tt>nspace</tt> feature is enabled, in which case the prefix corresponding to the specified namespace is used.
|
||||
</p>
|
||||
<p>
|
||||
For scoped C++11 enums, the enum name itself is used as an additional prefix.
|
||||
</p>
|
||||
|
||||
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "example_wrap.h"
|
||||
|
||||
static void show_exception(const char* prefix) {
|
||||
SWIG_CException* ex = SWIG_PendingException_get();
|
||||
SWIG_CException* ex = example_SWIG_PendingException_get();
|
||||
assert(ex);
|
||||
printf("%s exception: %s (%d)\n", prefix, SWIG_CException_msg_get(ex), SWIG_CException_code_get(ex));
|
||||
SWIG_PendingException_reset();
|
||||
example_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -33,7 +32,7 @@ int main() {
|
|||
int i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
Test_multi(t, i);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
if (!example_SWIG_PendingException_get()) {
|
||||
printf("Success for i=%d\n", i);
|
||||
} else {
|
||||
printf("For i=%d", i);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "example_wrap.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int a = 42;
|
||||
int b = 105;
|
||||
int g = gcd(a, b);
|
||||
int g = example_gcd(a, b);
|
||||
printf("The gcd of %d and %d is %d\n", a, b, g);
|
||||
printf("Foo = %f\n", Foo);
|
||||
Foo = 3.1415926;
|
||||
|
|
|
@ -104,6 +104,8 @@ include $(srcdir)/../common.mk
|
|||
# Overridden variables here
|
||||
SWIGOPT += -w524 # Suppress SWIGWARN_LANG_EXPERIMENTAL warning
|
||||
|
||||
%.cpptest: SWIGOPT += -namespace $*
|
||||
|
||||
SRCDIR = ../$(srcdir)/
|
||||
|
||||
# Rules for the different types of tests
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
D *d = D_new();
|
||||
abstract_access_D *d = abstract_access_D_new();
|
||||
|
||||
assert(D_do_x(d) == 1);
|
||||
assert(abstract_access_D_do_x(d) == 1);
|
||||
|
||||
D_delete(d);
|
||||
abstract_access_D_delete(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Engine *e = Engine_new();
|
||||
A *a = A_new();
|
||||
abstract_typedef_Engine *e = abstract_typedef_Engine_new();
|
||||
abstract_typedef_A *a = abstract_typedef_A_new();
|
||||
|
||||
assert(AbstractBaseClass_write((AbstractBaseClass*)a, e) == true);
|
||||
assert(abstract_typedef_AbstractBaseClass_write((abstract_typedef_AbstractBaseClass*)a, e) == true);
|
||||
|
||||
A_delete(a);
|
||||
Engine_delete(e);
|
||||
abstract_typedef_A_delete(a);
|
||||
abstract_typedef_Engine_delete(e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
B *b = B_new();
|
||||
D *d = D_new();
|
||||
E *e = E_new();
|
||||
abstract_virtual_B *b = abstract_virtual_B_new();
|
||||
abstract_virtual_D *d = abstract_virtual_D_new();
|
||||
abstract_virtual_E *e = abstract_virtual_E_new();
|
||||
|
||||
assert(B_foo(b) == 0);
|
||||
assert(D_foo(d) == 0);
|
||||
assert(E_foo(e) == 0);
|
||||
assert(abstract_virtual_B_foo(b) == 0);
|
||||
assert(abstract_virtual_D_foo(d) == 0);
|
||||
assert(abstract_virtual_E_foo(e) == 0);
|
||||
|
||||
B_delete(b);
|
||||
D_delete(d);
|
||||
E_delete(e);
|
||||
abstract_virtual_B_delete(b);
|
||||
abstract_virtual_D_delete(d);
|
||||
abstract_virtual_E_delete(e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Foo *f = Foo_new();
|
||||
Foo *f2 = Foo_blah(f);
|
||||
add_link_Foo *f = add_link_Foo_new();
|
||||
add_link_Foo *f2 = add_link_Foo_blah(f);
|
||||
|
||||
assert(f2 != 0);
|
||||
|
||||
Foo_delete(f);
|
||||
Foo_delete(f2);
|
||||
add_link_Foo_delete(f);
|
||||
add_link_Foo_delete(f2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,28 +2,28 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Foo *f = Foo_new();
|
||||
anonymous_bitfield_Foo *f = anonymous_bitfield_Foo_new();
|
||||
|
||||
assert(f != 0);
|
||||
|
||||
Foo_x_set(f, 1);
|
||||
assert(Foo_x_get(f) == 1);
|
||||
assert(Foo_y_get(f) == 0);
|
||||
anonymous_bitfield_Foo_x_set(f, 1);
|
||||
assert(anonymous_bitfield_Foo_x_get(f) == 1);
|
||||
assert(anonymous_bitfield_Foo_y_get(f) == 0);
|
||||
|
||||
Foo_y_set(f, 0);
|
||||
assert(Foo_x_get(f) == 1);
|
||||
assert(Foo_y_get(f) == 0);
|
||||
anonymous_bitfield_Foo_y_set(f, 0);
|
||||
assert(anonymous_bitfield_Foo_x_get(f) == 1);
|
||||
assert(anonymous_bitfield_Foo_y_get(f) == 0);
|
||||
|
||||
Foo_f_set(f, 1);
|
||||
assert(Foo_f_get(f) == 1);
|
||||
anonymous_bitfield_Foo_f_set(f, 1);
|
||||
assert(anonymous_bitfield_Foo_f_get(f) == 1);
|
||||
|
||||
Foo_z_set(f, 1);
|
||||
assert(Foo_z_get(f) == 1);
|
||||
anonymous_bitfield_Foo_z_set(f, 1);
|
||||
assert(anonymous_bitfield_Foo_z_get(f) == 1);
|
||||
|
||||
Foo_seq_set(f, 1);
|
||||
assert(Foo_seq_get(f) == 1);
|
||||
anonymous_bitfield_Foo_seq_set(f, 1);
|
||||
assert(anonymous_bitfield_Foo_seq_get(f) == 1);
|
||||
|
||||
Foo_delete(f);
|
||||
anonymous_bitfield_Foo_delete(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
#include <assert.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "c_backend_cpp_exception/c_backend_cpp_exception_wrap.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(checkVal == 0);
|
||||
throwSomeKnownException();
|
||||
assert(checkVal == 1);
|
||||
throwSomeUnknownException();
|
||||
assert(checkVal == 2);
|
||||
assert(c_backend_cpp_exception_checkVal_get() == 0);
|
||||
c_backend_cpp_exception_throwSomeKnownException();
|
||||
assert(c_backend_cpp_exception_checkVal_get() == 1);
|
||||
c_backend_cpp_exception_throwSomeUnknownException();
|
||||
assert(c_backend_cpp_exception_checkVal_get() == 2);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -2,12 +2,11 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_wrap.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
char *myComposedString = myStringAppend("World, ", "Hello!");
|
||||
char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend("World, ", "Hello!");
|
||||
|
||||
assert(myComposedString);
|
||||
assert(strcmp(myComposedString, "World, Hello!") == 0);
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "cast_operator/cast_operator_wrap.h"
|
||||
|
||||
int main() {
|
||||
A *a = A_new();
|
||||
if (strcmp(A_tochar(a), "hi"))
|
||||
cast_operator_A *a = cast_operator_A_new();
|
||||
if (strcmp(cast_operator_A_tochar(a), "hi"))
|
||||
fprintf(stderr, "cast failed\n");
|
||||
A_delete(a);
|
||||
cast_operator_A_delete(a);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "char_strings/char_strings_wrap.h"
|
||||
|
||||
int main() {
|
||||
|
@ -14,25 +13,25 @@ int main() {
|
|||
|
||||
// get functions
|
||||
for (i=0; i<count; i++) {
|
||||
char *str = GetCharHeapString();
|
||||
char *str = char_strings_GetCharHeapString();
|
||||
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char get 1 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
DeleteCharHeapString();
|
||||
char_strings_DeleteCharHeapString();
|
||||
}
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
const char *str = GetConstCharProgramCodeString();
|
||||
const char *str = char_strings_GetConstCharProgramCodeString();
|
||||
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char get 2 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
DeleteCharHeapString();
|
||||
char_strings_DeleteCharHeapString();
|
||||
}
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
char *str = GetCharStaticString();
|
||||
char *str = char_strings_GetCharStaticString();
|
||||
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char get 3 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
|
@ -40,7 +39,7 @@ int main() {
|
|||
}
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
char *str = GetCharStaticStringFixed();
|
||||
char *str = char_strings_GetCharStaticStringFixed();
|
||||
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char get 4 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
|
@ -48,7 +47,7 @@ int main() {
|
|||
}
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
const char *str = GetConstCharStaticStringFixed();
|
||||
const char *str = char_strings_GetConstCharStaticStringFixed();
|
||||
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char get 5 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
|
@ -59,7 +58,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetCharHeapString(str, i)) {
|
||||
if (!char_strings_SetCharHeapString(str, i)) {
|
||||
fprintf(stderr, "Test char set 1 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetCharStaticString(str, i)) {
|
||||
if (!char_strings_SetCharStaticString(str, i)) {
|
||||
fprintf(stderr, "Test char set 2 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -78,7 +77,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetCharArrayStaticString(str, i)) {
|
||||
if (!char_strings_SetCharArrayStaticString(str, i)) {
|
||||
fprintf(stderr, "Test char set 3 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetConstCharHeapString(str, i)) {
|
||||
if (!char_strings_SetConstCharHeapString(str, i)) {
|
||||
fprintf(stderr, "Test char set 4 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -96,7 +95,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetConstCharStaticString(str, i)) {
|
||||
if (!char_strings_SetConstCharStaticString(str, i)) {
|
||||
fprintf(stderr, "Test char set 5 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetConstCharArrayStaticString(str, i)) {
|
||||
if (!char_strings_SetConstCharArrayStaticString(str, i)) {
|
||||
fprintf(stderr, "Test char set 6 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -115,7 +114,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char ping[256];
|
||||
sprintf(ping, "%s%d", OTHERLAND_MSG, i);
|
||||
char *pong = CharPingPong(ping);
|
||||
char *pong = char_strings_CharPingPong(ping);
|
||||
if (strcmp(ping, pong) != 0) {
|
||||
fprintf(stderr, "Test PingPong 1 failed.\nExpected:%d\nReceived:%d\n", ping, pong);
|
||||
exit(1);
|
||||
|
@ -127,8 +126,8 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
global_char = str;
|
||||
if (strcmp(global_char, str) != 0) {
|
||||
char_strings_global_char_set(str);
|
||||
if (strcmp(char_strings_global_char_get(), str) != 0) {
|
||||
fprintf(stderr, "Test variables 1 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -137,8 +136,8 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
sprintf(global_char_array1, "%s%d", OTHERLAND_MSG, i);
|
||||
if (strcmp(global_char_array1, str) != 0) {
|
||||
sprintf(char_strings_global_char_array1_get(), "%s%d", OTHERLAND_MSG, i);
|
||||
if (strcmp(char_strings_global_char_array1_get(), str) != 0) {
|
||||
fprintf(stderr, "Test variables 2 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -147,15 +146,15 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char str[256];
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
sprintf(global_char_array2, "%s%d", OTHERLAND_MSG, i);
|
||||
if (strcmp(global_char_array2, str) != 0) {
|
||||
sprintf(char_strings_global_char_array2_get(), "%s%d", OTHERLAND_MSG, i);
|
||||
if (strcmp(char_strings_global_char_array2_get(), str) != 0) {
|
||||
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
if (strcmp(global_const_char, CPLUSPLUS_MSG) != 0) {
|
||||
if (strcmp(char_strings_global_const_char_get(), CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -180,7 +179,7 @@ int main() {
|
|||
// char *& tests
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
const char **str = GetConstCharPointerRef();
|
||||
const char **str = char_strings_GetConstCharPointerRef();
|
||||
if (strcmp(*str, CPLUSPLUS_MSG) != 0) {
|
||||
fprintf(stderr, "Test char pointer ref get failed, iteration %d\n",i);
|
||||
exit(1);
|
||||
|
@ -190,7 +189,7 @@ int main() {
|
|||
for (i=0; i<count; i++) {
|
||||
char *str = (char*) malloc(sizeof(char) * 256);
|
||||
sprintf(str, "%s%d", OTHERLAND_MSG, i);
|
||||
if (!SetConstCharPointerRef((const char **)&str, i)) {
|
||||
if (!char_strings_SetConstCharPointerRef((const char **)&str, i)) {
|
||||
fprintf(stderr, "Test char pointer ref set failed, iteration %d\n", i);
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Foo* f;
|
||||
Foo* f2;
|
||||
cpp11_shared_ptr_const_Foo* f;
|
||||
cpp11_shared_ptr_const_Foo* f2;
|
||||
|
||||
f = Foo_new(17);
|
||||
assert(Foo_get_m(f) == 17);
|
||||
f = cpp11_shared_ptr_const_Foo_new(17);
|
||||
assert(cpp11_shared_ptr_const_Foo_get_m(f) == 17);
|
||||
f2 = cpp11_shared_ptr_const_foo(f);
|
||||
assert(Foo_get_m(f2) == 17);
|
||||
Foo_delete(f2);
|
||||
Foo_delete(f);
|
||||
assert(cpp11_shared_ptr_const_Foo_get_m(f2) == 17);
|
||||
cpp11_shared_ptr_const_Foo_delete(f2);
|
||||
cpp11_shared_ptr_const_Foo_delete(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,23 +3,23 @@
|
|||
|
||||
int main(int argc, const char *argv[]) {
|
||||
{
|
||||
Derived* d;
|
||||
cpp11_shared_ptr_upcast_Derived* d;
|
||||
|
||||
d = Derived_new_i(17);
|
||||
assert( cpp11_shared_ptr_upcast_base_num1((Base *)d) == -1 );
|
||||
d = cpp11_shared_ptr_upcast_Derived_new_i(17);
|
||||
assert( cpp11_shared_ptr_upcast_base_num1((cpp11_shared_ptr_upcast_Base *)d) == -1 );
|
||||
assert( cpp11_shared_ptr_upcast_derived_num1(d) == 17 );
|
||||
|
||||
Derived_delete(d);
|
||||
cpp11_shared_ptr_upcast_Derived_delete(d);
|
||||
}
|
||||
|
||||
{
|
||||
Derived2* d2;
|
||||
cpp11_shared_ptr_upcast_Derived2* d2;
|
||||
|
||||
d2 = Derived2_new_i(289);
|
||||
assert( cpp11_shared_ptr_upcast_base2_num1((Base2 *)d2) == -1 );
|
||||
d2 = cpp11_shared_ptr_upcast_Derived2_new_i(289);
|
||||
assert( cpp11_shared_ptr_upcast_base2_num1((cpp11_shared_ptr_upcast_Base2 *)d2) == -1 );
|
||||
assert( cpp11_shared_ptr_upcast_derived2_num1(d2) == 289 );
|
||||
|
||||
Derived2_delete(d2);
|
||||
cpp11_shared_ptr_upcast_Derived2_delete(d2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "cpp_basic/cpp_basic_wrap.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
Foo *f = Foo_new(5);
|
||||
cpp_basic_Foo *f = cpp_basic_Foo_new(5);
|
||||
|
||||
// test global static variables
|
||||
// TODO: Implement or document as not available
|
||||
|
@ -12,98 +11,98 @@ int main(int argc, const char *argv[]) {
|
|||
assert(init_ref != 0);
|
||||
|
||||
global_fptr_set(f);
|
||||
assert(Foo_num_get(global_fptr_get()) == 5);
|
||||
assert(cpp_basic_Foo_num_get(global_fptr_get()) == 5);
|
||||
|
||||
assert(Foo_num_get(global_fref_get()) == -4);
|
||||
Foo_num_set(f, 6);
|
||||
assert(cpp_basic_Foo_num_get(global_fref_get()) == -4);
|
||||
cpp_basic_Foo_num_set(f, 6);
|
||||
global_fref_set(f);
|
||||
assert(Foo_num_get(global_fref_get()) == 6);
|
||||
assert(cpp_basic_Foo_num_get(global_fref_get()) == 6);
|
||||
|
||||
Foo_num_set(f, 7);
|
||||
cpp_basic_Foo_num_set(f, 7);
|
||||
global_fval_set(f);
|
||||
assert(Foo_num_get(global_fval_get()) == 7);
|
||||
assert(cpp_basic_Foo_num_get(global_fval_get()) == 7);
|
||||
*/
|
||||
|
||||
Foo_num_set(f, 5);
|
||||
assert(Foo_num_get(f) == 5);
|
||||
assert(Foo_func1(f, 2) == 20);
|
||||
assert(Foo_func2(f, 2) == -10);
|
||||
cpp_basic_Foo_num_set(f, 5);
|
||||
assert(cpp_basic_Foo_num_get(f) == 5);
|
||||
assert(cpp_basic_Foo_func1(f, 2) == 20);
|
||||
assert(cpp_basic_Foo_func2(f, 2) == -10);
|
||||
|
||||
// function pointer set/get tests are missing
|
||||
// because of unclear implementation details
|
||||
//foo_func_ptr_set(f, &Foo_func1);
|
||||
//foo_func_ptr_set(f, &cpp_basic_Foo_func1);
|
||||
|
||||
// test of global static variable is missing
|
||||
// because of unclear implementation details
|
||||
//assert(c_init_ref != 0);
|
||||
|
||||
Bar *b = Bar_new();
|
||||
cpp_basic_Bar *b = cpp_basic_Bar_new();
|
||||
|
||||
// check default value set by constructor
|
||||
assert(Bar_cint_get(b) == 3);
|
||||
assert(cpp_basic_Bar_cint_get(b) == 3);
|
||||
|
||||
// check default value set by Bar initializer
|
||||
assert(Foo_num_get(Bar_fval_get(b)) == 15);
|
||||
// check default value set by cpp_basic_Bar initializer
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 15);
|
||||
// change, recheck
|
||||
Foo_num_set(Bar_fval_get(b), 2);
|
||||
assert(Foo_num_get(Bar_fval_get(b)) == 2);
|
||||
cpp_basic_Foo_num_set(cpp_basic_Bar_fval_get(b), 2);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 2);
|
||||
|
||||
// check references
|
||||
assert(Bar_fref_get(b) != 0);
|
||||
assert(cpp_basic_Bar_fref_get(b) != 0);
|
||||
|
||||
// check global static value and references
|
||||
assert(Foo_num_get(Bar_fref_get(b)) == -4);
|
||||
Foo_num_set(Bar_fref_get(b), 1);
|
||||
assert(Foo_num_get(Bar_fref_get(b)) == 1);
|
||||
// create new Bar instance and check static member value
|
||||
Bar *b2 = Bar_new();
|
||||
assert(Foo_num_get(Bar_fref_get(b2)) == 1);
|
||||
Bar_delete(b2);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == -4);
|
||||
cpp_basic_Foo_num_set(cpp_basic_Bar_fref_get(b), 1);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == 1);
|
||||
// create new cpp_basic_Bar instance and check static member value
|
||||
cpp_basic_Bar *b2 = cpp_basic_Bar_new();
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b2)) == 1);
|
||||
cpp_basic_Bar_delete(b2);
|
||||
b2 = 0;
|
||||
|
||||
// Try to set a pointer
|
||||
Bar_fptr_set(b, f);
|
||||
cpp_basic_Bar_fptr_set(b, f);
|
||||
|
||||
assert(Bar_test(b, 2, f) == 9);
|
||||
assert(Bar_test(b, 2, 0) == 4);
|
||||
assert(cpp_basic_Bar_test(b, 2, f) == 9);
|
||||
assert(cpp_basic_Bar_test(b, 2, 0) == 4);
|
||||
|
||||
Foo *f2 = Bar_testFoo(b, 2, f);
|
||||
assert(Foo_num_get(f2) == 11);
|
||||
Foo_delete(f2);
|
||||
cpp_basic_Foo *f2 = cpp_basic_Bar_testFoo(b, 2, f);
|
||||
assert(cpp_basic_Foo_num_get(f2) == 11);
|
||||
cpp_basic_Foo_delete(f2);
|
||||
f2 = 0;
|
||||
|
||||
// test static variables
|
||||
Bar_global_fptr_set(f);
|
||||
assert(Foo_num_get(Bar_global_fptr_get()) == 5);
|
||||
cpp_basic_Bar_global_fptr_set(f);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fptr_get()) == 5);
|
||||
|
||||
Foo_num_set(f, 6);
|
||||
Bar_global_fref_set(f);
|
||||
assert(Foo_num_get(Bar_global_fref_get()) == 6);
|
||||
cpp_basic_Foo_num_set(f, 6);
|
||||
cpp_basic_Bar_global_fref_set(f);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fref_get()) == 6);
|
||||
|
||||
Foo_num_set(f, 7);
|
||||
Bar_global_fval_set(f);
|
||||
assert(Foo_num_get(Bar_global_fval_get()) == 7);
|
||||
cpp_basic_Foo_num_set(f, 7);
|
||||
cpp_basic_Bar_global_fval_set(f);
|
||||
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fval_get()) == 7);
|
||||
|
||||
// getting, setting and calling function pointers isn't supported yet
|
||||
#if 0
|
||||
SomeTypeForMemFnPtr func1 = get_func1_ptr();
|
||||
Foo_func_ptr_set(f, func1);
|
||||
cpp_basic_Foo_func_ptr_set(f, func1);
|
||||
assert(test_func_ptr(f, 2) == 28);
|
||||
SomeTypeForMemFnPtr func2 = get_func2_ptr();
|
||||
Foo_func_ptr_set(f, func2);
|
||||
cpp_basic_Foo_func_ptr_set(f, func2);
|
||||
assert(test_func_ptr(f, 2) == -14);
|
||||
#endif
|
||||
|
||||
Bar_delete(b);
|
||||
Foo_delete(f);
|
||||
cpp_basic_Bar_delete(b);
|
||||
cpp_basic_Foo_delete(f);
|
||||
|
||||
Fl_Window *w = Fl_Window_new();
|
||||
cpp_basic_Fl_Window *w = cpp_basic_Fl_Window_new();
|
||||
// Test whether macro worked for code extension
|
||||
// and test optional function parameters
|
||||
Fl_Window_show(w);
|
||||
Fl_Window_show_pv(w, 0);
|
||||
Fl_Window_show_pv_pv(w, 0, 0);
|
||||
Fl_Window_delete(w);
|
||||
cpp_basic_Fl_Window_show(w);
|
||||
cpp_basic_Fl_Window_show_pv(w, 0);
|
||||
cpp_basic_Fl_Window_show_pv_pv(w, 0, 0);
|
||||
cpp_basic_Fl_Window_delete(w);
|
||||
w = 0;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -5,67 +5,67 @@
|
|||
int main(int argc, const char *argv[]) {
|
||||
|
||||
// We don't have "enum SOME_ENUM"
|
||||
int e = ENUM_ONE, *p;
|
||||
int e = cpp_enum_ENUM_ONE, *p;
|
||||
|
||||
// check the constructor's default value
|
||||
StructWithEnums *s = StructWithEnums_new();
|
||||
assert(StructWithEnums_some_enum_get(s) == ENUM_ONE);
|
||||
cpp_enum_StructWithEnums *s = cpp_enum_StructWithEnums_new();
|
||||
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_ONE);
|
||||
|
||||
// check setter
|
||||
StructWithEnums_some_enum_set(s, ENUM_TWO);
|
||||
assert(StructWithEnums_some_enum_get(s) == ENUM_TWO);
|
||||
cpp_enum_StructWithEnums_some_enum_set(s, cpp_enum_ENUM_TWO);
|
||||
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_TWO);
|
||||
|
||||
// check function call
|
||||
StructWithEnums_enum_test1(s, e, &e, &e);
|
||||
cpp_enum_StructWithEnums_enum_test1(s, e, &e, &e);
|
||||
|
||||
// check function call
|
||||
StructWithEnums_enum_test2(s, e, &e, &e);
|
||||
cpp_enum_StructWithEnums_enum_test2(s, e, &e, &e);
|
||||
|
||||
// check function call
|
||||
assert(StructWithEnums_enum_test3(s) == ENUM_ONE);
|
||||
assert(cpp_enum_StructWithEnums_enum_test3(s) == cpp_enum_ENUM_ONE);
|
||||
|
||||
// check function call
|
||||
assert(StructWithEnums_enum_test4(s) == ENUM_TWO);
|
||||
assert(cpp_enum_StructWithEnums_enum_test4(s) == cpp_enum_ENUM_TWO);
|
||||
|
||||
// check function call
|
||||
p = StructWithEnums_enum_test5(s);
|
||||
assert(*p == ENUM_TWO);
|
||||
p = cpp_enum_StructWithEnums_enum_test5(s);
|
||||
assert(*p == cpp_enum_ENUM_TWO);
|
||||
|
||||
// check function call
|
||||
p = StructWithEnums_enum_test6(s);
|
||||
assert(*p == ENUM_TWO);
|
||||
p = cpp_enum_StructWithEnums_enum_test6(s);
|
||||
assert(*p == cpp_enum_ENUM_TWO);
|
||||
|
||||
// check function call
|
||||
p = StructWithEnums_enum_test7(s);
|
||||
assert(*p == ENUM_TWO);
|
||||
p = cpp_enum_StructWithEnums_enum_test7(s);
|
||||
assert(*p == cpp_enum_ENUM_TWO);
|
||||
|
||||
// check function call
|
||||
p = StructWithEnums_enum_test8(s);
|
||||
assert(*p == ENUM_TWO);
|
||||
p = cpp_enum_StructWithEnums_enum_test8(s);
|
||||
assert(*p == cpp_enum_ENUM_TWO);
|
||||
|
||||
StructWithEnums_delete(s);
|
||||
cpp_enum_StructWithEnums_delete(s);
|
||||
|
||||
Foo *f = Foo_new();
|
||||
cpp_enum_Foo *f = cpp_enum_Foo_new();
|
||||
|
||||
// check the constructor's default value
|
||||
assert(Foo_hola_get(f) == Foo_Hello);
|
||||
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hello);
|
||||
|
||||
Foo_hola_set(f, Foo_Hi);
|
||||
assert(Foo_hola_get(f) == Foo_Hi);
|
||||
cpp_enum_Foo_hola_set(f, cpp_enum_Foo_Hi);
|
||||
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hi);
|
||||
|
||||
Foo_delete(f);
|
||||
cpp_enum_Foo_delete(f);
|
||||
|
||||
//check C enum
|
||||
hi = Hi;
|
||||
hi = Hello;
|
||||
cpp_enum_hi_set(cpp_enum_Hi);
|
||||
cpp_enum_hi_set(cpp_enum_Hello);
|
||||
|
||||
// check typedef enum
|
||||
play_state t;
|
||||
cpp_enum_play_state t;
|
||||
|
||||
t = PLAY;
|
||||
t = cpp_enum_PLAY;
|
||||
assert(t == 1);
|
||||
|
||||
t = STOP;
|
||||
t = cpp_enum_STOP;
|
||||
assert(t == 0);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include "enum_rename/enum_rename_wrap.h"
|
||||
|
||||
int main() {
|
||||
assert(M_Jan == 0);
|
||||
assert(May == 1);
|
||||
assert(M_Dec == 2);
|
||||
assert(enum_rename_M_Jan == 0);
|
||||
assert(enum_rename_May == 1);
|
||||
assert(enum_rename_M_Dec == 2);
|
||||
|
||||
assert(S_Can == 1);
|
||||
assert(S_Must == 2);
|
||||
assert(enum_rename_S_Can == 1);
|
||||
assert(enum_rename_S_Must == 2);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "enums/enums_wrap.h"
|
||||
|
||||
int main() {
|
||||
assert(GlobalInstance == globalinstance1);
|
||||
assert(iFoo_Char == 'a');
|
||||
bar2(1);
|
||||
bar3(1);
|
||||
bar1(1);
|
||||
enums_bar2(1);
|
||||
enums_bar3(1);
|
||||
enums_bar1(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "exception_order/exception_order_wrap.h"
|
||||
|
||||
int main() {
|
||||
A* a = A_new();
|
||||
exception_order_A* a = exception_order_A_new();
|
||||
|
||||
A_foo(a);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
exception_order_A_foo(a);
|
||||
if (!exception_order_SWIG_PendingException_get()) {
|
||||
fprintf(stderr, "foo: bad exception order\n");
|
||||
} else {
|
||||
SWIG_PendingException_reset();
|
||||
exception_order_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
A_bar(a);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
exception_order_A_bar(a);
|
||||
if (!exception_order_SWIG_PendingException_get()) {
|
||||
fprintf(stderr, "bar: bad exception order\n");
|
||||
} else {
|
||||
SWIG_PendingException_reset();
|
||||
exception_order_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
A_foobar(a);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
exception_order_A_foobar(a);
|
||||
if (!exception_order_SWIG_PendingException_get()) {
|
||||
fprintf(stderr, "foobar: bad exception order\n");
|
||||
} else {
|
||||
SWIG_PendingException_reset();
|
||||
exception_order_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
A_barfoo(a, 1);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
exception_order_A_barfoo(a, 1);
|
||||
if (!exception_order_SWIG_PendingException_get()) {
|
||||
fprintf(stderr, "barfoo(1): bad exception order\n");
|
||||
} else {
|
||||
SWIG_PendingException_reset();
|
||||
exception_order_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
A_barfoo(a, 2);
|
||||
if (!SWIG_PendingException_get()) {
|
||||
exception_order_A_barfoo(a, 2);
|
||||
if (!exception_order_SWIG_PendingException_get()) {
|
||||
fprintf(stderr, "barfoo(2): bad exception order\n");
|
||||
} else {
|
||||
SWIG_PendingException_reset();
|
||||
exception_order_SWIG_PendingException_reset();
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
|
|
@ -6,8 +6,8 @@ int main(int argc, const char *argv[])
|
|||
{
|
||||
global_vars_init();
|
||||
|
||||
assert(strcmp(b_get(), "string b") == 0);
|
||||
assert(x == 1234);
|
||||
assert(strcmp(global_vars_b_get(), "string b") == 0);
|
||||
assert(global_vars_x_get() == 1234);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
int main(int argc, const char *argv[]) {
|
||||
{
|
||||
Klass* k = Klass_new_rcstd_string("me oh my");
|
||||
assert( strcmp(Klass_getValue(k), "me oh my") == 0 );
|
||||
Klass_delete(k);
|
||||
li_boost_shared_ptr_Klass* k = li_boost_shared_ptr_Klass_new_rcstd_string("me oh my");
|
||||
assert( strcmp(li_boost_shared_ptr_Klass_getValue(k), "me oh my") == 0 );
|
||||
li_boost_shared_ptr_Klass_delete(k);
|
||||
}
|
||||
|
||||
{
|
||||
Klass* k = li_boost_shared_ptr_factorycreate();
|
||||
assert( strcmp(Klass_getValue(k), "factorycreate") == 0 );
|
||||
Klass_delete(k);
|
||||
li_boost_shared_ptr_Klass* k = li_boost_shared_ptr_factorycreate();
|
||||
assert( strcmp(li_boost_shared_ptr_Klass_getValue(k), "factorycreate") == 0 );
|
||||
li_boost_shared_ptr_Klass_delete(k);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,25 +2,25 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
A* a1 = A_new_i(3);
|
||||
A* a2 = A_new_i(7);
|
||||
li_std_map_A* a1 = li_std_map_A_new_i(3);
|
||||
li_std_map_A* a2 = li_std_map_A_new_i(7);
|
||||
|
||||
mapA* mA = mapA_new();
|
||||
mapA_set(mA, 1, a1);
|
||||
mapA_set(mA, 2, a2);
|
||||
li_std_map_mapA* mA = li_std_map_mapA_new();
|
||||
li_std_map_mapA_set(mA, 1, a1);
|
||||
li_std_map_mapA_set(mA, 2, a2);
|
||||
|
||||
assert( mapA_size(mA) == 2 );
|
||||
assert( li_std_map_mapA_size(mA) == 2 );
|
||||
|
||||
{
|
||||
A* a = mapA_get(mA, 1);
|
||||
assert( A_val_get(a) == 3 );
|
||||
li_std_map_A* a = li_std_map_mapA_get(mA, 1);
|
||||
assert( li_std_map_A_val_get(a) == 3 );
|
||||
}
|
||||
|
||||
assert( !mapA_has_key(mA, 3) );
|
||||
assert( !li_std_map_mapA_has_key(mA, 3) );
|
||||
|
||||
mapA_delete(mA);
|
||||
A_delete(a2);
|
||||
A_delete(a1);
|
||||
li_std_map_mapA_delete(mA);
|
||||
li_std_map_A_delete(a2);
|
||||
li_std_map_A_delete(a1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,42 @@
|
|||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "li_std_pair/li_std_pair_wrap.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
{
|
||||
IntPair* intPair = makeIntPair(7, 6);
|
||||
assert(IntPair_first_get(intPair)==7 && IntPair_second_get(intPair)==6);
|
||||
li_std_pair_IntPair* intPair = li_std_pair_makeIntPair(7, 6);
|
||||
assert(li_std_pair_IntPair_first_get(intPair)==7 && li_std_pair_IntPair_second_get(intPair)==6);
|
||||
|
||||
assert(product1(intPair) == 42);
|
||||
assert(product2(intPair) == 42);
|
||||
assert(product3(intPair) == 42);
|
||||
assert(li_std_pair_product1(intPair) == 42);
|
||||
assert(li_std_pair_product2(intPair) == 42);
|
||||
assert(li_std_pair_product3(intPair) == 42);
|
||||
|
||||
IntPair_delete(intPair);
|
||||
li_std_pair_IntPair_delete(intPair);
|
||||
}
|
||||
|
||||
{
|
||||
IntPair* intPairPtr = makeIntPairPtr(7, 6);
|
||||
assert(IntPair_first_get(intPairPtr)==7 && IntPair_second_get(intPairPtr)==6);
|
||||
li_std_pair_IntPair* intPairPtr = li_std_pair_makeIntPairPtr(7, 6);
|
||||
assert(li_std_pair_IntPair_first_get(intPairPtr)==7 && li_std_pair_IntPair_second_get(intPairPtr)==6);
|
||||
|
||||
assert(product1(intPairPtr) == 42);
|
||||
assert(product2(intPairPtr) == 42);
|
||||
assert(product3(intPairPtr) == 42);
|
||||
assert(li_std_pair_product1(intPairPtr) == 42);
|
||||
assert(li_std_pair_product2(intPairPtr) == 42);
|
||||
assert(li_std_pair_product3(intPairPtr) == 42);
|
||||
}
|
||||
|
||||
{
|
||||
IntPair* intPairRef = makeIntPairRef(7, 6);
|
||||
assert(IntPair_first_get(intPairRef)==7 && IntPair_second_get(intPairRef)==6);
|
||||
li_std_pair_IntPair* intPairRef = li_std_pair_makeIntPairRef(7, 6);
|
||||
assert(li_std_pair_IntPair_first_get(intPairRef)==7 && li_std_pair_IntPair_second_get(intPairRef)==6);
|
||||
|
||||
assert(product1(intPairRef) == 42);
|
||||
assert(product2(intPairRef) == 42);
|
||||
assert(product3(intPairRef) == 42);
|
||||
assert(li_std_pair_product1(intPairRef) == 42);
|
||||
assert(li_std_pair_product2(intPairRef) == 42);
|
||||
assert(li_std_pair_product3(intPairRef) == 42);
|
||||
}
|
||||
|
||||
{
|
||||
IntPair* intPairConstRef = makeIntPairConstRef(7, 6);
|
||||
assert(IntPair_first_get(intPairConstRef)==7 && IntPair_second_get(intPairConstRef)==6);
|
||||
li_std_pair_IntPair* intPairConstRef = li_std_pair_makeIntPairConstRef(7, 6);
|
||||
assert(li_std_pair_IntPair_first_get(intPairConstRef)==7 && li_std_pair_IntPair_second_get(intPairConstRef)==6);
|
||||
|
||||
assert(product1(intPairConstRef) == 42);
|
||||
assert(product2(intPairConstRef) == 42);
|
||||
assert(product3(intPairConstRef) == 42);
|
||||
assert(li_std_pair_product1(intPairConstRef) == 42);
|
||||
assert(li_std_pair_product2(intPairConstRef) == 42);
|
||||
assert(li_std_pair_product3(intPairConstRef) == 42);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,30 +3,30 @@
|
|||
|
||||
int main() {
|
||||
{
|
||||
IntSet* is = IntSet_new();
|
||||
li_std_set_IntSet* is = li_std_set_IntSet_new();
|
||||
|
||||
IntSet_add(is, 1);
|
||||
IntSet_add(is, 4);
|
||||
IntSet_add(is, 9);
|
||||
li_std_set_IntSet_add(is, 1);
|
||||
li_std_set_IntSet_add(is, 4);
|
||||
li_std_set_IntSet_add(is, 9);
|
||||
|
||||
assert( IntSet_size(is) == 3 );
|
||||
assert( IntSet_has(is, 4) );
|
||||
assert( !IntSet_has(is, 16) );
|
||||
assert( li_std_set_IntSet_size(is) == 3 );
|
||||
assert( li_std_set_IntSet_has(is, 4) );
|
||||
assert( !li_std_set_IntSet_has(is, 16) );
|
||||
|
||||
IntSet_delete(is);
|
||||
li_std_set_IntSet_delete(is);
|
||||
}
|
||||
|
||||
{
|
||||
StringSet* ss = StringSet_new();
|
||||
li_std_set_StringSet* ss = li_std_set_StringSet_new();
|
||||
|
||||
StringSet_add(ss, "foo");
|
||||
StringSet_add(ss, "bar");
|
||||
li_std_set_StringSet_add(ss, "foo");
|
||||
li_std_set_StringSet_add(ss, "bar");
|
||||
|
||||
assert( StringSet_size(ss) == 2 );
|
||||
assert( StringSet_has(ss, "bar") );
|
||||
assert( !StringSet_has(ss, "baz") );
|
||||
assert( li_std_set_StringSet_size(ss) == 2 );
|
||||
assert( li_std_set_StringSet_has(ss, "bar") );
|
||||
assert( !li_std_set_StringSet_has(ss, "baz") );
|
||||
|
||||
StringSet_delete(ss);
|
||||
li_std_set_StringSet_delete(ss);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -4,19 +4,19 @@
|
|||
int main() {
|
||||
size_t i;
|
||||
|
||||
IntVector* iv = IntVector_new();
|
||||
assert( IntVector_size(iv) == 0 );
|
||||
li_std_vector_IntVector* iv = li_std_vector_IntVector_new();
|
||||
assert( li_std_vector_IntVector_size(iv) == 0 );
|
||||
|
||||
IntVector_push_back(iv, 1);
|
||||
IntVector_push_back(iv, 4);
|
||||
IntVector_push_back(iv, 9);
|
||||
assert( IntVector_size(iv) == 3 );
|
||||
li_std_vector_IntVector_push_back(iv, 1);
|
||||
li_std_vector_IntVector_push_back(iv, 4);
|
||||
li_std_vector_IntVector_push_back(iv, 9);
|
||||
assert( li_std_vector_IntVector_size(iv) == 3 );
|
||||
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
assert( IntVector_get(iv, i) == (i + 1)*(i + 1) );
|
||||
assert( li_std_vector_IntVector_get(iv, i) == (i + 1)*(i + 1) );
|
||||
}
|
||||
|
||||
IntVector_delete(iv);
|
||||
li_std_vector_IntVector_delete(iv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SWIG_DEFINE_WRAPPER_ALIASES
|
||||
#include "operator_overload/operator_overload_wrap.h"
|
||||
|
||||
#define assert(x,msg) if (!x) { printf("%d: %s\n", x, msg); exit(1); }
|
||||
|
||||
int main() {
|
||||
Op_sanity_check();
|
||||
operator_overload_Op_sanity_check();
|
||||
|
||||
Op *op1 = Op_new_i(1), *op2 = Op_new_i(2), *op3 = Op_copy(op1);
|
||||
operator_overload_Op *op1 = operator_overload_Op_new_i(1), *op2 = operator_overload_Op_new_i(2), *op3 = operator_overload_Op_copy(op1);
|
||||
|
||||
assert(Op_NotEqual(op1, op2), "neq failed");
|
||||
Op_PlusPlusPrefix(op3);
|
||||
assert(Op_EqualEqual(op2, op3), "eqeq failed");
|
||||
assert(Op_GreaterThanEqual(op2, op1), "geq failed");
|
||||
Op_PlusEqual(op3, op1);
|
||||
assert(Op_LessThan(op1, op2) && Op_LessThan(op2, op3), "lt failed");
|
||||
assert(3 == *Op_IndexInto(op3, Op_IndexIntoConst(op2, Op_Functor(op1))), "[] or () failed");
|
||||
assert(5 == Op_Functor_i(op3, 2), "f(x) failed");
|
||||
assert(operator_overload_Op_NotEqual(op1, op2), "neq failed");
|
||||
operator_overload_Op_PlusPlusPrefix(op3);
|
||||
assert(operator_overload_Op_EqualEqual(op2, op3), "eqeq failed");
|
||||
assert(operator_overload_Op_GreaterThanEqual(op2, op1), "geq failed");
|
||||
operator_overload_Op_PlusEqual(op3, op1);
|
||||
assert(operator_overload_Op_LessThan(op1, op2) && operator_overload_Op_LessThan(op2, op3), "lt failed");
|
||||
assert(3 == *operator_overload_Op_IndexInto(op3, operator_overload_Op_IndexIntoConst(op2, operator_overload_Op_Functor(op1))), "[] or () failed");
|
||||
assert(5 == operator_overload_Op_Functor_i(op3, 2), "f(x) failed");
|
||||
|
||||
Op_delete(op1);
|
||||
Op_delete(op2);
|
||||
Op_delete(op3);
|
||||
operator_overload_Op_delete(op1);
|
||||
operator_overload_Op_delete(op2);
|
||||
operator_overload_Op_delete(op3);
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,19 @@ struct ExtendMe {
|
|||
};
|
||||
%}
|
||||
|
||||
// Use different names for the C backend to be consistent with the global prefix used.
|
||||
%inline {
|
||||
#ifdef SWIGC
|
||||
%#define ADD_PREFIX(name) memberin_extend_ ## name
|
||||
#else
|
||||
%#define ADD_PREFIX(name) name
|
||||
#endif
|
||||
}
|
||||
|
||||
%{
|
||||
#include <map>
|
||||
std::map<ExtendMe*, char *> ExtendMeStringMap;
|
||||
void ExtendMe_thing_set(ExtendMe *self, const char *val) {
|
||||
void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) {
|
||||
char *old_val = ExtendMeStringMap[self];
|
||||
delete [] old_val;
|
||||
if (val) {
|
||||
|
@ -22,7 +31,7 @@ void ExtendMe_thing_set(ExtendMe *self, const char *val) {
|
|||
ExtendMeStringMap[self] = 0;
|
||||
}
|
||||
}
|
||||
char * ExtendMe_thing_get(ExtendMe *self) {
|
||||
char * ADD_PREFIX(ExtendMe_thing_get)(ExtendMe *self) {
|
||||
return ExtendMeStringMap[self];
|
||||
}
|
||||
%}
|
||||
|
|
|
@ -10,15 +10,20 @@ namespace foo {
|
|||
}
|
||||
%}
|
||||
|
||||
// C uses different naming convention, with all functions starting with the class prefix.
|
||||
// C uses different naming convention, with all functions starting with the class prefix
|
||||
// and using the global namespace prefix too, if specified (which is the case for the tests).
|
||||
#ifdef SWIGC
|
||||
%{
|
||||
foo::bar *foo_bar_new() {
|
||||
foo::bar *namespace_extend_foo_bar_new() {
|
||||
return new foo::bar;
|
||||
}
|
||||
void foo_bar_delete(foo::bar *self) {
|
||||
void namespace_extend_foo_bar_delete(foo::bar *self) {
|
||||
delete self;
|
||||
}
|
||||
|
||||
int namespace_extend_foo_bar_blah(foo::bar *self, int x) {
|
||||
return x;
|
||||
}
|
||||
%}
|
||||
#else
|
||||
%{
|
||||
|
@ -28,14 +33,12 @@ foo::bar *new_foo_bar() {
|
|||
void delete_foo_bar(foo::bar *self) {
|
||||
delete self;
|
||||
}
|
||||
%}
|
||||
#endif
|
||||
|
||||
%{
|
||||
int foo_bar_blah(foo::bar *self, int x) {
|
||||
return x;
|
||||
}
|
||||
%}
|
||||
#endif
|
||||
|
||||
namespace foo {
|
||||
class bar {
|
||||
|
|
|
@ -173,7 +173,6 @@ class C:public Language {
|
|||
File *f_wrappers_cxx;
|
||||
File *f_wrappers_types;
|
||||
File *f_wrappers_decl;
|
||||
File *f_wrappers_aliases;
|
||||
File *f_init;
|
||||
|
||||
String *empty_string;
|
||||
|
@ -567,10 +566,6 @@ public:
|
|||
f_wrappers_types = NewString("");
|
||||
f_wrappers_decl = NewString("");
|
||||
|
||||
// We may also define aliases for the global wrapper functions to allow calling them using their original names, but as this can result in problems (as
|
||||
// usual when using the preprocessor), this is only done when SWIG_DEFINE_WRAPPER_ALIASES is defined, so use a separate section for this.
|
||||
f_wrappers_aliases = NIL;
|
||||
|
||||
{
|
||||
|
||||
cplusplus_output_guard
|
||||
|
@ -589,13 +584,6 @@ public:
|
|||
|
||||
Dump(f_wrappers_h_body, f_wrappers_h);
|
||||
Delete(f_wrappers_h_body);
|
||||
|
||||
if (f_wrappers_aliases) {
|
||||
Dump(f_wrappers_aliases, f_wrappers_h);
|
||||
Delete(f_wrappers_aliases);
|
||||
|
||||
Printv(f_wrappers_h, "#endif /* SWIG_DEFINE_WRAPPER_ALIASES */\n", NIL);
|
||||
}
|
||||
} // close wrapper header guard
|
||||
|
||||
// write all to the file
|
||||
|
@ -813,7 +801,7 @@ public:
|
|||
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
||||
emit_wrapper_func_decl(n, name, wname);
|
||||
emit_wrapper_func_decl(n, wname);
|
||||
|
||||
// cleanup
|
||||
Delete(proto);
|
||||
|
@ -955,25 +943,14 @@ public:
|
|||
* emit_wrapper_func_decl()
|
||||
*
|
||||
* Declares the wrapper function, using the C types used for it, in the header.
|
||||
* Also emits a define allowing to use the function without the "_wrap_" prefix.
|
||||
* The node here is a function declaration.
|
||||
* ---------------------------------------------------------------------- */
|
||||
void emit_wrapper_func_decl(Node *n, String *name, String *wname)
|
||||
void emit_wrapper_func_decl(Node *n, String *wname)
|
||||
{
|
||||
current_output = output_wrapper_decl;
|
||||
|
||||
// add function declaration to the proxy header file
|
||||
Printv(f_wrappers_decl, "SWIGIMPORT ", get_wrapper_func_return_type(n).get(), " ", wname, get_wrapper_func_proto(n).get(), ";\n\n", NIL);
|
||||
|
||||
if (Cmp(name, wname) != 0) {
|
||||
if (!f_wrappers_aliases) {
|
||||
// Allocate it on demand.
|
||||
f_wrappers_aliases = NewStringEmpty();
|
||||
Printv(f_wrappers_aliases, "#ifdef SWIG_DEFINE_WRAPPER_ALIASES\n", NIL);
|
||||
}
|
||||
|
||||
Printf(f_wrappers_aliases, "#define %s %s\n", name, wname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1153,7 +1130,7 @@ public:
|
|||
// cleanup
|
||||
DelWrapper(wrapper);
|
||||
|
||||
emit_wrapper_func_decl(n, name, wname);
|
||||
emit_wrapper_func_decl(n, wname);
|
||||
|
||||
Delete(name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue