forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFileParser.cpp
More file actions
72 lines (58 loc) · 1.72 KB
/
TestFileParser.cpp
File metadata and controls
72 lines (58 loc) · 1.72 KB
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
// Copyright 2004-present Facebook. All Rights Reserved.
#include "tck-test/TestFileParser.h"
#include <folly/String.h>
#include <glog/logging.h>
namespace rsocket {
namespace tck {
TestFileParser::TestFileParser(const std::string& fileName) : input_(fileName) {
if (!input_.good()) {
LOG(FATAL) << "Could not read from file " << fileName;
}
}
TestSuite TestFileParser::parse() {
currentLine_ = 0;
std::string newCommand;
while (std::getline(input_, newCommand)) {
parseCommand(newCommand);
++currentLine_;
}
addCurrentTest();
return std::move(testSuite_);
}
void TestFileParser::parseCommand(const std::string& command) {
if (command.empty()) {
// ignore empty lines
return;
}
// test delimiter
if (command == "!" || command == "EOF") {
addCurrentTest();
return;
}
std::vector<std::string> parameters;
folly::split("%%", command, parameters, /*ignoreEmpty=*/true);
if (parameters.size() == 2 && parameters[0] == "name") {
currentTest_.setName(parameters[1]);
currentTest_.setResumption(false);
return;
}
TestCommand newCommand(std::move(parameters));
if (!newCommand.valid()) {
LOG(ERROR) << "invalid command on line " << currentLine_ << ": " << command;
throw std::runtime_error("unknown command in the test");
} else {
// if test contain resumption related command.
if ("disconnect" == newCommand.name() || "resume" == newCommand.name()) {
currentTest_.setResumption(true);
}
currentTest_.addCommand(std::move(newCommand));
}
}
void TestFileParser::addCurrentTest() {
if (!currentTest_.empty()) {
testSuite_.addTest(std::move(currentTest_));
DCHECK(currentTest_.empty());
}
}
} // namespace tck
} // namespace rsocket