2014-01-19 01:09:44 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2013-2014 Mnemosyne LLC
|
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-07 17:52:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "transmission.h"
|
2008-12-23 17:27:15 +00:00
|
|
|
#include "session.h"
|
2016-09-21 20:56:03 +00:00
|
|
|
#include "session-id.h"
|
2008-01-07 17:52:50 +00:00
|
|
|
#include "utils.h"
|
2009-04-13 19:04:21 +00:00
|
|
|
#include "version.h"
|
2008-01-07 17:52:50 +00:00
|
|
|
|
2009-01-23 18:44:15 +00:00
|
|
|
#undef VERBOSE
|
2012-08-18 16:07:05 +00:00
|
|
|
#include "libtransmission-test.h"
|
2008-01-07 17:52:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int testPeerId(void)
|
2008-01-07 17:52:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
2017-04-19 12:04:45 +00:00
|
|
|
uint8_t peer_id[PEER_ID_LEN + 1];
|
2008-01-07 17:52:50 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i = 0; i < 100000; ++i)
|
2008-01-07 17:52:50 +00:00
|
|
|
{
|
2011-03-10 12:35:23 +00:00
|
|
|
int j;
|
|
|
|
int val = 0;
|
2008-01-07 17:52:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_peerIdInit(peer_id);
|
2008-01-07 17:52:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(strlen((char*)peer_id) == PEER_ID_LEN);
|
|
|
|
check(memcmp(peer_id, PEERID_PREFIX, 8) == 0);
|
2011-03-10 12:35:23 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (j = 8; j < PEER_ID_LEN; ++j)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2016-03-29 03:04:54 +00:00
|
|
|
char tmp[2] = { (char)peer_id[j], '\0' };
|
2017-04-19 12:04:45 +00:00
|
|
|
val += strtoul(tmp, NULL, 36);
|
2008-01-07 17:52:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check((val % 36) == 0);
|
2008-01-07 17:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int test_session_id(void)
|
2016-09-21 20:56:03 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_session_id_t session_id;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* session_id_str_1 = NULL;
|
|
|
|
char const* session_id_str_2 = NULL;
|
|
|
|
char const* session_id_str_3 = NULL;
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(!tr_session_id_is_local(NULL));
|
|
|
|
check(!tr_session_id_is_local(""));
|
|
|
|
check(!tr_session_id_is_local("test"));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
session_id = tr_session_id_new();
|
|
|
|
check(session_id != NULL);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_timeUpdate(0);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
session_id_str_1 = tr_session_id_get_current(session_id);
|
|
|
|
check(session_id_str_1 != NULL);
|
|
|
|
check(strlen(session_id_str_1) == 48);
|
|
|
|
session_id_str_1 = tr_strdup(session_id_str_1);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_timeUpdate(60 * 60 - 1);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
session_id_str_2 = tr_session_id_get_current(session_id);
|
|
|
|
check(session_id_str_2 != NULL);
|
|
|
|
check(strlen(session_id_str_2) == 48);
|
|
|
|
check(strcmp(session_id_str_2, session_id_str_1) == 0);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_timeUpdate(60 * 60);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
session_id_str_2 = tr_session_id_get_current(session_id);
|
|
|
|
check(session_id_str_2 != NULL);
|
|
|
|
check(strlen(session_id_str_2) == 48);
|
|
|
|
check(strcmp(session_id_str_2, session_id_str_1) != 0);
|
|
|
|
session_id_str_2 = tr_strdup(session_id_str_2);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_2));
|
|
|
|
check(tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_timeUpdate(60 * 60 * 2);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_2));
|
|
|
|
check(tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
session_id_str_3 = tr_session_id_get_current(session_id);
|
|
|
|
check(session_id_str_3 != NULL);
|
|
|
|
check(strlen(session_id_str_3) == 48);
|
|
|
|
check(strcmp(session_id_str_3, session_id_str_2) != 0);
|
|
|
|
check(strcmp(session_id_str_3, session_id_str_1) != 0);
|
|
|
|
session_id_str_3 = tr_strdup(session_id_str_3);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_3));
|
|
|
|
check(tr_session_id_is_local(session_id_str_2));
|
|
|
|
check(!tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_timeUpdate(60 * 60 * 10);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_session_id_is_local(session_id_str_3));
|
|
|
|
check(tr_session_id_is_local(session_id_str_2));
|
|
|
|
check(!tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(!tr_session_id_is_local(NULL));
|
|
|
|
check(!tr_session_id_is_local(""));
|
|
|
|
check(!tr_session_id_is_local("test"));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_session_id_free(session_id);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
check(!tr_session_id_is_local(session_id_str_3));
|
|
|
|
check(!tr_session_id_is_local(session_id_str_2));
|
|
|
|
check(!tr_session_id_is_local(session_id_str_1));
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_free(session_id_str_3);
|
|
|
|
tr_free(session_id_str_2);
|
|
|
|
tr_free(session_id_str_1);
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return 0;
|
2016-09-21 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int main(void)
|
2016-09-21 20:56:03 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
testFunc const tests[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
testPeerId,
|
|
|
|
test_session_id
|
|
|
|
};
|
2016-09-21 20:56:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return runTests(tests, NUM_TESTS(tests));
|
2016-09-21 20:56:03 +00:00
|
|
|
}
|