-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcasewidget.cpp
59 lines (52 loc) · 1.85 KB
/
testcasewidget.cpp
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
#include "testcasewidget.h"
#include <QBoxLayout>
#include <QLabel>
#include <QSizePolicy>
#include <QSpacerItem>
#include <QTextEdit>
TestCaseWidget::TestCaseWidget(const QString &input, const QString &expected, QWidget *parent)
{
QLabel *l1 = new QLabel("Input:");
inputTextEdit = new QTextEdit;
inputTextEdit->setText(input);
inputTextEdit->setFixedHeight(100);
inputTextEdit->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
QLabel *l2 = new QLabel("Output:");
outputTextEdit = new QTextEdit;
outputTextEdit->setFixedHeight(100);
QLabel *l3 = new QLabel("Expected:");
expectedTextEdit = new QTextEdit;
expectedTextEdit->setText(expected);
expectedTextEdit->setFixedHeight(100);
connect(outputTextEdit, &QTextEdit::textChanged, this, &TestCaseWidget::compare);
connect(expectedTextEdit, &QTextEdit::textChanged, this, &TestCaseWidget::compare);
QBoxLayout *layout = new QBoxLayout(QBoxLayout::Direction::TopToBottom, this);
layout->setSpacing(0);
layout->addWidget(l1);
layout->addWidget(inputTextEdit);
layout->addWidget(l2);
layout->addWidget(outputTextEdit);
layout->addWidget(l3);
layout->addWidget(expectedTextEdit);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
}
void TestCaseWidget::setInput(const QString &newInput)
{
inputTextEdit->setText(newInput);
}
void TestCaseWidget::setOutput(const QString &newOutput)
{
outputTextEdit->setText(newOutput);
}
void TestCaseWidget::setExpected(const QString &newExpected)
{
expectedTextEdit->setText(newExpected);
}
void TestCaseWidget::compare()
{
if (outputTextEdit->toPlainText() != expectedTextEdit->toPlainText()) {
outputTextEdit->setStyleSheet("QTextEdit { border: 1px solid red; }");
} else {
outputTextEdit->setStyleSheet("");
}
}