root/test/util/opal_basename.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. test

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 #include "ompi_config.h"
  21 
  22 #include <stdio.h>
  23 #include <string.h>
  24 #include <stdlib.h>
  25 
  26 #include "support.h"
  27 #include "opal/util/basename.h"
  28 #include "opal/util/printf.h"
  29 
  30 
  31 static void test(const char* in, const char* out);
  32 
  33 
  34 int main(int argc, char* argv[])
  35 {
  36   test_init("opal_basename()");
  37 
  38   test("foo.txt", "foo.txt");
  39   test("/foo/bar/baz", "baz");
  40   test("/yow.c", "yow.c");
  41   test("/", "/");
  42 
  43   test("foo.txt/", "foo.txt");
  44   test("/foo/bar/baz/", "baz");
  45   test("/yow.c/", "yow.c");
  46   test("//", "/");
  47 
  48   /* All done */
  49   return test_finalize();
  50 }
  51 
  52 
  53 void test(const char* in, const char* out)
  54 {
  55     char *msg;
  56     char *ret = opal_basename(in);
  57 
  58     if (0 == strcmp(ret, out)) {
  59         test_success();
  60     } else {
  61         opal_asprintf(&msg, "Mismatch: input \"%s\", expected \"%s\", got \"%s\"\n",
  62                  in, out, ret);
  63         test_failure(msg);
  64         free(msg);
  65     }
  66     if (NULL != ret) {
  67         free(ret);
  68     }
  69 }
  70 
  71 

/* [<][>][^][v][top][bottom][index][help] */