1/* Self tests for child_path for GDB, the GNU debugger. 2 3 Copyright (C) 2019-2020 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20#include "defs.h" 21#include "gdbsupport/pathstuff.h" 22#include "gdbsupport/selftest.h" 23 24namespace selftests { 25namespace child_path { 26 27/* Verify the result of a single child_path test. */ 28 29static bool 30child_path_check (const char *parent, const char *child, const char *expected) 31{ 32 const char *result = ::child_path (parent, child); 33 if (result == NULL || expected == NULL) 34 return result == expected; 35 return strcmp (result, expected) == 0; 36} 37 38/* Test child_path. */ 39 40static void 41test () 42{ 43 SELF_CHECK (child_path_check ("/one", "/two", NULL)); 44 SELF_CHECK (child_path_check ("/one", "/one", NULL)); 45 SELF_CHECK (child_path_check ("/one", "/one/", NULL)); 46 SELF_CHECK (child_path_check ("/one", "/one//", NULL)); 47 SELF_CHECK (child_path_check ("/one", "/one/two", "two")); 48 SELF_CHECK (child_path_check ("/one/", "/two", NULL)); 49 SELF_CHECK (child_path_check ("/one/", "/one", NULL)); 50 SELF_CHECK (child_path_check ("/one/", "/one/", NULL)); 51 SELF_CHECK (child_path_check ("/one/", "/one//", NULL)); 52 SELF_CHECK (child_path_check ("/one/", "/one/two", "two")); 53 SELF_CHECK (child_path_check ("/one/", "/one//two", "two")); 54 SELF_CHECK (child_path_check ("/one/", "/one//two/", "two/")); 55 SELF_CHECK (child_path_check ("/one", "/onetwo", NULL)); 56 SELF_CHECK (child_path_check ("/one", "/onetwo/three", NULL)); 57} 58 59} 60} 61 62void _initialize_child_path_selftests (); 63void 64_initialize_child_path_selftests () 65{ 66 selftests::register_test ("child_path", 67 selftests::child_path::test); 68} 69 70