Ejemplo n.º 1
0
void Test_dictionary_unset(CuTest *tc)
{
    int i, j;
    char sec_name[32];
    char key_name[64];
    dictionary *dic1;
    dictionary *dic2;
    char *dic1_dump;
    char *dic2_dump;

    /* try dummy unsets */
    dictionary_unset(NULL, NULL);
    dictionary_unset(NULL, key_name);

    /* Generate two similar dictionaries */
    dic1 = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic1);
    for (i = 1 ; i < 10; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_set(dic1, sec_name, "");
        for (j = 1 ; j < 10; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_set(dic1, key_name, "dummy_value");
        }
    }
    dic2 = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic2);
    for (i = 1 ; i < 10; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_set(dic2, sec_name, "");
        for (j = 1 ; j < 10; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_set(dic2, key_name, "dummy_value");
        }
    }

    /* Make sure the dictionaries are the same */
    dic1_dump = get_dump(dic1);
    dic2_dump = get_dump(dic2);
    CuAssertStrEquals(tc, dic1_dump, dic2_dump);
    free(dic1_dump);
    free(dic2_dump);

    /* Those tests should not change the dictionary */
    dictionary_unset(dic2, NULL);
    dictionary_unset(dic2, "bad_key");

    /* dic1 and dic2 must still be the same */
    dic1_dump = get_dump(dic1);
    dic2_dump = get_dump(dic2);
    CuAssertStrEquals(tc, dic1_dump, dic2_dump);
    free(dic1_dump);
    free(dic2_dump);
}
Ejemplo n.º 2
0
void Test_dictionary_wrapper(CuTest *tc)
{
    dictionary *dic;

    dic = dictionary_new(10);

    CuAssertIntEquals(tc, -1, iniparser_set(dic, NULL, NULL));
    CuAssertIntEquals(tc, -1, iniparser_set(NULL, "section", "value"));

    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section", NULL));
    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", "value"));

    CuAssertStrEquals(tc, "value", iniparser_getstring(dic, "section:key", NULL));
    /* reset the key's value*/
    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", NULL));
    CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section:key", "dummy"));
    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", "value"));
    CuAssertStrEquals(tc, "value", iniparser_getstring(dic, "section:key", NULL));

    iniparser_unset(dic, "section:key");
    CuAssertStrEquals(tc, "dummy", iniparser_getstring(dic, "section:key", "dummy"));
    CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section", "dummy"));

    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key", NULL));
    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key1", NULL));
    CuAssertIntEquals(tc, 0, iniparser_set(dic, "section:key2", NULL));

    iniparser_unset(dic, "section");
    CuAssertStrEquals(tc, NULL, iniparser_getstring(dic, "section", NULL));

    iniparser_freedict(dic);
}
Ejemplo n.º 3
0
void array_new(ArrayValue* myself, char* xml) {
	Tag* valueTag;
	DictValue* curValue;

	myself->values = NULL;
	myself->size = 0;
	while (*xml != '\0') {
		valueTag = getNextTag(&xml);
		if (valueTag == NULL) {
			break;
		}

		myself->size++;
		myself->values = realloc(myself->values, sizeof(DictValue*)
				* myself->size);
		curValue = (DictValue*) malloc(sizeof(DictValue));

		curValue->key = (char*) malloc(sizeof("arraykey"));
		strcpy(curValue->key, "arraykey");
		curValue->next = NULL;

		if (strcmp(valueTag->name, "dict") == 0) {
			curValue->type = DictionaryType;
			curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
			dictionary_new((Dictionary*) curValue, valueTag->xml);

		} else if (strcmp(valueTag->name, "string") == 0) {
			curValue->type = StringType;
			curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
			((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
			strcpy(((StringValue*)curValue)->value, valueTag->xml);
		} else if(strcmp(valueTag->name, "data") == 0) {
			size_t len;
			curValue->type = StringType;
			curValue = (DictValue*) realloc(curValue, sizeof(DataValue));
			((DataValue*)curValue)->value = decodeBase64(valueTag->xml, &len);
			((DataValue*)curValue)->len = len;
		} else if(strcmp(valueTag->name, "integer") == 0) {
			curValue->type = IntegerType;
			curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
			sscanf(valueTag->xml, "%d", &(((IntegerValue*) curValue)->value));
		} else if (strcmp(valueTag->name, "array") == 0) {
			curValue->type = ArrayType;
			curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
			array_new((ArrayValue*) curValue, valueTag->xml);
		} else if (strcmp(valueTag->name, "true/") == 0) {
			curValue->type = BoolType;
			curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
			((BoolValue*) curValue)->value = TRUE;
		} else if (strcmp(valueTag->name, "false/") == 0) {
			curValue->type = BoolType;
			curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
			((BoolValue*) curValue)->value = FALSE;
		}

		myself->values[myself->size - 1] = curValue;

		releaseTag(valueTag);
	}
}
Ejemplo n.º 4
0
void camera_control_backup_system_settings(CameraControl* cc, const char* file) {
    int AutoAEC = 0;
    int AutoAGC = 0;
    int Gain = 0;
    int Exposure = 0;
    int Contrast = 0;
    int Brightness = 0;

    int fd = open_v4l2_device(cc->cameraID);

    if (fd != -1) {
        AutoAEC = v4l2_get_control(fd, V4L2_CID_EXPOSURE_AUTO);
        AutoAGC = v4l2_get_control(fd, V4L2_CID_AUTOGAIN);
        Gain = v4l2_get_control(fd, V4L2_CID_GAIN);
        Exposure = v4l2_get_control(fd, V4L2_CID_EXPOSURE);
        Contrast = v4l2_get_control(fd, V4L2_CID_CONTRAST);
        Brightness = v4l2_get_control(fd, V4L2_CID_BRIGHTNESS);
        v4l2_close(fd);

        dictionary* ini = dictionary_new(0);
        iniparser_set(ini, "PSEye", 0);
        iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
        iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
        iniparser_set_int(ini, "PSEye:Gain", Gain);
        iniparser_set_int(ini, "PSEye:Exposure", Exposure);
        iniparser_set_int(ini, "PSEye:Contrast", Contrast);
        iniparser_set_int(ini, "PSEye:Brightness", Brightness);
        iniparser_save_ini(ini, file);
        dictionary_del(ini);
    }
}
Ejemplo n.º 5
0
/** 
  Test funckji dictionary_hints().
  Wstawienie do słownika 7 słów.
  Sprawdzenie, czy funkcja zwraca prawidłowe podpowiedzi.
  */
static void dictionary_hints_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	struct word_list *l = malloc(sizeof(word_list));
    word_list_init(l);
    wchar_t *word1 = L"at";
    wchar_t *word2 = L"car";
    wchar_t *word3 = L"cat";
    wchar_t *word4 = L"cats";
    wchar_t *word5 = L"cut";
    wchar_t *word6 = L"mat";
    wchar_t *word7 = L"rat";
	dictionary_insert(dict, word1);
	dictionary_insert(dict, word2);
	dictionary_insert(dict, word3);
	dictionary_insert(dict, word4);
	dictionary_insert(dict, word5);
	dictionary_insert(dict, word6);
	dictionary_insert(dict, word7);
	dictionary_hints(dict, word3, l);
	assert_string_equal(l->next->word, word1);
	assert_string_equal(l->next->next->word, word2);
	assert_string_equal(l->next->next->next->word, word3);
	assert_string_equal(l->next->next->next->next->word, word4);
	assert_string_equal(l->next->next->next->next->next->word, word5);
	assert_string_equal(l->next->next->next->next->next->next->word, word6);
	assert_string_equal(l->next->next->next->next->next->next->next->word, word7);
	word_list_done(l);
	dictionary_done(dict);
	free(l);
}
Ejemplo n.º 6
0
void Test_iniparser_getsecname(CuTest *tc)
{
    unsigned i;
    char sec_name[32];
    dictionary *dic;
    /* NULL test */
    CuAssertTrue(tc, iniparser_getsecname(NULL, 0) == NULL);

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getsecname(dic, 0));
    dictionary_del(dic);

    /* Sections without entries dictionary */
    dic = generate_dictionary(100, 0);
    for (i = 0; i < 100; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
    }
    dictionary_del(dic);

    /* Generic dictionary */
    dic = generate_dictionary(10, 100);
    for (i = 0; i < 10; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertStrEquals(tc, sec_name, iniparser_getsecname(dic, i));
    }
    dictionary_del(dic);
}
Ejemplo n.º 7
0
/**
  Testuje zapisywanie słownika.
  @param state Środowisko testowe.
  */
