PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/java_lib_various.i

#
Swig | 51 lines | 39 code | 11 blank | 1 comment | 0 complexity | 6a2edcdc7ec5497086cbbcd07b4adf5b MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* Java various.i library tests */
  2. %module java_lib_various
  3. %include "various.i"
  4. %apply char **STRING_ARRAY { char **received };
  5. %apply char **STRING_ARRAY { char **get_names };
  6. %apply char **STRING_ARRAY { char **languages };
  7. %apply char *BYTE { char *chars };
  8. %apply char **STRING_OUT { char **string_ptr };
  9. %typemap(freearg) char **languages "" // don't delete memory when setting global variable
  10. %{
  11. char *langs[] = { (char *)"Hungarian", (char *)"Afrikaans", (char *)"Norwegian", NULL };
  12. %}
  13. %inline %{
  14. char **languages = &langs[0];
  15. %}
  16. %inline %{
  17. int check_animals(char **received) {
  18. const char *expected[] = {"Cat","Dog","Cow","Goat", 0};
  19. int strings_match = 1;
  20. int i=0;
  21. while (expected[i]) {
  22. if (strcmp(received[i], expected[i]) != 0)
  23. strings_match = 0;
  24. i++;
  25. }
  26. return strings_match;
  27. }
  28. char **get_names() {
  29. static char *values[] = { (char *)"Dave", (char *)"Mike", (char *)"Susan", (char *)"John", (char *)"Michelle", NULL};
  30. return &values[0];
  31. }
  32. void charout(char *chars) {
  33. if(chars != NULL)
  34. sprintf(chars, "by jove");
  35. }
  36. void char_ptr_ptr_out(char **string_ptr) {
  37. static char ret[] = "returned string";
  38. *string_ptr = ret;
  39. }
  40. %}