
Enabling -Wmissing-declarations points out that a bunch of function in the unittests can be made static, do that. gdb/ChangeLog: * unittests/array-view-selftests.c (check_ptr_size_ctor2): Make static. * unittests/basic_string_view/capacity/1.cc (test01): Likewise. * unittests/basic_string_view/cons/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/cons/char/2.cc (test03): Likewise. (main): Likewise. * unittests/basic_string_view/cons/char/3.cc (test05): Likewise. (main): Likewise. * unittests/basic_string_view/element_access/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/element_access/char/empty.cc (main): Likewise. * unittests/basic_string_view/element_access/char/front_back.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/inserters/char/2.cc (test05): Likewise. (main): Likewise. * unittests/basic_string_view/modifiers/remove_prefix/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/modifiers/remove_suffix/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/modifiers/swap/char/1.cc (test01): Likewise. * unittests/basic_string_view/operations/compare/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operations/compare/char/13650.cc (test01): Likewise. * unittests/basic_string_view/operations/copy/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operations/data/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operations/find/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operations/find/char/2.cc (test02): Likewise. (main): Likewise. * unittests/basic_string_view/operations/find/char/3.cc (test03): Likewise. (main): Likewise. * unittests/basic_string_view/operations/find/char/4.cc (main): Likewise. * unittests/basic_string_view/operations/rfind/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operations/rfind/char/2.cc (test02): Likewise. (main): Likewise. * unittests/basic_string_view/operations/rfind/char/3.cc (test03): Likewise. (main): Likewise. * unittests/basic_string_view/operations/substr/char/1.cc (test01): Likewise. (main): Likewise. * unittests/basic_string_view/operators/char/2.cc (main): Likewise. * unittests/optional/assignment/1.cc (test): Likewise. * unittests/optional/assignment/2.cc (test): Likewise. * unittests/optional/assignment/3.cc (test): Likewise. * unittests/optional/assignment/4.cc (test): Likewise. * unittests/optional/assignment/5.cc (test): Likewise. * unittests/optional/assignment/6.cc (test): Likewise. * unittests/optional/assignment/7.cc (test): Likewise. * unittests/optional/cons/copy.cc (test): Likewise. * unittests/optional/cons/default.cc (test): Likewise. * unittests/optional/cons/move.cc (test): Likewise. * unittests/optional/cons/value.cc (test): Likewise. * unittests/optional/in_place.cc (test): Likewise. * unittests/optional/observers/1.cc (test): Likewise. * unittests/optional/observers/2.cc (test): Likewise. Change-Id: I66626db864cb877cacc570d4660df633530554f5
132 lines
4 KiB
C++
132 lines
4 KiB
C++
// { dg-options "-std=gnu++17" }
|
|
|
|
// Copyright (C) 2013-2019 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING3. If not see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
// basic_string_view::compare
|
|
// int compare(const basic_string_view& str) const;
|
|
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
|
|
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
|
// size_type pos2, size_type n2) const;
|
|
// int compare(const charT* s) const;
|
|
// int compare(size_type pos1, size_type n1,
|
|
// const charT* s, size_type n2 = npos) const;
|
|
|
|
// NB compare should be thought of as a lexographical compare, ie how
|
|
// things would be sorted in a dictionary.
|
|
|
|
namespace operations_compare_1 {
|
|
|
|
enum want_value {lt=0, z=1, gt=2};
|
|
|
|
int
|
|
test_value(int result, want_value expected);
|
|
|
|
int
|
|
test_value(int result, want_value expected)
|
|
{
|
|
bool pass = false;
|
|
|
|
switch (expected) {
|
|
case lt:
|
|
if (result < 0)
|
|
pass = true;
|
|
break;
|
|
case z:
|
|
if (!result)
|
|
pass = true;
|
|
break;
|
|
case gt:
|
|
if (result > 0)
|
|
pass = true;
|
|
break;
|
|
default:
|
|
pass = false; //should not get here
|
|
}
|
|
VERIFY(pass);
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
test01 ()
|
|
{
|
|
using gdb::string_view;
|
|
|
|
string_view str_0("costa rica");
|
|
string_view str_1("costa marbella");
|
|
string_view str_2;
|
|
|
|
//sanity check
|
|
test_value(strcmp("costa marbella", "costa rica"), lt);
|
|
test_value(strcmp("costa rica", "costa rica"), z);
|
|
test_value(strcmp(str_1.data(), str_0.data()), lt);
|
|
test_value(strcmp(str_0.data(), str_1.data()), gt);
|
|
test_value(strncmp(str_1.data(), str_0.data(), 6), z);
|
|
test_value(strncmp(str_1.data(), str_0.data(), 14), lt);
|
|
test_value(memcmp(str_1.data(), str_0.data(), 6), z);
|
|
test_value(memcmp(str_1.data(), str_0.data(), 10), lt);
|
|
test_value(memcmp("costa marbella", "costa rica", 10), lt);
|
|
|
|
// int compare(const basic_string_view& str) const;
|
|
test_value(str_0.compare(str_1), gt); //because r>m
|
|
test_value(str_1.compare(str_0), lt); //because m<r
|
|
str_2 = str_0;
|
|
test_value(str_2.compare(str_0), z);
|
|
str_2 = "cost";
|
|
test_value(str_2.compare(str_0), lt);
|
|
str_2 = "costa ricans";
|
|
test_value(str_2.compare(str_0), gt);
|
|
|
|
// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
|
|
test_value(str_1.compare(0, 6, str_0), lt);
|
|
str_2 = "cost";
|
|
test_value(str_1.compare(0, 4, str_2), z);
|
|
test_value(str_1.compare(0, 5, str_2), gt);
|
|
|
|
// int compare(size_type pos1, size_type n1, const basic_string_view& str,
|
|
// size_type pos2, size_type n2) const;
|
|
test_value(str_1.compare(0, 6, str_0, 0, 6), z);
|
|
test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
|
|
test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
|
|
|
|
// int compare(const charT* s) const;
|
|
test_value(str_0.compare("costa marbella"), gt);
|
|
test_value(str_1.compare("costa rica"), lt);
|
|
str_2 = str_0;
|
|
test_value(str_2.compare("costa rica"), z);
|
|
test_value(str_2.compare("cost"), gt);
|
|
test_value(str_2.compare("costa ricans"), lt);
|
|
|
|
// int compare(size_type pos, size_type n1, const charT* str,
|
|
// size_type n2 = npos) const;
|
|
test_value(str_1.compare(0, 6, "costa rica", 0, 6), z);
|
|
test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt);
|
|
test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int
|
|
main ()
|
|
{
|
|
test01();
|
|
|
|
return 0;
|
|
}
|
|
|
|
} // namespace operations_compare_1
|