File:  [ELWIX - Embedded LightWeight unIX -] / libaitcfg / example / test.c
Revision 1.2.8.1: download - view: text, annotated - select for diffs - revision graph
Mon Aug 6 14:52:51 2012 UTC (10 years, 2 months ago) by misho
Branches: cfg5_4
Diff to: branchpoint 1.2: preferred, colored
fix bugs appeared from last version of libaitio

#include <stdio.h>
#include <sys/types.h>
#include <aitcfg.h>


int main()
{
	cfg_root_t lst, tmp;
	char szStr[256];
	struct tagCfg *av;
	ait_val_t v;

	printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst));
	printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
	printf("Find Attribute at position=%d\n", cfg_findAttribute(&lst, NULL, "testattr"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "testattr"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122277777777"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "att"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, NULL, "att"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));

	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "section", "attr3", NULL));
	printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "section", "attr3", &v, "iH"));
	printf("Str=%s\n", AIT_GET_STR(&v));
	AIT_FREE_VAL(&v);
	printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "", "testattr", &v, "iH2"));
	printf("Str=%s\n", AIT_GET_STR(&v));
	AIT_FREE_VAL(&v);

	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
	cfgUnloadConfig(&lst);
	printf("0) ---------------------------------\n");

	printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));

	cfgInitConfig(&tmp);
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "BLAHzdf"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999 sdfbj"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777555"));

	cfgInitConfig(&lst);
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "zzz", "ZZZ"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122222222222"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
	printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
	printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
	printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999"));

	cfgWriteConfig(stdout, &tmp, 0);
	cfgWriteConfig(stdout, &lst, 1);
	printf("1) ---------------------------------\n");

#ifndef SKIP_TEST_CONCAT
	printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
	cfgWriteConfig(stdout, &lst, 0);
	printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
	cfgWriteConfig(stdout, &lst, 1);
#else
	cfgUnloadConfig(&tmp);
#endif

	cfgInitConfig(&tmp);
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiiiiii"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777"));
	printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho"));

#ifndef SKIP_TEST_MERGE
	printf("before_merge ---------------------------------\n");
	cfgWriteConfig(stdout, &lst, 1);
	printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(&lst, &tmp));
	cfgWriteConfig(stdout, &lst, 1);
#else
	cfgUnloadConfig(&tmp);
#endif

	printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", &lst, 1));
	printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());

	cfgUnloadConfig(&tmp);
	cfgUnloadConfig(&lst);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>