File: RawKeywordTests.cpp

package info (click to toggle)
opm-common 2024.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 98,420 kB
  • sloc: cpp: 263,013; python: 3,155; sh: 198; xml: 174; pascal: 136; makefile: 12
file content (102 lines) | stat: -rw-r--r-- 3,500 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
  Copyright 2013 Statoil ASA.

  This file is part of the Open Porous Media project (OPM).

  OPM is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  OPM is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with OPM.  If not, see <http://www.gnu.org/licenses/>.
 */

#define BOOST_TEST_MODULE RawKeywordTests
#include <cstring>
#include <stdexcept>
#include <boost/test/unit_test.hpp>
#include <opm/common/OpmLog/KeywordLocation.hpp>

#include "../../opm/input/eclipse/Parser/raw/RawEnums.hpp"
#include "../../opm/input/eclipse/Parser/raw/RawKeyword.hpp"
#include "../../opm/input/eclipse/Parser/raw/RawRecord.hpp"


using namespace Opm;


BOOST_AUTO_TEST_CASE(RawKeywordConstructor) {
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::FIXED), std::logic_error);
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::TABLE_COLLECTION), std::logic_error);
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::TABLE_COLLECTION, {}, 0), std::logic_error);
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::SLASH_TERMINATED, {}, 5), std::logic_error);
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::UNKNOWN, {}, 5), std::logic_error);
    BOOST_CHECK_THROW( RawKeyword("NAME", "file", 10, false, Raw::CODE, {}, 2), std::logic_error);
    RawKeyword kw1("NAME", "file", 10, false, Raw::SLASH_TERMINATED);
    RawKeyword kw2("NAME", "file", 10, false, Raw::FIXED, {}, 10);
    RawKeyword kw3("NAME", "file", 10, false, Raw::TABLE_COLLECTION, {}, 7);
    RawKeyword kw4("NAME", "file", 10, false, Raw::CODE);
}

BOOST_AUTO_TEST_CASE(IsFinished) {
    std::string storage = "RecordString";
    std::string_view line(storage);
    RawRecord rec(line, KeywordLocation("KW", "file", 100 ));

    RawKeyword kw1("NAME", "file", 10, false, Raw::FIXED, {}, 0);
    BOOST_CHECK(kw1.isFinished());

    {
        RawKeyword kw2("NAME", "file", 10, false, Raw::FIXED, {}, 2);
        BOOST_CHECK(!kw2.isFinished());

        BOOST_CHECK(!kw2.addRecord(rec));
        BOOST_CHECK(!kw2.isFinished());

        BOOST_CHECK(kw2.addRecord(rec));
        BOOST_CHECK(kw2.isFinished());
    }

    {
        RawKeyword kw("NAME", "file", 10, false, Raw::CODE);
        BOOST_CHECK(!kw.isFinished());

        BOOST_CHECK(kw.addRecord(rec));
        BOOST_CHECK(kw.isFinished());
    }

    {
        RawKeyword kw3("NAME", "file", 10, false, Raw::TABLE_COLLECTION, {}, 2);
        BOOST_CHECK(!kw3.isFinished());

        BOOST_CHECK(!kw3.terminateKeyword());
        BOOST_CHECK(!kw3.isFinished());

        BOOST_CHECK(kw3.terminateKeyword());
        BOOST_CHECK(kw3.isFinished());
    }

    {
        RawKeyword kw4("NAME", "file", 10, false, Raw::SLASH_TERMINATED);
        BOOST_CHECK(!kw4.isFinished());

        BOOST_CHECK(kw4.terminateKeyword());
        BOOST_CHECK(kw4.isFinished());
    }

    {
        RawKeyword kw5("NAME", "file", 10, false, Raw::UNKNOWN);
        BOOST_CHECK(!kw5.isFinished());

        BOOST_CHECK(kw5.terminateKeyword());
        BOOST_CHECK(kw5.isFinished());
    }
}