static void dictionary_save_test(void** state)
{
    struct dictionary *dict = dictionary_new();

    FILE *stream;
    wchar_t *buf = NULL;
    size_t len;

    stream = open_wmemstream(&buf, &len);
    if (stream == NULL)
    {
        fprintf(stderr, "Failed to open memory stream\n");
        exit(EXIT_FAILURE);
    }

    dictionary_insert(dict, L"ciupaga");
    assert_true(dictionary_save(dict, stream) == 0);
    fflush(stream);
    assert_true(wcscmp(L"ciupaga*^^^^^^^\n0\n", buf) == 0);
    fseek(stream, 0, SEEK_SET);

    fclose(stream);
#   undef free
    free(buf);
#   define free(ptr) _test_free(ptr, __FILE__, __LINE__)
    dictionary_done(dict);
}
Ejemplo n.º 8
0
void INI::create()
{
	if (this->ini)
		this->free();

	this->ini = dictionary_new(0);
}
Ejemplo n.º 9
0
void scripto_dblclick(t_scripto *x)
{
	if (x->s_patcher)
		object_method(x->s_patcher, gensym("vis"));
	else {
		t_dictionary *d = dictionary_new();
		char parsebuf[256];
		t_atom a;
		long ac = 0;
		t_atom *av = NULL;

		// create a patcher without scroll bars and a toolbar
		sprintf(parsebuf,"@defrect 0 0 300 400 @title scripto @enablehscroll 0 @enablevscroll 0 @presentation 0 @toolbarid \"\"");
		atom_setparse(&ac,&av,parsebuf);
		attr_args_dictionary(d,ac,av);
		atom_setobj(&a,d);
		sysmem_freeptr(av);
		x->s_patcher = (t_object *)object_new_typed(CLASS_NOBOX,gensym("jpatcher"),1, &a);
		freeobject((t_object *)d);	// we created this dictionary and we don't need it anymore

		object_method(x->s_patcher,gensym("vis"));
		x->s_ui = newobject_sprintf(x->s_patcher, "@maxclass scripto_ui @patching_rect 0 0 300 400 @oncolor %.2f %.2f %.2f %.2f @offcolor %.2f %.2f %.2f %.2f",
									x->s_oncolor.red, x->s_oncolor.green, x->s_oncolor.blue, x->s_oncolor.alpha, x->s_offcolor.red, x->s_offcolor.green, x->s_offcolor.blue, x->s_offcolor.alpha);
		object_attach_byptr_register(x, x->s_ui, CLASS_BOX);			// attach our UI object to us
		object_attach_byptr_register(x, x->s_patcher, CLASS_NOBOX);		// attach our UI object to us
	}
}
Ejemplo n.º 10
0
Archivo: dict.c Proyecto: elechak/blue
static Link addChild(Link self,Link value,Link keys){
    
    Link * args = array_getArray(keys);
    size_t argn  = array_getLength(keys);       
    
    if (argn != 1) return NULL;

    string_t key = object_getString(args[0]);
    
    if ( ! key ) return NULL;
    
    Dict dict = self->value.vptr;
    if ( ! dict){
        dict = self->value.vptr = malloc( sizeof( *dict) );
        dict->dictionary = dictionary_new();
        dict->mutex = mutex_new();
    }
    
    mutex_lock(dict->mutex);    
    Link old = dictionary_insert(dict->dictionary, key, value );
    mutex_unlock(dict->mutex);
    if (old) link_free(old);
    
    return value; // return original not duplicate child
}
Ejemplo n.º 11
0
void Test_dictionary_growing(CuTest *tc)
{
    int i, j;
    char sec_name[32];
    char key_name[64];
    dictionary *dic;

    dic = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic);
    CuAssertIntEquals(tc, 0, dic->n);

    /* Makes the dictionary grow */
    for (i = 1 ; i < 101; ++i) {
        sprintf(sec_name, "sec%d", i);
        CuAssertIntEquals(tc, 0, dictionary_set(dic, sec_name, ""));
        for (j = 1 ; j < 11; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            CuAssertIntEquals(tc, 0, dictionary_set(dic, key_name, "dummy_value"));
            CuAssertIntEquals(tc, i + (i - 1) * 10 + j, dic->n);
        }
    }

    /* Shrink the dictionary */
    for (i = 100 ; i > 0; --i) {
        sprintf(sec_name, "sec%d", i);
        for (j = 10 ; j > 0; --j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_unset(dic, key_name);
        }
        dictionary_unset(dic, sec_name);
        CuAssertIntEquals(tc, (i - 1) * (11), dic->n);
    }

    dictionary_del(dic);
}
Ejemplo n.º 12
0
/* Tool function to create and populate a generic non-empty dictionary */
static dictionary * generate_dictionary(unsigned sections, unsigned entries_per_section)
{
    unsigned i, j ;
    dictionary * dic;
    char sec_name[32];
    char key_name[64];
    char key_value[32];

    dic = dictionary_new(sections + sections * entries_per_section);
    if (dic == NULL)
        return NULL;

    /* Insert the sections */
    for (i = 0; i < sections; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_set(dic, sec_name, "");
        for (j = 0; j < entries_per_section; ++j) {
            /* Populate the section with the entries */
            sprintf(key_name, "%s:key%d", sec_name, j);
            sprintf(key_value, "value-%d/%d", i, j);
            dictionary_set(dic, key_name, key_value);
        }
    }

    return dic;
}
Ejemplo n.º 13
0
void Test_iniparser_getnsec(CuTest *tc)
{
    int i;
    char sec_name[32];
    dictionary *dic;

    /* NULL test */
    CuAssertIntEquals(tc, -1, iniparser_getnsec(NULL));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertIntEquals(tc, 0, iniparser_getnsec(dic));
    dictionary_del(dic);

    /* Regular dictionary */
    dic = generate_dictionary(512, 0);
    CuAssertIntEquals(tc, 512, iniparser_getnsec(dic));

    /* Check after removing sections */
    for (i = 1; i < 512; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_unset(dic, sec_name);
        CuAssertIntEquals(tc, 512 - i, iniparser_getnsec(dic));
    }
    dictionary_del(dic);

    /* Mix sections and regular keys */
    dic = generate_dictionary(10, 512);
    CuAssertIntEquals(tc, 10, iniparser_getnsec(dic));
    dictionary_del(dic);
}
Ejemplo n.º 14
0
static int dictionary_setup(void **state) {
    struct dictionary *d = dictionary_new();
    dictionary_insert(d,first);
    dictionary_insert(d,second);
    dictionary_insert(d,third);
    *state = d;
    return 0;
}
Ejemplo n.º 15
0
/**
 Tworzy środowisko do testów
 @param[in,out] state Środowisko
 @return Kod błędu
 */
