aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/runnable_pair/runnable_pair_test.cpp
blob: 68a2835a29c119e252ccaa63c88a72ce0666d8c2 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/runnable_pair.h>

using namespace vespalib;

struct Add : public Runnable {
    int &val;
    Add(int &v) : val(v) {}
    void run() override { val += 10; }
};

struct Mul : public Runnable {
    int &val;
    Mul(int &v) : val(v) {}
    void run() override { val *= 10; }
};

TEST("require that runnable pair runs runnables in order") {
    int value = 0;
    Add add(value);
    Mul mul(value);
    RunnablePair pair(add, mul);
    EXPECT_EQUAL(0, value);
    pair.run();
    EXPECT_EQUAL(100, value);
}

TEST_MAIN() { TEST_RUN_ALL(); }