FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_regex.cc
1 /*********************************************************************
2 Copyright (C) 2014, Siemens AG
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 
24 #include "regex.hpp"
25 
26 
27 using namespace std;
28 
33 class regexTest : public CPPUNIT_NS :: TestFixture {
34  CPPUNIT_TEST_SUITE (regexTest);
35  CPPUNIT_TEST (regTest);
36 
37  CPPUNIT_TEST_SUITE_END ();
38 
39 protected:
49  void regTest (void) {
50 
51  std::string content = "This is copy of a copyright statement similar to copyleft found in copying";
52  rx::regex matchingRegex ("copy");
53 
54  std::string::const_iterator begin = content.begin();
55  std::string::const_iterator end = content.end();
56  rx::match_results<std::string::const_iterator> what;
57 
58  int nfound =0;
59  while (rx::regex_search(begin, end, what,matchingRegex)) {
60  nfound++;
61  begin = what[0].second;
62  }
63 
64  CPPUNIT_ASSERT_EQUAL (4, nfound);
65  };
66 
67 
68 
69 };
70 
71 CPPUNIT_TEST_SUITE_REGISTRATION( regexTest );
void regTest(void)
Test regex on a test string.
Definition: test_regex.cc:49
Test fixture to test regex accuracy.
Definition: test_regex.cc:33