static int dictionary_setup(void **state)
{
	dictionary *d = dictionary_new();
	if (d == NULL)
		return -1;
	*state = d;
	return 0;
}
Ejemplo n.º 16
0
void test_failure(){
    if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)){
        dictionary *dd = dictionary_new();
        dictionary_add(dd, NULL, "blank");
    }
    g_test_trap_assert_failed();
    g_test_trap_assert_stderr("NULL is not a valid key.\n");
}
Ejemplo n.º 17
0
void Test_iniparser_getseckeys(CuTest *tc)
{
    unsigned i;
    char key_name[64];
    dictionary *dic;
    int nkeys;
    const char * keys[10]; /* At most 10 elements per section */
    /* NULL test */
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy", keys));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
    dictionary_del(dic);

    /* Generic dictionary */

    dic = generate_dictionary(100, 10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL, keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy", keys));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec0", NULL));
    nkeys = iniparser_getsecnkeys(dic, "sec42");
    CuAssertIntEquals(tc, nkeys, 10);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec42", keys));
    for (i = 0; i < 10; ++i) {
        sprintf(key_name, "sec42:key%d", i);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    /* Remove some keys to make the dictionary more real */
    dictionary_unset(dic, "sec42");
    dictionary_unset(dic, "sec99:key9");
    dictionary_unset(dic, "sec0:key0");
    dictionary_unset(dic, "sec0:key1");
    dictionary_unset(dic, "sec0:key2");

    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42", keys));
    nkeys = iniparser_getsecnkeys(dic, "sec99");
    CuAssertIntEquals(tc, nkeys, 9);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec99", keys));
    for (i = 0; i < 9; ++i) {
        sprintf(key_name, "sec99:key%d", i);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    nkeys = iniparser_getsecnkeys(dic, "sec0");
    CuAssertIntEquals(tc, nkeys, 7);
    CuAssertPtrEquals(tc, keys, iniparser_getseckeys(dic, "sec0", keys));
    for (i = 0; i < 7; ++i) {
        sprintf(key_name, "sec0:key%d", i + 3);
        CuAssertStrEquals(tc, key_name, keys[i]);
    }

    dictionary_del(dic);
}
Ejemplo n.º 18
0
/**
  Test funkcji dictionary_new().
  Stworzenie słownika.
  */
static void dictionary_new_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	assert_true(dict->root->letter == '-');
	assert_true(dict->alphabet->letter == '#');
	assert_int_equal(dict->root->isInWord, 0);
	assert_null(dict->alphabet->next);
	dictionary_done(dict);
}
Ejemplo n.º 19
0
/// Funkcja sprawdzająca inicjalizację, dodanie słów ze stałych i destrukcję.
static void dict_setup_done_test(void **state) {
	struct dictionary* d = dictionary_new();
	assert_non_null(d);
	assert_int_equal(dictionary_insert(d, first), 1);
	assert_int_equal(dictionary_insert(d, second), 1);
	assert_int_equal(dictionary_insert(d, third), 1);
	assert_int_equal(dictionary_insert(d, forth), 1);
	assert_int_equal(dictionary_insert(d, fifth), 1);
	dictionary_done(d);
}
Ejemplo n.º 20
0
int
config_init(void)
{
	overrides = dictionary_new(0);
	if(!overrides)
	{
		return -1;
	}
	return 0;
}
Ejemplo n.º 21
0
dictionary * iniparser_load(const char * ininame)
{
    dictionary  *   d ;
    char        lin[ASCIILINESZ+1];
    char        sec[ASCIILINESZ+1];
    char        key[ASCIILINESZ+1];
    char        val[ASCIILINESZ+1];
    char    *   where ;
    FILE    *   ini ;
    int         lineno ;

    if ((ini=fopen(ininame, "r"))==NULL) {
        return NULL ;
    }

    sec[0]=0;

    /*
     * Initialize a new dictionary entry
     */
    if (!(d = dictionary_new(0))) {
	    fclose(ini);
	    return NULL;
    }
    lineno = 0 ;
    while (fgets(lin, ASCIILINESZ, ini)!=NULL) {
        lineno++ ;
        where = strskp(lin); /* Skip leading spaces */
        if (*where==';' || *where=='#' || *where==0)
            continue ; /* Comment lines */
        else {
            if (sscanf(where, "[%[^]]", sec)==1) {
                /* Valid section name */
                strcpy(sec, strlwc(sec));
                iniparser_add_entry(d, sec, NULL, NULL);
            } else if (sscanf (where, "%[^=] = \"%[^\"]\"", key, val) == 2
                   ||  sscanf (where, "%[^=] = '%[^\']'",   key, val) == 2
                   ||  sscanf (where, "%[^=] = %[^;#]",     key, val) == 2) {
                strcpy(key, strlwc(strcrop(key)));
                /*
                 * sscanf cannot handle "" or '' as empty value,
                 * this is done here
                 */
                if (!strcmp(val, "\"\"") || !strcmp(val, "''")) {
                    val[0] = (char)0;
                } else {
                    strcpy(val, strcrop(val));
                }
                iniparser_add_entry(d, sec, key, val);
            }
        }
    }
    fclose(ini);
    return d ;
}
Ejemplo n.º 22
0
void update_config(char *token, char *username)
{
    bstring file = locate_config_file();

    bstring tmp = bstrcpy(file);
    bcatcstr(tmp, ".tmp_XXXXXX");

    int fd = mkstemp((char *) tmp->data);
    if (fd < 0)
    {
	perror("mkstemp");
	exit(1);
    }
    FILE *fp = fdopen(fd, "w");
    if (fp == 0)
    {
	perror("fdopen");
	exit(1);
    }

    dictionary *config;

    struct stat statbuf;
    int rc = stat((char *) file->data, &statbuf);
    if (rc < 0 || statbuf.st_size == 0)
    {
	/* create a new empty dictionary */
	config = dictionary_new(0);
	dictionary_set(config, "authentication", 0);
    }
    else
    {
	config = iniparser_load(bdata(file));
    }

    iniparser_set(config, "authentication:token", token);
    if (username)
	iniparser_set(config, "authentication:user_id", username);
    iniparser_dump_ini(config, fp);

    iniparser_freedict(config);

    fclose(fp);

    if (rename(bdata(tmp), bdata(file)) < 0)
    {
	fprintf(stderr, "Error rename %s to %s: %s\n",
		bdata(tmp), bdata(file), strerror(errno));
	exit(1);
    }

    bdestroy(tmp);
    bdestroy(file);
}
Ejemplo n.º 23
0
/// Ustawia słownik z podobnych stringów do testów setup_teardown.
static int dict_setup_similar(void **state) {
	struct dictionary* d = dictionary_new();
	if(!d)
		return -1;
	assert_int_equal(dictionary_insert(d, firstSimilar), 1);
	assert_int_equal(dictionary_insert(d, secondSimilar), 1);
	assert_int_equal(dictionary_insert(d, thirdSimilar), 1);
	assert_int_equal(dictionary_insert(d, forthSimilar), 1);
	assert_int_equal(dictionary_insert(d, fifthSimilar), 1);
	*state = d;
	return 0;
}
Ejemplo n.º 24
0
void Test_iniparser_getseckeys(CuTest *tc)
{
    unsigned i;
    char key_name[64];
    dictionary *dic;
    const char ** sections;
    /* NULL test */
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(NULL, "dummy"));

    /* Empty dictionary */
    dic = dictionary_new(10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy"));
    dictionary_del(dic);

    /* Generic dictionary */
    dic = generate_dictionary(100, 10);
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, NULL));
    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "dummy"));
    sections = iniparser_getseckeys(dic, "sec42");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 10; ++i) {
        sprintf(key_name, "sec42:key%d", i);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);

    /* Remove some keys to make the dictionary more real */
    dictionary_unset(dic, "sec42");
    dictionary_unset(dic, "sec99:key9");
    dictionary_unset(dic, "sec0:key0");
    dictionary_unset(dic, "sec0:key1");
    dictionary_unset(dic, "sec0:key2");

    CuAssertPtrEquals(tc, NULL, iniparser_getseckeys(dic, "sec42"));
    sections = iniparser_getseckeys(dic, "sec99");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 9; ++i) {
        sprintf(key_name, "sec99:key%d", i);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);
    sections = iniparser_getseckeys(dic, "sec0");
    CuAssertPtrNotNull(tc, sections);
    for (i = 0; i < 7; ++i) {
        sprintf(key_name, "sec0:key%d", i + 3);
        CuAssertStrEquals(tc, key_name, sections[i]);
    }
    free(sections);

    dictionary_del(dic);
}
Ejemplo n.º 25
0
/**
 * Signal handler for HUP which tells us to swap the log file
 * and reload configuration file if specified
 *
 * @param sig
 */
