Add failing unit test for TopicTree

This commit is contained in:
Alex Hultman
2020-05-08 09:58:15 +02:00
parent 6512b5f2c0
commit 7a000bffcf
3 changed files with 54 additions and 2 deletions
+2 -1
View File
@@ -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 <set>
#include <chrono>
#include <list>
#include <cstring>
namespace uWS {
+3 -1
View File
@@ -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
+49
View File
@@ -0,0 +1,49 @@
#include "../src/TopicTree.h"
#include <cassert>
#include <iostream>
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();
}