-
Notifications
You must be signed in to change notification settings - Fork 114
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
add cpp interface and unit tests #36
base: master
Are you sure you want to change the base?
Conversation
@@ -16,9 +16,13 @@ enum EventType { | |||
|
|||
struct Event { | |||
Event(const EventType type, const std::string &directory, const std::string &fileA, const std::string &fileB) : | |||
type(type), directory(directory), fileA(fileA), fileB(fileB) {} | |||
type(type), directory(directory), fileA(fileA), fileB(fileB) { | |||
timePoint = std::chrono::high_resolution_clock::now(); |
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.
rename timePoint
to the more idiomatic name timestamp
, please
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.
with forgiveness I think it is a time point because the std::chrono libraries doesn't know any 'timestamps' just a lot of time points
see: http://en.cppreference.com/w/cpp/chrono/time_point
"Class template std::chrono::time_point represents a point in time. It is implemented as if it stores a value of type Duration indicating the time interval from the start of the Clock's epoch."
if we rename this as "timestamp" there is confusion with some known timestamps
return transform(std::move(vecEvents)); | ||
} | ||
|
||
virtual VecEvents transform(VecEvents vecEvents) = 0; |
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.
style: NSFW uses two-spaced tabs.
[this](std::unique_ptr<Event> &event){ | ||
std::regex self_regex(regex, | ||
std::regex_constants::ECMAScript | ||
| std::regex_constants::icase); |
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.
not sure about the detailed semantics here. Though, my feeling is that you should set up self_regex
outside the lambda and capture it. Otherwise it would recompile the regex several times, no?
ExcludeDirectories(const std::string ®ex) | ||
: regex(regex) {} | ||
|
||
VecEvents transform(VecEvents vecEvents) { |
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.
please implement that in a *.cpp file.
return vecEvents; | ||
} | ||
|
||
virtual ~ExcludeDirectories() {} |
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.
not needed
test/u_ExcludeDirectories.cpp
Outdated
std::string regex = "/bar$"; | ||
ExcludeDirectories exDir(regex); | ||
|
||
SECTION("directory name does match") { |
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.
does NOT match, no?
auto transformed = exDir(std::move(vec)); | ||
REQUIRE(transformed->size() == 0); | ||
} | ||
} |
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.
another test with both matching and non-matching dir names would be great.
test/u_ExcludeFiles.cpp
Outdated
std::string regex = "~[a-zA-Z_][a-zA-Z_0-9]*\\.tmp"; | ||
ExcludeFiles exFiles(regex); | ||
|
||
SECTION("file name does match") { |
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.
does NOT match, again?
test/u_FileWatcher.cpp
Outdated
|
||
#include "test_helper.h" | ||
|
||
std::string getDirectoryFromFile(const std::string &path) { |
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.
should be static
(i.e. not part of the public interface of this compilation unit)
test/u_FileWatcher.cpp
Outdated
std::string executionPath(getDirectoryFromFile(programmName)); | ||
TestFileSystemAdapter testWatcher(executionPath, | ||
std::chrono::milliseconds(10)); | ||
auto comparation = [](const Event &lhs, const Event &rhs) { |
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.
comparison
includes/Listener.hpp
Outdated
void notify(Args&&... args) { | ||
std::lock_guard<std::mutex> lock(mListenersMutex); | ||
for(const auto &func : mListeners) { | ||
func.second(std::move(std::forward<Args>(args)...)); |
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.
Retrofitting this into our private code base I noticed that the template parameter unpacking is wrong here. It doesn't work for multi-argument Listener<>
callbacks. Needs to look like this:
// move closing paren of std::move _before_ param unpacking
func.second(std::move(std::forward<Args>(args))...);
includes/Listener.hpp
Outdated
|
||
template <class CallbackType> | ||
class Listener | ||
{ |
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.
two-spaced tabs, please.
} | ||
|
||
VecEvents ExcludeDirectories::transform(VecEvents vecEvents) { | ||
std::regex self_regex(mRegex, |
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.
two-spaced tabs, please.
@implausible @maxkorp Any thoughts on that? :-) |
Hello again! @reneme I will get to this over the weekend. |
add namespaces change the includes to a relativpath independent path
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.
Test framework should run on travis/appveyor.
okay :) the test framework run on travis and appveyor.. except the mac implementation.. |
That's a little strange. There's also some inconsistency on windows as well. |
this is a PR for the future work of #34
what we have worked on?
With this changes we can use and test the library with c++.
After the installation of cmake you can run the following command
cmake . && make -j