diff --git a/src/TopicTree.h b/src/TopicTree.h index 22fba82..c1ee999 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -1,5 +1,5 @@ /* - * Authored by Alex Hultman, 2018-2019. + * Authored by Alex Hultman, 2018-2020. * Intellectual property of third-party. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,6 +26,7 @@ #include #include #include +#include namespace uWS { diff --git a/tests/Makefile b/tests/Makefile index 100e8cf..7c9acff 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,3 +1,5 @@ default: - $(CXX) -std=c++17 HttpRouter.cpp -o HttpRouter + $(CXX) -std=c++17 -fsanitize=address TopicTree.cpp -o TopicTree + ./TopicTree + $(CXX) -std=c++17 -fsanitize=address HttpRouter.cpp -o HttpRouter ./HttpRouter \ No newline at end of file diff --git a/tests/TopicTree.cpp b/tests/TopicTree.cpp new file mode 100644 index 0000000..de9b84e --- /dev/null +++ b/tests/TopicTree.cpp @@ -0,0 +1,49 @@ +#include "../src/TopicTree.h" + +#include +#include + +uWS::TopicTree *topicTree; + +void testUnsubscribeInside() { + + topicTree = new uWS::TopicTree([](uWS::Subscriber *s, std::string_view data) { + std::cout << s << " got <" << data << ">" << std::endl; + + if (s == (void *) UINTPTR_MAX) { + std::cout << "Error! Received UINTPTR_MAX as Subscriber!" << std::endl; + exit(-1); + } + + /* This one causes the following cb to get UINTPTR_MAX */ + topicTree->unsubscribeAll(s); + + return 0; + }); + + uWS::Subscriber *s1 = new uWS::Subscriber(nullptr); + uWS::Subscriber *s2 = new uWS::Subscriber(nullptr); + + std::cout << "s1 = " << s1 << std::endl; + std::cout << "s2 = " << s2 << std::endl; + + topicTree->subscribe("1", s1); + topicTree->subscribe("2", s2); + + topicTree->publish("1", "Ett!"); + topicTree->publish("2", "TvÄ!"); + + topicTree->drain(); + + topicTree->unsubscribeAll(s1); + topicTree->unsubscribeAll(s2); + + delete s1; + delete s2; + + delete topicTree; +} + +int main() { + testUnsubscribeInside(); +} \ No newline at end of file