OTest2
A C++ testing framework
difflogblock.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <difflogblock.h>
20 
21 #include <assert.h>
22 
23 namespace OTest2 {
24 
25 namespace {
26 
27 void updateRecord(
28  DiffBlock& block_,
29  int DiffBlock::* begin_,
30  int DiffBlock::* end_,
31  int value_) {
32  assert(block_.*end_ == value_);
33  ++(block_.*end_);
34 }
35 
36 } /* -- namespace */
37 
39  DiffLogBlocks* blocks_) :
40  blocks(blocks_),
41  opened_block(false),
42  curr_left(-1),
43  curr_right(-1) {
44  assert(blocks != nullptr);
45 
46 }
47 
49 
50 }
51 
52 void DiffLogBuilderBlock::openBlock() {
53  if(!opened_block) {
54  blocks->push_back({
55  curr_left + 1, curr_left + 1, curr_right + 1, curr_right + 1});
56  opened_block = true;
57  }
58  assert(!blocks->empty());
59 }
60 
62  int left_index_,
63  int right_index_) {
64  curr_left = left_index_;
65  curr_right = right_index_;
66  /* -- a match closes currently opened block of changes */
67  opened_block = false;
68 }
69 
71  int left_index_,
72  int right_index_) {
73  openBlock();
74  curr_left = left_index_;
75  curr_right = right_index_;
76 
77  DiffBlock& block_(blocks->back());
78  updateRecord(
79  block_, &DiffBlock::left_begin, &DiffBlock::left_end, left_index_);
80  updateRecord(
81  block_, &DiffBlock::right_begin, &DiffBlock::right_end, right_index_);
82 }
83 
85  int right_index_) {
86  openBlock();
87  curr_right = right_index_;
88 
89  DiffBlock& block_(blocks->back());
90  updateRecord(
91  block_, &DiffBlock::right_begin, &DiffBlock::right_end, right_index_);
92 }
93 
95  int left_index_) {
96  openBlock();
97  curr_left = left_index_;
98 
99  DiffBlock& block_(blocks->back());
100  updateRecord(
101  block_, &DiffBlock::left_begin, &DiffBlock::left_end, left_index_);
102 }
103 
104 } /* namespace OTest2 */
OTest2::DiffLogBuilderBlock::~DiffLogBuilderBlock
virtual ~DiffLogBuilderBlock()
Dtor.
Definition: difflogblock.cpp:48
OTest2::DiffLogBuilderBlock::addMatch
virtual void addMatch(int left_index_, int right_index_)
Add match of characters in both sequences.
Definition: difflogblock.cpp:61
OTest2::DiffLogBlocks
std::vector< DiffBlock > DiffLogBlocks
Ordered (indexes into the sequences) list of diff changes.
Definition: difflogblock.h:42
OTest2::DiffBlock::right_end
int right_end
Definition: difflogblock.h:36
OTest2::DiffBlock::left_begin
int left_begin
Definition: difflogblock.h:33
OTest2
Definition: assertbean.h:25
OTest2::DiffBlock::left_end
int left_end
Definition: difflogblock.h:34
OTest2::DiffLogBuilderBlock::DiffLogBuilderBlock
DiffLogBuilderBlock(DiffLogBlocks *blocks_)
Ctor.
Definition: difflogblock.cpp:38
OTest2::DiffBlock::right_begin
int right_begin
Definition: difflogblock.h:35
OTest2::DiffBlock
One block change.
Definition: difflogblock.h:32
OTest2::DiffLogBuilderBlock::addInsert
virtual void addInsert(int left_index_)
Add inserted item to the left sequence.
Definition: difflogblock.cpp:94
OTest2::DiffLogBuilderBlock::addDelete
virtual void addDelete(int right_index_)
Add deleted item from the right sequence.
Definition: difflogblock.cpp:84
difflogblock.h
OTest2::DiffLogBuilderBlock::addChange
virtual void addChange(int left_index_, int right_index_)
Add change of both sequences.
Definition: difflogblock.cpp:70