summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/matching/handle_recorder/handle_recorder_test.cpp
blob: 4675c09768e9dd63051bc3d7fe98b065eec146ea (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
55
56
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchcore/proton/matching/handlerecorder.h>
#include <vespa/vespalib/gtest/gtest.h>

#include <vespa/log/log.h>

LOG_SETUP("handle_recorder_test");

using search::fef::MatchDataDetails;
using search::fef::TermFieldHandle;
using namespace proton::matching;

using HandleMap = HandleRecorder::HandleMap;

constexpr MatchDataDetails NormalMask = MatchDataDetails::Normal;
constexpr MatchDataDetails CheapMask = MatchDataDetails::Cheap;
constexpr MatchDataDetails BothMask = static_cast<MatchDataDetails>(static_cast<int>(NormalMask) | static_cast<int>(CheapMask));

void
register_normal_handle(TermFieldHandle handle)
{
    HandleRecorder::register_handle(handle, MatchDataDetails::Normal);
}

void
register_cheap_handle(TermFieldHandle handle)
{
    HandleRecorder::register_handle(handle, MatchDataDetails::Cheap);
}

TEST(HandleRecorderTest, can_record_both_normal_and_cheap_handles)
{
    HandleRecorder recorder;
    {
        HandleRecorder::Binder binder(recorder);
        register_normal_handle(3);
        register_cheap_handle(5);
        register_normal_handle(7);
    }
    EXPECT_EQ(HandleMap({{3, NormalMask}, {5, CheapMask}, {7, NormalMask}}), recorder.get_handles());
    EXPECT_EQ("normal: [3,7], cheap: [5]", recorder.to_string());
}

TEST(HandleRecorderTest, the_same_handle_can_be_in_both_normal_and_cheap_set)
{
    HandleRecorder recorder;
    {
        HandleRecorder::Binder binder(recorder);
        register_normal_handle(3);
        register_cheap_handle(3);
    }
    EXPECT_EQ(HandleMap({{3, BothMask}}), recorder.get_handles());
}

GTEST_MAIN_RUN_ALL_TESTS()