Source

mpi3-fortran / ompi / mpi / fortran / tests / src / check_argv.c

Full commit
#include <string.h>
#include <stdio.h>

#define DEBUG_PRINT 1

int check_argv(char * argv, int len)
{
   char ** c_argv;

   char * fstr;
   char * cstr;

   fstr = argv;
   ompi_fortran_string_f2c(fstr, len, &cstr);
   printf("check_argv: len=%ld %s\n", strlen(cstr), cstr);

   fstr += len;
   ompi_fortran_string_f2c(fstr, len, &cstr);
   printf("check_argv: len=%ld %s\n", strlen(cstr), cstr);
   fstr += len;
   ompi_fortran_string_f2c(fstr, len, &cstr);
   printf("check_argv: len=%ld %s\n", strlen(cstr), cstr);

   ompi_fortran_argv_f2c(argv, len, len, &c_argv);


#ifdef DEBUG_PRINT
   printf("check_argv: %s\n", c_argv[0]);
   printf("check_argv: %s\n", c_argv[1]);
   if (c_argv[2] == NULL) printf("check_argv: is NULL terminated\n");
   else                   printf("check_argv: should be NULL: %s\n", c_argv[2]);
#endif

   if (strcmp(c_argv[0], "cmd1_arg1") != 0) return 1;
   if (strcmp(c_argv[1], "cmd1_arg2") != 0) return 1;

   if (c_argv[2] != NULL)                   return 1;

   return 0;
}

int check_argvs(int count, char * argvs, int len)
{
   char *** c_argvs;

   ompi_fortran_multiple_argvs_f2c(count, argvs, len, &c_argvs);

#ifdef DEBUG_PRINT
   printf("check_argvs: %s\n", c_argvs[0][0]);
   printf("check_argvs: %s\n", c_argvs[0][1]);
   printf("check_argvs: %s\n", c_argvs[1][0]);
   printf("check_argvs: %s\n", c_argvs[1][1]);
   if (c_argvs[0][3] == NULL) printf("check_argv: is NULL terminated\n");
   else                       printf("check_argv: should be NULL: %s\n", c_argvs[0][3]);
   if (c_argvs[0][3] == NULL) printf("check_argv: is NULL terminated\n");
   else                       printf("check_argv: should be NULL: %s\n", c_argvs[0][3]);
#endif

   if (strcmp(c_argvs[0][0], "cmd1_arg1") != 0) { printf("fail1\n"); return 1; }
   if (strcmp(c_argvs[0][1], "cmd1_arg2") != 0) { printf("fail2\n"); return 1; }
   if (strcmp(c_argvs[1][0], "cmd2_arg1") != 0) { printf("fail3\n"); return 1; }
   if (strcmp(c_argvs[1][1], "cmd2_arg2") != 0) { printf("fail4\n"); return 1; }

   if (c_argvs[0][3] != NULL)                   { printf("fail5\n"); return 1; }
   if (c_argvs[1][3] != NULL)                   { printf("fail6\n"); return 1; }

   return 0;
}