"Fossies" - the Fresh Open Source Software Archive

Member "icinga2-2.10.5/test/base-string.cpp" (23 May 2019, 3247 Bytes) of package /linux/misc/icinga2-2.10.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "base-string.cpp": 2.10.0_vs_2.10.1.

    1 /******************************************************************************
    2  * Icinga 2                                                                   *
    3  * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
    4  *                                                                            *
    5  * This program is free software; you can redistribute it and/or              *
    6  * modify it under the terms of the GNU General Public License                *
    7  * as published by the Free Software Foundation; either version 2             *
    8  * of the License, or (at your option) any later version.                     *
    9  *                                                                            *
   10  * This program is distributed in the hope that it will be useful,            *
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
   13  * GNU General Public License for more details.                               *
   14  *                                                                            *
   15  * You should have received a copy of the GNU General Public License          *
   16  * along with this program; if not, write to the Free Software Foundation     *
   17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
   18  ******************************************************************************/
   19 
   20 #include "base/string.hpp"
   21 #include <BoostTestTargetConfig.h>
   22 
   23 using namespace icinga;
   24 
   25 BOOST_AUTO_TEST_SUITE(base_string)
   26 
   27 BOOST_AUTO_TEST_CASE(construct)
   28 {
   29     BOOST_CHECK(String() == "");
   30     BOOST_CHECK(String(5, 'n') == "nnnnn");
   31 }
   32 
   33 BOOST_AUTO_TEST_CASE(equal)
   34 {
   35     BOOST_CHECK(String("hello") == String("hello"));
   36     BOOST_CHECK("hello" == String("hello"));
   37     BOOST_CHECK(String("hello") == String("hello"));
   38 
   39     BOOST_CHECK(String("hello") != String("helloworld"));
   40     BOOST_CHECK("hello" != String("helloworld"));
   41     BOOST_CHECK(String("hello") != "helloworld");
   42 }
   43 
   44 BOOST_AUTO_TEST_CASE(clear)
   45 {
   46     String s = "hello";
   47     s.Clear();
   48     BOOST_CHECK(s == "");
   49     BOOST_CHECK(s.IsEmpty());
   50 }
   51 
   52 BOOST_AUTO_TEST_CASE(append)
   53 {
   54     String s;
   55     s += "he";
   56     s += String("ll");
   57     s += 'o';
   58 
   59     BOOST_CHECK(s == "hello");
   60 }
   61 
   62 BOOST_AUTO_TEST_CASE(trim)
   63 {
   64     String s1 = "hello";
   65     BOOST_CHECK(s1.Trim() == "hello");
   66 
   67     String s2 = "  hello";
   68     BOOST_CHECK(s2.Trim() == "hello");
   69 
   70     String s3 = "hello ";
   71     BOOST_CHECK(s3.Trim() == "hello");
   72 
   73     String s4 = " hello ";
   74     BOOST_CHECK(s4.Trim() == "hello");
   75 }
   76 
   77 BOOST_AUTO_TEST_CASE(contains)
   78 {
   79     String s1 = "hello world";
   80     String s2 = "hello";
   81     BOOST_CHECK(s1.Contains(s2));
   82 
   83     String s3 = "  hello world  ";
   84     String s4 = "  hello";
   85     BOOST_CHECK(s3.Contains(s4));
   86 
   87     String s5 = "  hello world  ";
   88     String s6 = "world  ";
   89     BOOST_CHECK(s5.Contains(s6));
   90 }
   91 
   92 BOOST_AUTO_TEST_CASE(replace)
   93 {
   94     String s = "hello";
   95 
   96     s.Replace(0, 2, "x");
   97     BOOST_CHECK(s == "xllo");
   98 }
   99 
  100 BOOST_AUTO_TEST_CASE(index)
  101 {
  102     String s = "hello";
  103     BOOST_CHECK(s[0] == 'h');
  104 
  105     s[0] = 'x';
  106     BOOST_CHECK(s == "xello");
  107 
  108     for (char& ch : s) {
  109         ch = 'y';
  110     }
  111     BOOST_CHECK(s == "yyyyy");
  112 }
  113 
  114 BOOST_AUTO_TEST_CASE(find)
  115 {
  116     String s = "hello";
  117     BOOST_CHECK(s.Find("ll") == 2);
  118     BOOST_CHECK(s.FindFirstOf("xl") == 2);
  119 }
  120 
  121 BOOST_AUTO_TEST_SUITE_END()