-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of multiple responses in one read #152
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a1edefc
Fix handling of multiple responses in one read
at-wat 750cbf9
Fix unknown command handling
at-wat d8e7b8a
Ignore when status line is empty
at-wat 2808e83
Fix response processing on non-aligned read
at-wat 30e43e9
Add comment
at-wat a4423e2
Fix multiple responses in one read
at-wat f2a4e5d
Unuse eof which is not available
at-wat 658cc57
Remove unused block
at-wat 4f07667
Remove duplicated code
at-wat d655009
Handle getline error as well
at-wat File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2024 The urg_stamped Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <memory> | ||
#include <ostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <scip2/protocol.h> | ||
#include <scip2/connection.h> | ||
|
||
class ConnectionDummy : public scip2::Connection | ||
{ | ||
public: | ||
void spin() final | ||
{ | ||
} | ||
void stop() final | ||
{ | ||
} | ||
void send(const std::string&, CallbackSend = CallbackSend()) final | ||
{ | ||
} | ||
void startWatchdog(const boost::posix_time::time_duration&) final | ||
{ | ||
} | ||
void feed(boost::asio::streambuf& buf, const boost::posix_time::ptime& time_read) | ||
{ | ||
receive(buf, time_read); | ||
} | ||
}; | ||
|
||
TEST(SCIP2, MultipleResponses) | ||
{ | ||
std::shared_ptr<ConnectionDummy> dev(new ConnectionDummy()); | ||
scip2::Protocol p(dev); | ||
|
||
const auto now = boost::posix_time::microsec_clock::universal_time(); | ||
int num_receive = 0; | ||
|
||
const auto cb = | ||
[&num_receive, now]( | ||
const boost::posix_time::ptime& time_read, | ||
const std::string& echo_back, | ||
const std::string& status) | ||
{ | ||
num_receive++; | ||
EXPECT_EQ(now, time_read); | ||
EXPECT_EQ("00", status); | ||
}; | ||
p.registerCallback<scip2::ResponseQT>(cb); | ||
|
||
/* | ||
Input data: | ||
|
||
QT // First QT response | ||
00P | ||
|
||
FOO // Unknown response | ||
BAR | ||
QT // This line must be ignored as a part of unknown command | ||
|
||
QT // This must be ignored as it doesn't have correct status line | ||
|
||
QT // Second QT response | ||
00P | ||
|
||
*/ | ||
boost::asio::streambuf buf; | ||
std::ostream os(&buf); | ||
os << "QT\n00P\n\nF"; | ||
dev->feed(buf, now); | ||
ASSERT_EQ(1, num_receive); | ||
|
||
os << "OO\nBAR\nQT\n\n"; | ||
dev->feed(buf, now); | ||
ASSERT_EQ(1, num_receive); | ||
|
||
os << "QT\n\nQT\n"; | ||
dev->feed(buf, now); | ||
ASSERT_EQ(1, num_receive); | ||
|
||
os << "00P\n\n"; | ||
dev->feed(buf, now); | ||
ASSERT_EQ(2, num_receive); | ||
|
||
os << "\n\n"; | ||
dev->feed(buf, now); | ||
ASSERT_EQ(2, num_receive); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continued lines must be processed on the next callback