FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_regex.cc
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2014 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 
13 #include "regex.hpp"
14 
15 
16 using namespace std;
17 
22 class regexTest : public CPPUNIT_NS :: TestFixture {
23  CPPUNIT_TEST_SUITE (regexTest);
24  CPPUNIT_TEST (regTest);
25 
26  CPPUNIT_TEST_SUITE_END ();
27 
28 protected:
38  void regTest (void) {
39 
40  std::string content = "This is copy of a copyright statement similar to copyleft found in copying";
41  rx::regex matchingRegex ("copy");
42 
43  std::string::const_iterator begin = content.begin();
44  std::string::const_iterator end = content.end();
45  rx::match_results<std::string::const_iterator> what;
46 
47  int nfound =0;
48  while (rx::regex_search(begin, end, what,matchingRegex)) {
49  nfound++;
50  begin = what[0].second;
51  }
52 
53  CPPUNIT_ASSERT_EQUAL (4, nfound);
54  };
55 
56 
57 
58 };
59 
60 CPPUNIT_TEST_SUITE_REGISTRATION( regexTest );
Test fixture to test regex accuracy.
Definition: test_regex.cc:22
void regTest(void)
Test regex on a test string.
Definition: test_regex.cc:38