diff tests/libcommon/util/main.cpp @ 44:f30c84b4b9ed

Tests: switch from GoogleTest to Boost.Unit, closes #588
author David Demelier <markand@malikania.fr>
date Wed, 30 Nov 2016 21:15:53 +0100
parents fabbe1759cec
children b0593a3e2ca8
line wrap: on
line diff
--- a/tests/libcommon/util/main.cpp	Tue Nov 29 22:25:17 2016 +0100
+++ b/tests/libcommon/util/main.cpp	Wed Nov 30 21:15:53 2016 +0100
@@ -16,7 +16,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE "Util"
+#include <boost/test/unit_test.hpp>
 
 #include <malikania/util.hpp>
 
@@ -27,81 +28,82 @@
  * ------------------------------------------------------------------
  */
 
-TEST(Clamp, normal)
+BOOST_AUTO_TEST_SUITE(clamp)
+
+BOOST_AUTO_TEST_CASE(normal)
 {
-    ASSERT_EQ(5, util::clamp(5, 0, 10));
+    BOOST_REQUIRE_EQUAL(5, util::clamp(5, 0, 10));
 }
 
-TEST(Clamp, minimum)
+BOOST_AUTO_TEST_CASE(minimum)
 {
-    ASSERT_EQ(0, util::clamp(0, 0, 10));
+    BOOST_REQUIRE_EQUAL(0, util::clamp(0, 0, 10));
 }
 
-TEST(Clamp, maximum)
+BOOST_AUTO_TEST_CASE(maximum)
 {
-    ASSERT_EQ(10, util::clamp(10, 0, 10));
+    BOOST_REQUIRE_EQUAL(10, util::clamp(10, 0, 10));
 }
 
-TEST(Clamp, less)
+BOOST_AUTO_TEST_CASE(less)
 {
-    ASSERT_EQ(0, util::clamp(-10, 0, 10));
+    BOOST_REQUIRE_EQUAL(0, util::clamp(-10, 0, 10));
 }
 
-TEST(Clamp, higher)
+BOOST_AUTO_TEST_CASE(higher)
 {
-    ASSERT_EQ(10, util::clamp(20, 0, 10));
+    BOOST_REQUIRE_EQUAL(10, util::clamp(20, 0, 10));
 }
 
+BOOST_AUTO_TEST_SUITE_END()
+
 /*
  * util::netsplit
  * ------------------------------------------------------------------
  */
 
-TEST(Netsplit, simple)
+BOOST_AUTO_TEST_SUITE(netsplit)
+
+BOOST_AUTO_TEST_CASE(simple)
 {
     std::string input = "hello world\r\n\r\n";
     std::vector<std::string> messages = util::netsplit(input);
 
-    ASSERT_EQ(1U, messages.size());
-    ASSERT_EQ("hello world", messages[0]);
-    ASSERT_TRUE(input.empty());
+    BOOST_REQUIRE_EQUAL(1U, messages.size());
+    BOOST_REQUIRE_EQUAL("hello world", messages[0]);
+    BOOST_REQUIRE(input.empty());
 }
 
-TEST(Netsplit, two)
+BOOST_AUTO_TEST_CASE(two)
 {
     std::string input = "hello world\r\n\r\nhow are you?\r\n\r\n";
     std::vector<std::string> messages = util::netsplit(input);
 
-    ASSERT_EQ(2U, messages.size());
-    ASSERT_EQ("hello world", messages[0]);
-    ASSERT_EQ("how are you?", messages[1]);
-    ASSERT_TRUE(input.empty());
+    BOOST_REQUIRE_EQUAL(2U, messages.size());
+    BOOST_REQUIRE_EQUAL("hello world", messages[0]);
+    BOOST_REQUIRE_EQUAL("how are you?", messages[1]);
+    BOOST_REQUIRE(input.empty());
 }
 
-TEST(Netsplit, imcomplete)
+BOOST_AUTO_TEST_CASE(imcomplete)
 {
     std::string input = "hello world\r\n";
     std::vector<std::string> messages = util::netsplit(input);
 
-    ASSERT_EQ(0U, messages.size());
-    ASSERT_EQ("hello world\r\n", input);
+    BOOST_REQUIRE_EQUAL(0U, messages.size());
+    BOOST_REQUIRE_EQUAL("hello world\r\n", input);
 }
 
-TEST(Netsplit, empty)
+BOOST_AUTO_TEST_CASE(empty)
 {
     std::string input = "hello world\r\n\r\n\r\n\r\nhow are you?\r\n\r\n";
     std::vector<std::string> messages = util::netsplit(input);
 
-    ASSERT_EQ(3U, messages.size());
-    ASSERT_EQ("hello world", messages[0]);
-    ASSERT_TRUE(messages[1].empty());
-    ASSERT_EQ("how are you?", messages[2]);
-    ASSERT_TRUE(input.empty());
+    BOOST_REQUIRE_EQUAL(3U, messages.size());
+    BOOST_REQUIRE_EQUAL("hello world", messages[0]);
+    BOOST_REQUIRE(messages[1].empty());
+    BOOST_REQUIRE_EQUAL("how are you?", messages[2]);
+    BOOST_REQUIRE(input.empty());
 }
 
-int main(int argc, char **argv)
-{
-    testing::InitGoogleTest(&argc, argv);
-
-    return RUN_ALL_TESTS();
-}
+BOOST_AUTO_TEST_SUITE_END()