[mockitopp] r156 committed - correctly detect regex support in C++11-enable GCC 4.7 and 4.8. We fou...

2 views
Skip to first unread message

mock...@googlecode.com

unread,
Jun 11, 2013, 5:10:43 PM6/11/13
to mockit...@googlegroups.com
Revision: 156
Author: plazt...@gmail.com
Date: Tue Jun 11 14:10:23 2013
Log: correctly detect regex support in C++11-enable GCC 4.7 and 4.8.
We found that regex class in GCC is broken for bracked operators -- it does
not match when it should. Need to enhance the build to correctly detect
C++11-capable GCC/clang and turn on regex matcher tests.
http://code.google.com/p/mockitopp/source/detail?r=156

Modified:
/trunk/include/mockitopp/matchers/regex.hpp
/trunk/test/src/matchers/test_regex.cpp

=======================================
--- /trunk/include/mockitopp/matchers/regex.hpp Mon Sep 19 17:11:06 2011
+++ /trunk/include/mockitopp/matchers/regex.hpp Tue Jun 11 14:10:23 2013
@@ -13,6 +13,8 @@
namespace __tr1 = ::boost;
#elif defined(_GLIBCXX_TR1_REGEX) || defined(_REGEX_)
namespace __tr1 = ::std::tr1;
+ #elif defined(_GLIBCXX_REGEX)
+ namespace __tr1 = ::std;
#else
#error compatible tr1 regex header not found!
#endif
=======================================
--- /trunk/test/src/matchers/test_regex.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/matchers/test_regex.cpp Tue Jun 11 14:10:23 2013
@@ -1,4 +1,3 @@
-
#if defined(MOCKITOPP_STD_REGEX)
#include <regex>
#elif defined(MOCKITOPP_STD_TR1_REGEX)
@@ -9,6 +8,8 @@

#if defined(MOCKITOPP_STD_REGEX) || defined(MOCKITOPP_STD_TR1_REGEX) ||
defined(MOCKITOPP_BOOST_REGEX)

+/* gcc versions <= 4.8 do not fully support ECMAScript regular expressions
*/
+
#include "tpunit++.hpp"
#include <mockitopp/mockitopp.hpp>
#include <mockitopp/matchers/regex.hpp>
@@ -38,12 +39,16 @@
mock_object<regex_interface> mock;

mock(&regex_interface::const_char_s).when(regex(".*foo.*")).thenReturn("matches__.*foo.*");

mock(&regex_interface::const_char_s).when(regex(".*bar.*")).thenReturn("matches__.*bar.*");
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))

mock(&regex_interface::const_char_s).when(regex("[A-Z]*")).thenReturn("matches__[A-Z]*");
+#endif
regex_interface& obj = mock.getInstance();

ASSERT_EQUAL("matches__.*foo.*", obj.const_char_s("foo"));
ASSERT_EQUAL("matches__.*bar.*", obj.const_char_s("bar"));
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))
ASSERT_EQUAL("matches__[A-Z]*",
obj.const_char_s("ABCDEFGHIKLMNOPQRSTUVWXYZ"));
+#endif
ASSERT_THROW(obj.const_char_s("FOO-BAR"),
mockitopp::partial_implementation_exception);
ASSERT_THROW(obj.const_char_s("1234567890"),
mockitopp::partial_implementation_exception);
}
@@ -53,12 +58,16 @@
mock_object<regex_interface> mock;
mock(&regex_interface::std_string).when(regex<const
std::string&>(".*foo.*")).thenReturn("matches__.*foo.*");
mock(&regex_interface::std_string).when(regex<const
std::string&>(".*bar.*")).thenReturn("matches__.*bar.*");
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))
mock(&regex_interface::std_string).when(regex<const
std::string&>("[A-Z]*")).thenReturn("matches__[A-Z]*");
+#endif
regex_interface& obj = mock.getInstance();

ASSERT_EQUAL("matches__.*foo.*", obj.std_string("foo"));
ASSERT_EQUAL("matches__.*bar.*", obj.std_string("bar"));
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))
ASSERT_EQUAL("matches__[A-Z]*",
obj.std_string("ABCDEFGHIKLMNOPQRSTUVWXYZ"));
+#endif
ASSERT_THROW(obj.std_string("FOO-BAR"),
mockitopp::partial_implementation_exception);
ASSERT_THROW(obj.std_string("1234567890"),
mockitopp::partial_implementation_exception);
}
@@ -68,14 +77,18 @@
mock_object<regex_interface> mock;
mock(&regex_interface::composite).when(regex(".*foo.*"), regex<const
std::string&>(".*bar.*")).thenReturn("matches__.*foo.*__.*bar.*");
mock(&regex_interface::composite).when(regex(".*FOO.*"), regex<const
std::string&>(".*BAR.*")).thenReturn("matches__.*FOO.*__.*BAR.*");
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))
mock(&regex_interface::composite).when(regex("[a-z]*"), regex<const
std::string&>("[A-Z]*")).thenReturn("matches__[a-z]*__[A-Z]*");
+#endif
regex_interface& obj = mock.getInstance();

ASSERT_EQUAL("matches__.*foo.*__.*bar.*",
obj.composite("foo", "bar"));
ASSERT_EQUAL("matches__.*foo.*__.*bar.*",
obj.composite("abc-foo-xyz", "123-bar-890"));
ASSERT_EQUAL("matches__.*FOO.*__.*BAR.*",
obj.composite("FOO", "BAR"));
ASSERT_EQUAL("matches__.*FOO.*__.*BAR.*", obj.composite("FOOTLONG
SANDWICH", "BARLEY SOUP"));
+#if ! (defined(_GLIBCXX_TR1_REGEX) || defined(_GLIBCXX_REGEX))
ASSERT_EQUAL("matches__[a-z]*__[A-Z]*",
obj.composite("abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIKLMNOPQRSTUVWXYZ"));
+#endif
ASSERT_THROW(obj.composite("foo", "abcdefghij"),
mockitopp::partial_implementation_exception);
ASSERT_THROW(obj.composite("1234567890", "bar"),
mockitopp::partial_implementation_exception);
}
Reply all
Reply to author
Forward
0 new messages