From b345f7660734ccd21808f5b37fefbaf99bb98ef6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Jun 2009 07:50:50 +0000 Subject: [PATCH] 2009-06-07 Tatsuhiro Tsujikawa Added unit tests for strjoin, strconcat and strappend. * test/a2functionalTest.cc --- ChangeLog | 5 +++++ test/a2functionalTest.cc | 41 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22c5f64c..41eaf316 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-06-07 Tatsuhiro Tsujikawa + + Added unit tests for strjoin, strconcat and strappend. + * test/a2functionalTest.cc + 2009-06-07 Tatsuhiro Tsujikawa Rewritten strconcat and strappend using operator+ instead of diff --git a/test/a2functionalTest.cc b/test/a2functionalTest.cc index 36b4564c..0129d4af 100644 --- a/test/a2functionalTest.cc +++ b/test/a2functionalTest.cc @@ -1,7 +1,9 @@ #include "a2functional.h" + +#include + #include #include -#include namespace aria2 { @@ -10,11 +12,17 @@ class a2functionalTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(a2functionalTest); CPPUNIT_TEST(testMemFunSh); CPPUNIT_TEST(testAdopt2nd); + CPPUNIT_TEST(testStrjoin); + CPPUNIT_TEST(testStrconcat); + CPPUNIT_TEST(testStrappend); CPPUNIT_TEST_SUITE_END(); public: void testMemFunSh(); void testAdopt2nd(); - + void testStrjoin(); + void testStrconcat(); + void testStrappend(); + class Greeting { public: virtual ~Greeting() {} @@ -63,4 +71,33 @@ void a2functionalTest::testAdopt2nd() adopt2nd(std::plus(), mem_fun_sh(&Greeting::sayGreeting))("A Japanese said:", greeting)); } +void a2functionalTest::testStrjoin() +{ + std::vector v; + CPPUNIT_ASSERT_EQUAL(std::string(""), strjoin(v.begin(), v.end(), " ")); + + v.push_back("A"); + + CPPUNIT_ASSERT_EQUAL(std::string("A"), strjoin(v.begin(), v.end(), " ")); + + v.push_back("hero"); + v.push_back("is"); + v.push_back("lonely"); + + CPPUNIT_ASSERT_EQUAL(std::string("A hero is lonely"), + strjoin(v.begin(), v.end(), " ")); +} + +void a2functionalTest::testStrconcat() +{ + CPPUNIT_ASSERT_EQUAL(std::string("X=3"), strconcat("X=", "3")); +} + +void a2functionalTest::testStrappend() +{ + std::string str = "X="; + strappend(str, "3", ",Y=", "5"); + CPPUNIT_ASSERT_EQUAL(std::string("X=3,Y=5"), str); +} + } // namespace aria2