blob: 2e0d6c397fc5a78b1affa3bae95d214e6d8c0b95 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <cppunit/extensions/HelperMacros.h>
#include <list>
#include <string>
#include <algorithm>
#include <vespa/storage/storageutil/functor.h>
class Functor_Test : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(Functor_Test);
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testDeletePointer);
CPPUNIT_TEST_SUITE_END();
public:
protected:
void testReplace();
void testDeletePointer();
};
using namespace storage;
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION(Functor_Test);
void Functor_Test::testReplace()
{
string source("this.is.a.string.with.many.dots.");
for_each(source.begin(), source.end(), Functor::Replace<char>('.', '_'));
CPPUNIT_ASSERT_EQUAL(string("this_is_a_string_with_many_dots_"), source);
}
namespace {
static int instanceCounter = 0;
class TestClass {
public:
TestClass() { instanceCounter++; }
~TestClass() { instanceCounter--; }
};
}
void Functor_Test::testDeletePointer()
{
list<TestClass*> mylist;
mylist.push_back(new TestClass());
mylist.push_back(new TestClass());
mylist.push_back(new TestClass());
CPPUNIT_ASSERT_EQUAL(3, instanceCounter);
for_each(mylist.begin(), mylist.end(), Functor::DeletePointer());
CPPUNIT_ASSERT_EQUAL(0, instanceCounter);
}
|