Changeset 3373
- Timestamp:
- 06/16/08 21:01:42 (3 months ago)
- Files:
-
- trunk/tests/mock-plugin/mock_sync.c (modified) (17 diffs)
- trunk/tests/mock-plugin/mock_sync.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tests/mock-plugin/mock_sync.c
r3361 r3373 44 44 } 45 45 46 static void free_env(mock_env *env)47 {48 while (env->directories) {49 MockDir *dir = env->directories->data;50 51 if (dir->sink)52 osync_objtype_sink_unref(dir->sink);53 54 env->directories = g_list_remove(env->directories, dir);55 }56 57 if (env->mainsink)58 osync_objtype_sink_unref(env->mainsink);59 60 g_free(env);61 }62 63 46 static char *mock_generate_hash(struct stat *buf) 64 47 { … … 106 89 char *path_field = g_strdup_printf("path_%s", osync_objtype_sink_get_name(sink)); 107 90 if (!osync_anchor_compare(anchorpath, path_field, dir->path)) 108 osync_objtype_sink_set_slowsync( dir->sink, TRUE);91 osync_objtype_sink_set_slowsync(sink, TRUE); 109 92 110 93 g_free(anchorpath); … … 168 151 MockDir *dir = osync_objtype_sink_get_userdata(sink); 169 152 OSyncError *error = NULL; 170 153 171 154 char *filename = g_strdup_printf("%s/%s", dir->path, osync_change_get_uid(change)); 172 155 … … 183 166 184 167 osync_assert(osync_file_read(filename, &(file->data), &(file->size), &error)); 168 185 169 OSyncData *odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), dir->objformat, &error); 186 170 osync_assert(odata); … … 266 250 osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, directory, subdir, ctx); 267 251 252 OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 253 osync_assert(sink); 254 255 OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 256 osync_assert(formatenv); 257 268 258 path = g_build_filename(directory->path, subdir, NULL); 269 259 osync_trace(TRACE_INTERNAL, "path %s", path); … … 305 295 g_free(filename); 306 296 g_free(relative_filename); 297 osync_change_unref(change); 307 298 continue; 308 299 } … … 315 306 OSyncData *odata = NULL; 316 307 317 if (mock_get_error(info->memberid, "ONLY_INFO")) { 318 odata = osync_data_new(NULL, 0, directory->objformat, &error); 319 } else { 308 if (!mock_get_error(info->memberid, "ONLY_INFO")) { 320 309 osync_assert(osync_file_read(filename, &(file->data), &(file->size), &error)); 321 310 … … 326 315 osync_assert(odata); 327 316 317 318 osync_change_set_data(change, odata); 319 328 320 } 329 321 330 osync_data_set_objtype(odata, osync_objtype_sink_get_name(directory->sink)); 331 osync_change_set_data(change, odata); 322 osync_data_set_objtype(odata, osync_objtype_sink_get_name(sink)); 332 323 osync_data_unref(odata); 333 324 … … 372 363 sleep(8); 373 364 374 if (osync_objtype_sink_get_slowsync( dir->sink)) {365 if (osync_objtype_sink_get_slowsync(sink)) { 375 366 osync_trace(TRACE_INTERNAL, "Slow sync requested"); 376 367 osync_assert(osync_hashtable_slowsync(dir->hashtable, &error)); … … 556 547 mock_env *env = osync_try_malloc0(sizeof(mock_env), error); 557 548 osync_assert(env); 558 559 osync_trace(TRACE_INTERNAL, "The config: %s", osync_plugin_info_get_config(info)); 549 550 OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 551 osync_assert(formatenv); 552 553 OSyncPluginConfig *config = osync_plugin_info_get_config(info); 554 osync_assert(config); 560 555 561 556 if (mock_get_error(info->memberid, "MAINSINK_CONNECT")) { … … 575 570 * synchronize any objtype we configure it to sync and where a conversion 576 571 * path to the file format can be found */ 577 GList *o = env->directories; 578 for (; o; o = o->next) { 579 MockDir *dir = o->data; 580 /* We register the given objtype here */ 581 OSyncObjTypeSink *sink = osync_objtype_sink_new(dir->objtype, error); 572 int i, numobjs = osync_plugin_info_num_objtypes(info); 573 for (i = 0; i < numobjs; i++) { 574 MockDir *dir = osync_try_malloc0(sizeof(MockDir), error); 575 osync_assert(dir); 576 577 dir->committed_all = TRUE; 578 579 OSyncObjTypeSink *sink = osync_plugin_info_nth_objtype(info, i); 582 580 osync_assert(sink); 583 584 dir->sink = sink; 585 581 582 OSyncList *r = osync_plugin_config_get_ressources(config); 583 for (; r; r = r->next) { 584 OSyncPluginRessource *res = r->data; 585 586 OSyncList *o = osync_plugin_ressource_get_objformat_sinks(res); 587 for (; o; o = o->next) { 588 OSyncObjFormatSink *format_sink = (OSyncObjFormatSink *) o->data; 589 const char *objformat_str = osync_objformat_sink_get_objformat(format_sink); 590 osync_assert(objformat_str); 591 OSyncObjFormat *objformat = osync_format_env_find_objformat(formatenv, objformat_str); 592 osync_assert(objformat); 593 const char *objtype = osync_objformat_get_objtype(objformat); 594 osync_assert(objtype); 595 if (!strcmp(objtype, osync_objtype_sink_get_name(sink))) { 596 dir->res = osync_plugin_ressource_ref(res); 597 dir->path = g_strdup(osync_plugin_ressource_get_path(res)); 598 dir->objformat = osync_objformat_ref(objformat); 599 break; 600 } 601 602 } 603 604 if (dir->res) 605 break; 606 } 607 586 608 osync_trace(TRACE_INTERNAL, "The configdir: %s", osync_plugin_info_get_configdir(info)); 587 609 char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); … … 593 615 osync_assert(osync_hashtable_load(dir->hashtable, error)); 594 616 617 618 /* 595 619 const char *objformat = osync_objformat_get_name(dir->objformat); 596 620 OSyncObjFormatSink *format_sink = osync_objformat_sink_new(objformat, error); … … 599 623 600 624 osync_objtype_sink_add_objformat_sink(sink, format_sink); 625 */ 601 626 602 627 /* All sinks have the same functions of course */ … … 626 651 * again once the functions are called */ 627 652 osync_objtype_sink_set_functions(sink, functions, dir); 628 osync_plugin_info_add_objtype(info, sink);629 653 630 654 //Lets reduce the timeouts a bit so the checks work faster … … 671 695 */ 672 696 673 #endif 697 #endif 698 env->directories = g_list_append(env->directories, dir); 674 699 } 675 700 … … 682 707 mock_env *env = data; 683 708 684 GList *o = env->directories; 685 for (; o; o = o->next) { 686 MockDir *dir = o->data; 687 688 if (dir->hashtable) { 689 osync_hashtable_unref(dir->hashtable); 690 dir->hashtable = NULL; 691 } 692 693 694 } 695 696 free_env(env); 709 while (env->directories) { 710 MockDir *dir = env->directories->data; 711 712 osync_plugin_ressource_unref(dir->res); 713 osync_objformat_unref(dir->objformat); 714 osync_hashtable_unref(dir->hashtable); 715 716 env->directories = g_list_remove(env->directories, dir); 717 } 718 719 if (env->mainsink) 720 osync_objtype_sink_unref(env->mainsink); 721 722 723 g_free(env); 697 724 } 698 725 … … 703 730 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data, info, error); 704 731 705 mock_env *env = (mock_env *)data; 706 GList *o = env->directories; 707 for (; o; o = o->next) { 708 MockDir *dir = o->data; 709 osync_objtype_sink_set_available(dir->sink, TRUE); 710 } 732 OSyncPluginConfig *config = osync_plugin_info_get_config(info); 733 osync_assert_msg(config, "No OSyncPluginConfig set for mock_discover!"); 734 735 OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 736 osync_assert_msg(config, "No OSyncFormatEnv set for mock_discover!"); 737 738 OSyncList *r = osync_plugin_config_get_ressources(config); 739 for (; r; r = r->next) { 740 OSyncPluginRessource *res = r->data; 741 OSyncObjTypeSink *sink; 742 743 OSyncList *o = osync_plugin_ressource_get_objformat_sinks(res); 744 for (; o; o = o->next) { 745 OSyncObjFormatSink *format_sink = (OSyncObjFormatSink *) o->data; 746 const char *objformat_str = osync_objformat_sink_get_objformat(format_sink); 747 OSyncObjFormat *objformat = osync_format_env_find_objformat(formatenv, objformat_str); 748 const char *objtype = osync_objformat_get_objtype(objformat); 749 750 osync_trace(TRACE_INTERNAL, "objtype: %s\n", objtype); 751 752 /* Check for ObjType sink */ 753 if ((sink = osync_plugin_info_find_objtype(info, objtype))) 754 osync_objtype_sink_set_available(sink, TRUE); 755 } 756 } 757 711 758 712 759 OSyncVersion *version = osync_version_new(error); trunk/tests/mock-plugin/mock_sync.h
r3360 r3373 19 19 */ 20 20 21 #ifndef _ FILE_PLUGIN_H22 #define _ FILE_PLUGIN_H21 #ifndef _MOCK_PLUGIN_H 22 #define _MOCK_PLUGIN_H 23 23 24 24 #include <stdlib.h> … … 27 27 #include <glib.h> 28 28 #include <string.h> 29 30 #include <libxml/xmlmemory.h>31 #include <libxml/parser.h>32 29 33 30 #include <opensync/opensync.h> … … 66 63 67 64 typedef struct MockDir { 68 char *objtype; 65 OSyncObjFormat *objformat; 66 OSyncPluginRessource *res; 67 GDir *dir; 69 68 char *path; 70 OSyncObjFormat *objformat;71 GDir *dir;72 69 OSyncHashTable *hashtable; 73 OSyncObjTypeSink *sink;74 70 mock_env *env; 75 71 osync_bool committed_all; 76 72 } MockDir; 77 73 78 #endif //_ FILE_PLUGIN_H74 #endif //_MOCK_PLUGIN_H