void
do_signal_sighup(RunTimeOpts * rtOpts, PtpClock * ptpClock)
{



	NOTIFY("SIGHUP received\n");

#ifdef RUNTIME_DEBUG
	if(rtOpts->transport == UDP_IPV4 && rtOpts->ipMode != IPMODE_UNICAST) {
		DBG("SIGHUP - running an ipv4 multicast based mode, re-sending IGMP joins\n");
		netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock);
	}
#endif /* RUNTIME_DEBUG */


	/* if we don't have a config file specified, we're done - just reopen log files*/
	if(strlen(rtOpts->configFile) !=  0) {

	    dictionary* tmpConfig = dictionary_new(0);

	    /* Try reloading the config file */
	    NOTIFY("Reloading configuration file: %s\n",rtOpts->configFile);

            if(!loadConfigFile(&tmpConfig, rtOpts)) {

		    dictionary_del(&tmpConfig);

	    } else {
		    dictionary_merge(rtOpts->cliConfig, tmpConfig, 1, 1, "from command line");
		    applyConfig(tmpConfig, rtOpts, ptpClock);
		    dictionary_del(&tmpConfig);

	    }

	}

	/* tell the service it can perform any HUP-triggered actions */
	ptpClock->timingService.reloadRequested = TRUE;

	if(rtOpts->recordLog.logEnabled ||
	    rtOpts->eventLog.logEnabled ||
	    (rtOpts->statisticsLog.logEnabled))
		INFO("Reopening log files\n");

	restartLogging(rtOpts);

	if(rtOpts->statisticsLog.logEnabled)
		ptpClock->resetStatisticsLog = TRUE;


}
Ejemplo n.º 26
0
/**
 *
 * key の値が存在していれば取得
 *
 * @param self
 * @param key
 * @return
 */
