aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/tests/priority/priority.cpp
blob: a4167e6551cbf10e60e96673b7dc8cdcf0a6a773 (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
57
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/documentapi/messagebus/priority.h>
#include <fstream>
#include <algorithm>

using namespace documentapi;

TEST_SETUP(Test);

int
Test::Main()
{
    TEST_INIT("priority_test");

    std::vector<int32_t> expected;
    expected.push_back(Priority::PRI_HIGHEST);
    expected.push_back(Priority::PRI_VERY_HIGH);
    expected.push_back(Priority::PRI_HIGH_1);
    expected.push_back(Priority::PRI_HIGH_2);
    expected.push_back(Priority::PRI_HIGH_3);
    expected.push_back(Priority::PRI_NORMAL_1);
    expected.push_back(Priority::PRI_NORMAL_2);
    expected.push_back(Priority::PRI_NORMAL_3);
    expected.push_back(Priority::PRI_NORMAL_4);
    expected.push_back(Priority::PRI_NORMAL_5);
    expected.push_back(Priority::PRI_NORMAL_6);
    expected.push_back(Priority::PRI_LOW_1);
    expected.push_back(Priority::PRI_LOW_2);
    expected.push_back(Priority::PRI_LOW_3);
    expected.push_back(Priority::PRI_VERY_LOW);
    expected.push_back(Priority::PRI_LOWEST);

    std::ifstream in;
    in.open(TEST_PATH("../../../test/crosslanguagefiles/5.1-Priority.txt").c_str());
    ASSERT_TRUE(in.good());
    while (in) {
        std::string str;
        in >> str;
        if (str.empty()) {
            continue;
        }
        size_t pos = str.find(":");
        ASSERT_TRUE(pos != std::string::npos);
        int32_t pri = atoi(str.substr(pos + 1).c_str());
        ASSERT_EQUAL(Priority::getPriority(str.substr(0, pos)), pri);

        std::vector<int32_t>::iterator it =
            std::find(expected.begin(), expected.end(), pri);
        ASSERT_TRUE(it != expected.end());
        expected.erase(it);
    }
    ASSERT_TRUE(expected.empty());

    TEST_DONE();
}