Example #1
0
static uint64_t loadRatioLimits(tr_variant* dict, tr_torrent* tor)
{
    tr_variant* d;
    uint64_t ret = 0;

    if (tr_variantDictFindDict(dict, TR_KEY_ratio_limit, &d))
    {
        int64_t i;
        double dratio;

        if (tr_variantDictFindReal(d, TR_KEY_ratio_limit, &dratio))
        {
            tr_torrentSetRatioLimit(tor, dratio);
        }

        if (tr_variantDictFindInt(d, TR_KEY_ratio_mode, &i))
        {
            tr_torrentSetRatioMode(tor, i);
        }

        ret = TR_FR_RATIOLIMIT;
    }

    return ret;
}
Example #2
0
double
gtr_pref_double_get (const tr_quark key)
{
  double d = 0.0;

  tr_variantDictFindReal (getPrefs (), key, &d);

  return d;
}
Example #3
0
static int test_elements(void)
{
    char const* in;
    tr_variant top;
    char const* str;
    bool f;
    double d;
    int64_t i;
    int err = 0;
    tr_quark key;

    in =
        "{ \"string\": \"hello world\","
        "  \"escaped\": \"bell \\b formfeed \\f linefeed \\n carriage return \\r tab \\t\","
        "  \"int\": 5, "
        "  \"float\": 6.5, "
        "  \"true\": true, "
        "  \"false\": false, "
        "  \"null\": null }";

    err = tr_variantFromJson(&top, in, strlen(in));
    check_int(err, ==, 0);
    check(tr_variantIsDict(&top));
    str = NULL;
    key = tr_quark_new("string", 6);
    check(tr_variantDictFindStr(&top, key, &str, NULL));
    check_str(str, ==, "hello world");
    check(tr_variantDictFindStr(&top, tr_quark_new("escaped", 7), &str, NULL));
    check_str(str, ==, "bell \b formfeed \f linefeed \n carriage return \r tab \t");
    i = 0;
    check(tr_variantDictFindInt(&top, tr_quark_new("int", 3), &i));
    check_int(i, ==, 5);
    d = 0;
    check(tr_variantDictFindReal(&top, tr_quark_new("float", 5), &d));
    check_int(((int)(d * 10)), ==, 65);
    f = false;
    check(tr_variantDictFindBool(&top, tr_quark_new("true", 4), &f));
    check_int(f, ==, true);
    check(tr_variantDictFindBool(&top, tr_quark_new("false", 5), &f));
    check_int(f, ==, false);
    check(tr_variantDictFindStr(&top, tr_quark_new("null", 4), &str, NULL));
    check_str(str, ==, "");

    if (err == 0)
    {
        tr_variantFree(&top);
    }

    return 0;
}
Example #4
0
static int
test_elements (void)
{
    const char * in;
    tr_variant top;
    const char * str;
    bool f;
    double d;
    int64_t i;
    int err = 0;
    tr_quark key;

    in = "{ \"string\": \"hello world\","
         "  \"escaped\": \"bell \\b formfeed \\f linefeed \\n carriage return \\r tab \\t\","
         "  \"int\": 5, "
         "  \"float\": 6.5, "
         "  \"true\": true, "
         "  \"false\": false, "
         "  \"null\": null }";

    err = tr_variantFromJson (&top, in, strlen(in));
    check_int_eq (0, err);
    check (tr_variantIsDict (&top));
    str = NULL;
    key = tr_quark_new ("string", 6);
    check (tr_variantDictFindStr (&top, key, &str, NULL));
    check_streq ("hello world", str);
    check (tr_variantDictFindStr (&top, tr_quark_new("escaped",7), &str, NULL));
    check_streq ("bell \b formfeed \f linefeed \n carriage return \r tab \t", str);
    i = 0;
    check (tr_variantDictFindInt (&top, tr_quark_new("int",3), &i));
    check_int_eq (5, i);
    d = 0;
    check (tr_variantDictFindReal (&top, tr_quark_new("float",5), &d));
    check_int_eq (65, ((int)(d*10)));
    f = false;
    check (tr_variantDictFindBool (&top, tr_quark_new("true",4), &f));
    check_int_eq (true, f);
    check (tr_variantDictFindBool (&top, tr_quark_new("false",5), &f));
    check_int_eq (false, f);
    check (tr_variantDictFindStr (&top, tr_quark_new("null",4), &str, NULL));
    check_streq ("", str);

    if (!err)
        tr_variantFree (&top);

    return 0;
}