Blame gnulib-tests/test-filenamecat.c

Packit 33f14e
/* Test of concatenation of two arbitrary file names.
Packit 33f14e
Packit 33f14e
   Copyright (C) 1996-2007, 2009-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Jim Meyering.  */
Packit 33f14e
Packit 33f14e
#include <config.h>
Packit 33f14e
Packit 33f14e
#include "filenamecat.h"
Packit 33f14e
Packit 33f14e
#include <stdbool.h>
Packit 33f14e
#include <stdio.h>
Packit 33f14e
#include <stdlib.h>
Packit 33f14e
#include <string.h>
Packit 33f14e
Packit 33f14e
Packit 33f14e
int
Packit 33f14e
main (int argc _GL_UNUSED, char *argv[])
Packit 33f14e
{
Packit 33f14e
  static char const *const tests[][3] =
Packit 33f14e
    {
Packit 33f14e
      {"a", "b",   "a/b"},
Packit 33f14e
      {"a/", "b",  "a/b"},
Packit 33f14e
      {"a/", "/b", "a/b"},
Packit 33f14e
      {"a", "/b",  "a/b"},
Packit 33f14e
Packit 33f14e
      {"/", "b",  "/b"},
Packit 33f14e
      {"/", "/b", "/b"},
Packit 33f14e
      {"/", "/",  "/"},
Packit 33f14e
      {"a", "/",  "a/"},   /* this might deserve a diagnostic */
Packit 33f14e
      {"/a", "/", "/a/"},  /* this might deserve a diagnostic */
Packit 33f14e
      {"a", "//b",  "a/b"},
Packit 33f14e
      {"", "a", "a"},  /* this might deserve a diagnostic */
Packit 33f14e
    };
Packit 33f14e
  unsigned int i;
Packit 33f14e
  bool fail = false;
Packit 33f14e
Packit 33f14e
  for (i = 0; i < sizeof tests / sizeof tests[0]; i++)
Packit 33f14e
    {
Packit 33f14e
      char *base_in_result;
Packit 33f14e
      char const *const *t = tests[i];
Packit 33f14e
      char *res = file_name_concat (t[0], t[1], &base_in_result);
Packit 33f14e
      if (strcmp (res, t[2]) != 0)
Packit 33f14e
        {
Packit 33f14e
          fprintf (stderr, "test #%u: got %s, expected %s\n", i, res, t[2]);
Packit 33f14e
          fail = true;
Packit 33f14e
        }
Packit 33f14e
    }
Packit 33f14e
  exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
Packit 33f14e
}