File: record.cpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (77 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <components/esmloader/record.hpp>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <array>
#include <tuple>

namespace
{
    using namespace testing;
    using namespace EsmLoader;

    struct Value
    {
        int mKey;
        int mValue;
    };

    auto tie(const Value& v)
    {
        return std::tie(v.mKey, v.mValue);
    }

    bool operator==(const Value& l, const Value& r)
    {
        return tie(l) == tie(r);
    }

    std::ostream& operator<<(std::ostream& s, const Value& v)
    {
        return s << "Value {" << v.mKey << ", " << v.mValue << "}";
    }

    Record<Value> present(const Value& v)
    {
        return Record<Value>(false, v);
    }

    Record<Value> deleted(const Value& v)
    {
        return Record<Value>(true, v);
    }

    struct Params
    {
        Records<Value> mRecords;
        std::vector<Value> mResult;
    };

    struct EsmLoaderPrepareRecordTest : TestWithParam<Params>
    {
    };

    TEST_P(EsmLoaderPrepareRecordTest, prepareRecords)
    {
        auto records = GetParam().mRecords;
        const auto getKey = [&](const Record<Value>& v) { return v.mValue.mKey; };
        EXPECT_THAT(prepareRecords(records, getKey), ElementsAreArray(GetParam().mResult));
    }

    const std::array params = {
        Params{ {}, {} },
        Params{ { present(Value{ 1, 1 }) }, { Value{ 1, 1 } } },
        Params{ { deleted(Value{ 1, 1 }) }, {} },
        Params{ { present(Value{ 1, 1 }), present(Value{ 2, 2 }) }, { Value{ 1, 1 }, Value{ 2, 2 } } },
        Params{ { present(Value{ 2, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 }, Value{ 2, 2 } } },
        Params{ { present(Value{ 1, 1 }), present(Value{ 1, 2 }) }, { Value{ 1, 2 } } },
        Params{ { present(Value{ 1, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 } } },
        Params{ { present(Value{ 1, 1 }), deleted(Value{ 1, 2 }) }, {} },
        Params{ { deleted(Value{ 1, 1 }), present(Value{ 1, 2 }) }, { Value{ 1, 2 } } },
        Params{ { present(Value{ 1, 2 }), deleted(Value{ 1, 1 }) }, {} },
        Params{ { deleted(Value{ 1, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 } } },
    };

    INSTANTIATE_TEST_SUITE_P(Params, EsmLoaderPrepareRecordTest, ValuesIn(params));
}