Use `TR_BAD_SIZE` instead of -1 in `tr_quark_new()` calls

Extend quark test to improve branch coverage.
This commit is contained in:
Mike Gelfand 2016-01-07 19:20:14 +00:00
parent 52ca481033
commit 13a98a02b8
8 changed files with 19 additions and 14 deletions

View File

@ -75,7 +75,7 @@ toggle_pref_cb (GtkToggleAction * action,
const char * key = gtk_action_get_name (GTK_ACTION (action));
const gboolean val = gtk_toggle_action_get_active (action);
gtr_core_set_pref_bool (myCore, tr_quark_new(key,-1), val);
gtr_core_set_pref_bool (myCore, tr_quark_new(key, TR_BAD_SIZE), val);
}
static GtkToggleActionEntry pref_toggle_entries[] =
@ -231,7 +231,7 @@ gtr_actions_init (GtkUIManager * ui_manager, gpointer callback_user_data)
for (i = 0, n = G_N_ELEMENTS (pref_toggle_entries); i < n; ++i)
pref_toggle_entries[i].is_active =
gtr_pref_flag_get (tr_quark_new (pref_toggle_entries[i].name, -1));
gtr_pref_flag_get (tr_quark_new (pref_toggle_entries[i].name, TR_BAD_SIZE));
gtk_action_group_add_toggle_actions (action_group,
pref_toggle_entries,

View File

@ -39,7 +39,7 @@ get_recent_destinations (void)
char key[64];
const char * val;
g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
if ((val = gtr_pref_string_get (tr_quark_new(key, TR_BAD_SIZE))))
list = g_slist_append (list, (void*)val);
}
@ -73,7 +73,7 @@ save_recent_destination (TrCore * core, const char * dir)
{
char key[64];
g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
gtr_pref_string_set (tr_quark_new(key,-1), l->data);
gtr_pref_string_set (tr_quark_new(key, TR_BAD_SIZE), l->data);
}
gtr_pref_save (gtr_core_session (core));

View File

@ -2038,7 +2038,7 @@ myHandshakeDoneCB (tr_handshake * handshake,
char buf[128];
if (peer_id != NULL)
client = tr_quark_new (tr_clientForId (buf, sizeof (buf), peer_id), -1);
client = tr_quark_new (tr_clientForId (buf, sizeof (buf), peer_id), TR_BAD_SIZE);
else
client = TR_KEY_NONE;

View File

@ -930,7 +930,7 @@ sendLtepHandshake (tr_peerMsgs * msgs)
return;
if (!version_quark)
version_quark = tr_quark_new (TR_NAME " " USERAGENT_PREFIX, -1);
version_quark = tr_quark_new (TR_NAME " " USERAGENT_PREFIX, TR_BAD_SIZE);
dbgmsg (msgs, "sending an ltep handshake");
msgs->clientSentLtepHandshake = true;

View File

@ -17,6 +17,7 @@ static int
test_static_quarks (void)
{
int i;
tr_quark q1, q2;
for (i=0; i<TR_N_KEYS; i++)
{
@ -41,6 +42,10 @@ test_static_quarks (void)
check (strcmp (str1, str2) < 0);
}
const tr_quark q = tr_quark_new (NULL, TR_BAD_SIZE);
check_int_eq (TR_KEY_NONE, q);
check_streq ("", tr_quark_get_string (q, NULL));
return 0;
}

View File

@ -480,7 +480,7 @@ tr_quark_new (const void * str, size_t len)
if (str == NULL)
len = 0;
else if (len == (size_t)-1)
else if (len == TR_BAD_SIZE)
len = strlen (str);
if (!tr_quark_lookup (str, len, &ret))

View File

@ -2527,7 +2527,7 @@ metainfoLookupInit (tr_session * session)
if (!tr_torrentParse (ctor, &inf))
{
++n;
tr_variantDictAddStr (lookup, tr_quark_new(inf.hashString,-1), path);
tr_variantDictAddStr (lookup, tr_quark_new(inf.hashString, TR_BAD_SIZE), path);
}
tr_free (path);
}
@ -2548,7 +2548,7 @@ tr_sessionFindTorrentFile (const tr_session * session,
if (!session->metainfoLookup)
metainfoLookupInit ((tr_session*)session);
tr_variantDictFindStr (session->metainfoLookup, tr_quark_new(hashString,-1), &filename, NULL);
tr_variantDictFindStr (session->metainfoLookup, tr_quark_new(hashString, TR_BAD_SIZE), &filename, NULL);
return filename;
}
@ -2563,7 +2563,7 @@ tr_sessionSetTorrentFile (tr_session * session,
* in that same directory, we don't need to do anything here if the
* lookup table hasn't been built yet */
if (session->metainfoLookup)
tr_variantDictAddStr (session->metainfoLookup, tr_quark_new(hashString,-1), filename);
tr_variantDictAddStr (session->metainfoLookup, tr_quark_new(hashString, TR_BAD_SIZE), filename);
}
/***

View File

@ -513,10 +513,10 @@ testParse2 (void)
char * benc;
const char * end;
size_t strLen;
const tr_quark key_bool = tr_quark_new ("this-is-a-bool", -1);
const tr_quark key_real = tr_quark_new ("this-is-a-real", -1);
const tr_quark key_int = tr_quark_new ("this-is-an-int", -1);
const tr_quark key_str = tr_quark_new ("this-is-a-string", -1);
const tr_quark key_bool = tr_quark_new ("this-is-a-bool", TR_BAD_SIZE);
const tr_quark key_real = tr_quark_new ("this-is-a-real", TR_BAD_SIZE);
const tr_quark key_int = tr_quark_new ("this-is-an-int", TR_BAD_SIZE);
const tr_quark key_str = tr_quark_new ("this-is-a-string", TR_BAD_SIZE);
tr_variantInitDict (&top, 0);
tr_variantDictAddBool (&top, key_bool, true);