hash_item *dictionary_get(hash *self, char *key) {
    dictionary *it = dictionary_new(self);
    hash_item *pair;

    while ((pair = dictionary_next(it))) {
        if (strcmp(key, pair->key) == 0) {
            dictionary_destroy(it);
            return pair;
        }
    }

    dictionary_destroy(it);
    return NULL;
}
Ejemplo n.º 27
0
int main(int argc, char* argv[])
{
    dictionary*     d ;
    char*       val ;
    int         i ;
    char        cval[90] ;

    /* Allocate dictionary */
    printf("allocating...\n");
    d = dictionary_new(0);

    /* Set values in dictionary */
    printf("setting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        dictionary_set(d, cval, "salut");
    }

    printf("getting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        val = dictionary_get(d, cval, DICT_INVALID_KEY);

        if (val==DICT_INVALID_KEY)
        {
            printf("cannot get value for key [%s]\n", cval);
        }
    }

    printf("unsetting %d values...\n", NVALS);

    for (i=0 ; i<NVALS ; i++)
    {
        sprintf(cval, "%04d", i);
        dictionary_unset(d, cval);
    }

    if (d->n != 0)
    {
        printf("error deleting values\n");
    }

    printf("deallocating...\n");
    dictionary_del(d);
    return 0 ;
}
Ejemplo n.º 28
0
void Test_dictionary_dump(CuTest *tc)
{
    int i, j;
    char sec_name[32];
    char key_name[64];
    dictionary *dic;
    char *dump_buff;
    const char dump_real[] = "\
                sec1\t[]\n\
           sec1:key1\t[dummy_value]\n\
           sec1:key2\t[dummy_value]\n\
           sec1:key3\t[dummy_value]\n\
           sec1:key4\t[dummy_value]\n\
                sec2\t[]\n\
           sec2:key1\t[dummy_value]\n\
           sec2:key2\t[dummy_value]\n\
           sec2:key3\t[dummy_value]\n\
           sec2:key4\t[dummy_value]\n\
";

    dic = dictionary_new(DICTMINSZ);
    CuAssertPtrNotNull(tc, dic);

    /* Try dummy values */
    dictionary_dump(NULL, NULL);
    dictionary_dump(dic, NULL);

    /* Try with empty dictionary first */
    dump_buff = get_dump(dic);
    CuAssertStrEquals(tc, "empty dictionary\n", dump_buff);
    free(dump_buff);

    /* Populate the dictionary */
    for (i = 1 ; i < 3; ++i) {
        sprintf(sec_name, "sec%d", i);
        dictionary_set(dic, sec_name, "");
        for (j = 1 ; j < 5; ++j) {
            sprintf(key_name, "%s:key%d", sec_name, j);
            dictionary_set(dic, key_name, "dummy_value");
        }
    }

    /* Check the dump file */
    dump_buff = get_dump(dic);
    CuAssertStrEquals(tc, dump_real, dump_buff);
    free(dump_buff);

    dictionary_del(dic);
}
Ejemplo n.º 29
0
/**
  Test funkcji dictionary_insert().
  Wstawienie pięciu słów do słownika.
  */
static int dictionary_insert_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	if (!dict)
		return -1;
	dictionary_insert(dict, first);
	assert_true(dictionary_find(dict, first));
	assert_false(dictionary_find(dict,second));
	dictionary_insert(dict, second);
	dictionary_insert(dict, third);
	dictionary_insert(dict, fourth);
	dictionary_insert(dict, fifth);
	*state = dict;
	return 0;
}
Ejemplo n.º 30
0
/**
  Przygotowsuje środowisko testowe
  @param state Środowisko testowe.
  @return 0 jeśli się udało, -1 w p.p.
  */
static int dictionary_setup(void **state)
{
    struct dictionary *dict = dictionary_new();

    size_t n_words = 6;
    wchar_t *words[] = {L"felin", L"fen", L"fin", L"féin", L"mein", L"tein"};

    for (size_t i = 0; i < n_words; i++)
    {
        dictionary_insert(dict, words[i]);
    }

    *state = dict;

    return 0;
}