swig/Examples/test-suite/c/cpp_enum_runme.c
Vadim Zeitlin e8f9bdba80 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
2021-11-10 02:11:59 +01:00

72 lines
1.8 KiB
C

#include "cpp_enum/cpp_enum_wrap.h"
#include <assert.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
// We don't have "enum SOME_ENUM"
int e = cpp_enum_ENUM_ONE, *p;
// check the constructor's default value
cpp_enum_StructWithEnums *s = cpp_enum_StructWithEnums_new();
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_ONE);
// check setter
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
cpp_enum_StructWithEnums_enum_test1(s, e, &e, &e);
// check function call
cpp_enum_StructWithEnums_enum_test2(s, e, &e, &e);
// check function call
assert(cpp_enum_StructWithEnums_enum_test3(s) == cpp_enum_ENUM_ONE);
// check function call
assert(cpp_enum_StructWithEnums_enum_test4(s) == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test5(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test6(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test7(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test8(s);
assert(*p == cpp_enum_ENUM_TWO);
cpp_enum_StructWithEnums_delete(s);
cpp_enum_Foo *f = cpp_enum_Foo_new();
// check the constructor's default value
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hello);
cpp_enum_Foo_hola_set(f, cpp_enum_Foo_Hi);
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hi);
cpp_enum_Foo_delete(f);
//check C enum
cpp_enum_hi_set(cpp_enum_Hi);
cpp_enum_hi_set(cpp_enum_Hello);
// check typedef enum
cpp_enum_play_state t;
t = cpp_enum_PLAY;
assert(t == 1);
t = cpp_enum_STOP;
assert(t == 0);
return 0;
}