From 7f5b057b05ab9262c878aef03dc92d3fbdad31ad Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 9 Mar 2017 15:15:07 +0100 Subject: [PATCH] Add test for changing the conference title and not receiving a callback. --- CMakeLists.txt | 5 +- auto_tests/Makefile.inc | 12 ++- .../self_conference_title_change_test.c | 86 +++++++++++++++++++ 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 auto_tests/self_conference_title_change_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 20d477a1d..2f76edec3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -422,9 +422,10 @@ auto_test(tox_many_tcp) auto_test(tox_one) auto_test(tox_strncasecmp) auto_test(version) -# TODO(iphydf): This test is broken. The code needs to be fixed, as the test -# itself is correct. +# TODO(iphydf): These tests are broken. The code needs to be fixed, as the +# tests themselves are correct. #auto_test(selfname_change_conference) +#auto_test(self_conference_title_change) if(BUILD_TOXAV) auto_test(toxav_basic) diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc index b27fcc5d3..244737d92 100644 --- a/auto_tests/Makefile.inc +++ b/auto_tests/Makefile.inc @@ -75,13 +75,21 @@ dht_autotest_CFLAGS = $(AUTOTEST_CFLAGS) dht_autotest_LDADD = $(AUTOTEST_LDADD) -# TODO(iphydf): This test is broken. The code needs to be fixed, as the test -# itself is correct. +# TODO(iphydf): These tests are broken. The code needs to be fixed, as the +# tests themselves are correct. #selfname_change_conference_SOURCE = ../auto_tests/selfname_change_conference_test.c # #selfname_change_conference_CFLAGS = $(AUTOTEST_CFLAGS) # #selfname_change_conference_LDADD = $(AUTOTEST_LDADD) +# +# +#self_conference_title_change_SOURCE = ../auto_tests/self_conference_title_change_test.c +# +#self_conference_title_change_CFLAGS = $(AUTOTEST_CFLAGS) +# +#self_conference_title_change_LDADD = $(AUTOTEST_LDADD) + if BUILD_AV toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c diff --git a/auto_tests/self_conference_title_change_test.c b/auto_tests/self_conference_title_change_test.c new file mode 100644 index 000000000..f08961012 --- /dev/null +++ b/auto_tests/self_conference_title_change_test.c @@ -0,0 +1,86 @@ +/* self_conference_title_change.c + * + * Small test for checking if obtaining savedata, saving it to disk and using + * works correctly. + * + * Copyright (C) 2017 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#include +#include +#include +#include + +#include "../toxcore/tox.h" +#include "../toxencryptsave/toxencryptsave.h" + +static const char *newtitle = "kitten over darknet"; + +static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, + size_t length, void *user_data) +{ + if (!memcmp(title, newtitle, tox_conference_get_title_size(tox, conference_number, NULL))) { + printf("success: title was changed and updated in the conference"); + exit(0); + } +} + +int main(void) +{ + uint32_t conference_number; + struct timespec sleeptime; + struct Tox_Options to; + Tox *t; + TOX_ERR_CONFERENCE_NEW conference_err; + TOX_ERR_CONFERENCE_TITLE title_err; + + tox_options_default(&to); + t = tox_new(&to, NULL); + + tox_callback_conference_title(t, &cbtitlechange); + + if ((conference_number = tox_conference_new(t, &conference_err)) == UINT32_MAX) { + tox_kill(t); + fprintf(stderr, "error: could not create new conference, error code %d\n", conference_err); + return 2; + } + + tox_iterate(t, NULL); + + sleeptime.tv_sec = 0; + sleeptime.tv_nsec = tox_iteration_interval(t) * 1E6; + + nanosleep(&sleeptime, NULL); + + if (!tox_conference_set_title(t, conference_number, (const uint8_t *)newtitle, strlen(newtitle), &title_err)) { + tox_kill(t); + fprintf(stderr, "error: could not set conference title, error code %d\n", title_err); + return 3; + } + + tox_iterate(t, NULL); + nanosleep(&sleeptime, NULL); + tox_iterate(t, NULL); + + fprintf(stderr, "error: title was not changed in callback. exiting.\n"); + + tox_kill(t); + + return 1; +}