From 2296d07e0963bcf4e0a13db51c6d11b294f941ab Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 19 Jun 2018 20:54:21 +0000 Subject: [PATCH] Add test for creating multiple conferences in one tox. This triggers a code path in Persistent Group Chats that causes a memory leak. I'm adding this test now, so that we don't merge PGC without fixing the memory leak first. --- CMakeLists.txt | 1 + auto_tests/check_compat.h | 1 + auto_tests/conference_two_test.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 auto_tests/conference_two_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 19dcacff..431faf89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -498,6 +498,7 @@ endif() auto_test(TCP) auto_test(bootstrap) auto_test(conference) +auto_test(conference_two) auto_test(crypto MSVC_DONT_BUILD) auto_test(dht MSVC_DONT_BUILD) auto_test(encryptsave) diff --git a/auto_tests/check_compat.h b/auto_tests/check_compat.h index badf18c8..9e174287 100644 --- a/auto_tests/check_compat.h +++ b/auto_tests/check_compat.h @@ -5,6 +5,7 @@ #include #include +#include #define START_TEST(name) static void name(void) #define END_TEST diff --git a/auto_tests/conference_two_test.c b/auto_tests/conference_two_test.c new file mode 100644 index 00000000..c3036165 --- /dev/null +++ b/auto_tests/conference_two_test.c @@ -0,0 +1,30 @@ +// This test checks that we can create two conferences and quit properly. +// +// This test triggers a different code path than if we only allocate a single +// conference. This is the simplest test possible that triggers it. +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#endif + +#include "../toxcore/tox.h" + +#include "check_compat.h" +#include "helpers.h" + +int main(void) +{ + // Create toxes. + uint32_t id = 1; + Tox *tox1 = tox_new_log(nullptr, nullptr, &id); + + // Create two conferences and then exit. + TOX_ERR_CONFERENCE_NEW err; + tox_conference_new(tox1, &err); + ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 1: %d", err); + tox_conference_new(tox1, &err); + ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 2: %d", err); + + tox_kill(tox1); + + return 0; +}