コード例 #1
0
END_TEST

START_TEST(eet_test_file_data_dump)
{
   Eet_Data_Descriptor *edd;
   Eet_Test_Ex_Type *result;
   Eet_Data_Descriptor_Class eddc;
   Eet_Test_Ex_Type etbt;
   Eet_File *ef;
   char *string1;
   char *file;
   int test;
   int tmpfd;

   file = strdup("/tmp/eet_suite_testXXXXXX");

   eet_init();

   eet_test_ex_set(&etbt, 0);
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.hash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2));
   eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2));
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ihash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
   eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
   etbt.slist = eina_list_prepend(NULL, "test");
   etbt.shash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
   memset(&etbt.charray, 0, sizeof(etbt.charray));
   etbt.charray[0] = "test";

   eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc),
                                           "Eet_Test_Ex_Type",
                                           sizeof(Eet_Test_Ex_Type));

   edd = eet_data_descriptor_file_new(&eddc);
   fail_if(!edd);

   eet_build_ex_descriptor(edd, EINA_FALSE);

   fail_if(-1 == (tmpfd = mkstemp(file)));
   fail_if(!!close(tmpfd));

   /* Save the encoded data in a file. */
   ef = eet_open(file, EET_FILE_MODE_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));

   eet_close(ef);

   /* Use dump/undump in the middle */
   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   string1 = NULL;
   fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1);
   fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
   fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1));

   eet_close(ef);

   /* Test the correctness of the reinsertion. */
   ef = eet_open(file, EET_FILE_MODE_READ);
   fail_if(!ef);

   result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
   fail_if(!result);

   eet_close(ef);

   /* Test the resulting data. */
   fail_if(eet_test_ex_check(result, 0, EINA_TRUE) != 0);
   fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0);
   fail_if(eina_list_data_get(result->ilist) == NULL);
   fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
   fail_if(eina_list_data_get(result->slist) == NULL);
   fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
   fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
   fail_if(strcmp(result->charray[0], "test") != 0);

   test = 0;
   _dump_call = EINA_TRUE;
   if (result->hash)
     eina_hash_foreach(result->hash, func, &test);
   _dump_call = EINA_FALSE;

   fail_if(test != 0);
   if (result->ihash)
     eina_hash_foreach(result->ihash, func7, &test);

   fail_if(test != 0);

   fail_if(unlink(file) != 0);

   eet_shutdown();
}
コード例 #2
0
ファイル: config.c プロジェクト: Limsik/e17
static void*
config_load(Eet_Data_Descriptor *descriptor, const char *filename, const char *section)
{
  Eet_File *ef;
  void *result;
  char buffer[PATH_MAX];
  struct stat st_readable;
  struct stat st_binary;
  Eina_Bool stre;
  Eina_Bool stbe;
  Eina_Bool take_binary = EINA_TRUE;

  snprintf(buffer, PATH_MAX, "%s.eet", filename);
  stbe = !!stat(buffer, &st_binary);

  snprintf(buffer, PATH_MAX, "%s.%s", filename, section);
  stre = !!stat(buffer, &st_readable);

  if (stbe && stre) return NULL;

  if (!stre && !stbe && st_readable.st_mtime > st_binary.st_mtime)
    take_binary = EINA_FALSE;

  if (stbe) take_binary = EINA_FALSE;
  if (stre) take_binary = EINA_TRUE;
  
  if (take_binary)
    {
      fprintf(stderr, "Taking binary config\n");

      snprintf(buffer, PATH_MAX, "%s.eet", filename);
      ef = eet_open(buffer, EET_FILE_MODE_READ);
      result = eet_data_read(ef, descriptor, section);
      eet_close(ef);
    }
  else
    {
      char *tmp;
      struct stat st;
      int fd;

      fprintf(stderr, "Taking human readable config\n");

      snprintf(buffer, PATH_MAX, "%s.%s", filename, section);
      fd = open(filename, O_RDONLY);
      
      tmp = malloc(st_readable.st_size + 1);
      read(fd, tmp, st_readable.st_size);
      tmp[st_readable.st_size] = '\0';
      close(fd);

      snprintf(buffer, PATH_MAX, "%s.eet", filename);
      ef = eet_open(buffer, EET_FILE_MODE_READ_WRITE);
      eet_data_undump(ef, section, tmp, st_readable.st_size, 1);
      result = eet_data_read(ef, descriptor, section);
      
      eet_close(ef);
    }

  return result;
}
コード例 #3
0
ファイル: ems_config.c プロジェクト: chep/Enna-Media-Server
static void
_make_config(const char *config_file)
{
	Eet_File *ef;
	FILE *f;
	int textlen;
	char *text;

	/* Create default config path and file */
	if (!config_file)
	{
		conf_filename = eina_stringshare_add(ems_config_filename_default_get());
		if (!ecore_file_is_dir(ems_config_dirname_get()))
			ecore_file_mkpath(ems_config_dirname_get());
	}
	else if (!ecore_file_exists(config_file))
	{
		conf_filename = eina_stringshare_add(config_file);
		ecore_file_mkpath(ecore_file_dir_get(config_file));
	}
	else
	{
		conf_filename = eina_stringshare_add(config_file);
	}

	INF("Config file : %s", conf_filename);

	if (!ecore_file_is_dir(ems_config_tmp_dirname_get()))
		ecore_file_mkdir(ems_config_tmp_dirname_get());
	ef = eet_open(ems_config_tmp_filename_get(),
	              EET_FILE_MODE_READ_WRITE);
	if (!ef)
		ef = eet_open(ems_config_tmp_filename_get(),
		              EET_FILE_MODE_WRITE);

	f = fopen(conf_filename, "rb");
	if (!f)
	{
		WRN("Could not open '%s', setup default config.", ems_config_filename_get());
		if (ecore_file_exists(ems_config_default_filename_get()))
		{
			ecore_file_cp(ems_config_default_filename_get(), ems_config_filename_get());
			f = fopen(ems_config_filename_get(), "rb");
			if (!f)
				return;
		}
		else
			return;
	}

	fseek(f, 0, SEEK_END);
	textlen = ftell(f);
	rewind(f);
	text = (char *)malloc(textlen);
	if (!text)
	{
		fclose(f);
		eet_close(ef);
		return;
	}

	if (fread(text, textlen, 1, f) != 1)
	{
		free(text);
		fclose(f);
		eet_close(ef);
		return;
	}

	fclose(f);
	if (eet_data_undump(ef, "config", text, textlen, 1))
		INF("Updating configuration %s", conf_filename);
	free(text);
	eet_close(ef);
}