Example #1
0
END_TEST

START_TEST (test_to_string)
{
    NValue *value = NULL;
    value = n_value_new ();
    fail_unless (value != NULL);
    const char *str = "NGF";
    const int i = -100;
    const uint ui = 10;
    const gboolean logic = TRUE;
    const gpointer point = value;
    char *expected = "<unknown value>";

    char *string = n_value_to_string (value);
    fail_unless (strcmp (string, expected) == 0);
    g_free (string);
    string = NULL;
	
    n_value_set_string (value, str);
    string = n_value_to_string (value);
    expected = "NGF (string)";
    fail_unless (strcmp (string, expected) == 0);
    g_free (string);
    string = NULL;

    n_value_set_int (value, i);
    string = n_value_to_string (value);
    expected = "-100 (int)";
    fail_unless (strcmp (string, expected) == 0);
    g_free (string);
    string = NULL;

    n_value_set_uint (value, ui);
    string = n_value_to_string (value);
    expected = "10 (uint)";
    fail_unless (strcmp (string, expected) == 0);
    g_free (string);
    string = NULL;

    n_value_set_bool (value, logic);
    string = n_value_to_string (value);
    expected = "TRUE (bool)";
    fail_unless (strcmp (string, expected) == 0);
    g_free (string);
    string = NULL;

    n_value_set_pointer (value, point);
    string = n_value_to_string (value);
    expected = g_strdup_printf ("0x%X (pointer)", (unsigned int)point);
    fail_unless (g_strcmp0 (string, expected) == 0);
    g_free (string);
    g_free (expected);
    string = NULL;

    n_value_free (value);
    value = NULL;
}
Example #2
0
END_TEST

START_TEST (test_copy)
{
    NValue *val = NULL;
    NValue *copy = NULL;
    copy = n_value_copy (val);
    fail_unless (copy == NULL);
    val = n_value_new ();
    copy = n_value_copy (val);
    fail_unless (copy == NULL);
    gboolean result = FALSE;
    const char *str = "ngf";

    /* copy string value */
    n_value_set_string (val, str);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy int value */
    n_value_set_int (val, -10);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy uint value */
    n_value_set_uint (val, 10);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

    /* copy bool value */
    n_value_set_bool (val, TRUE);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);
    n_value_free (copy);
    copy = NULL;

/* copy pointer value */
    n_value_set_pointer(val, val);
    copy = n_value_copy (val);
    result = n_value_equals (val, copy);
    fail_unless (result == TRUE);	
	
    n_value_free (val);
    val = NULL;
    n_value_free (copy);
    copy = NULL;
}
Example #3
0
END_TEST

START_TEST (test_bool)
{
    NValue *value = NULL;
    value = n_value_new ();
    fail_unless (value != NULL);
    fail_unless (n_value_get_bool (value) == FALSE);
    gboolean val = TRUE;
    n_value_set_bool (value, val);
    gboolean reply = n_value_get_bool (value);
    fail_unless (reply == val);

    n_value_free (value);
    value = NULL;
}
Example #4
0
static void
update_context_value (NContext *context, const char *profile, const char *key,
                      const char *value)
{
    gchar  *context_key = NULL;
    NValue *context_val = NULL;
    gint    level       = 0;
    gchar  *new_val     = NULL;

    context_key = construct_context_key (profile, key);
    context_val = n_value_new ();

    if (g_str_has_suffix (key, TONE_SUFFIX) ||
        g_str_has_suffix (key, PATTERN_SUFFIX)) {
        new_val = get_absolute_tone_path (value);
        new_val = new_val != NULL ? new_val : g_strdup (value);
        n_value_set_string (context_val, new_val);
        g_free (new_val);
    }
    else if (g_str_has_suffix (key, VOLUME_SUFFIX)) {
        n_value_set_int (context_val, profile_parse_int (value));
    }
    else if (g_str_has_suffix (key, SYSTEM_SUFFIX)) {
        level = profile_parse_int (value);
        level = CLAMP_VALUE (level, 0, (gint) num_system_sound_levels-1);
        n_value_set_int (context_val, system_sound_levels[level]);
    }
    else if (g_str_equal (key, KEY_VIBRATION_ENABLED)) {
        n_value_set_bool (context_val, profile_parse_bool (value));
    } else if (g_str_equal (key, KEY_TOUCH_VIBRA_LEVEL)) {
        n_value_set_int (context_val, profile_parse_int (value));
    } else {
        n_value_set_string (context_val, value);
    }

    n_context_set_value (context, context_key, context_val);
    g_free (context_key);
}
Example #5
0
END_TEST

START_TEST (test_equals)
{
    NValue *valA = NULL;
    NValue *valB = NULL;
    gboolean result = TRUE;

    /* both are NULL */
    result = n_value_equals (valA, valB);
    fail_unless (result == FALSE);

    valA = n_value_new ();
    valB = n_value_new ();

    const char *str = "ngf";

    n_value_set_string (valA, str);
    n_value_set_uint (valB, 10);
    /* types differ */
    result = n_value_equals (valA, valB);
    fail_unless (result == FALSE);
	
    /* string types */
    n_value_set_string (valB, str);
    result = n_value_equals (valA, valB);
    fail_unless (result == TRUE);

    /* int types */
    n_value_set_int (valA, -10);
    n_value_set_int (valB, -10);
    result = n_value_equals (valA, valB);
    fail_unless (result == TRUE);

    /* uint types */
    n_value_set_uint (valA, 10);
    n_value_set_uint (valB, 10);
    result = n_value_equals (valA, valB);
    fail_unless (result == TRUE);

    /* boolean types */
    n_value_set_bool (valA, TRUE);
    n_value_set_bool (valB, TRUE);
    result = n_value_equals (valA, valB);
    fail_unless (result == TRUE);

    /* pointer types */
    n_value_set_pointer (valA, valA);
    n_value_set_pointer (valB, valA);
    result = n_value_equals (valA, valB);
    fail_unless (result == TRUE);

    /* different poiter */
    n_value_set_pointer (valB, valB);
    result = n_value_equals (valA, valB);
    fail_unless (result == FALSE);

    n_value_free (valA);
    valA = NULL;
    n_value_free (valB);
    valB = NULL;
}