4
static void conv_vnote(const char *filename)
6
char *command = g_strdup_printf("cp %s/"OPENSYNC_TESTDATA"%s .", g_get_current_dir(), filename);
7
char *testbed = setup_testbed(NULL);
12
OSyncError *error = NULL;
13
OSyncEnv *env = init_env();
15
OSyncFormatEnv *conv_env = osync_conv_env_new(env);
16
fail_unless(conv_env != NULL, NULL);
21
char *file = g_path_get_basename(filename);
22
fail_unless(osync_file_read(file, &buffer, &size, &error), NULL);
24
OSyncChange *change = osync_change_new();
25
osync_change_set_uid(change, file);
26
osync_change_set_data(change, buffer, size + 1, TRUE);
27
osync_change_set_conv_env(change, conv_env);
29
osync_change_set_objformat_string(change, "plain");
31
OSyncObjFormat *sourceformat = osync_change_detect_objformat(conv_env, change, &error);
32
fail_unless(sourceformat != NULL, NULL);
33
osync_change_set_objformat(change, sourceformat);
34
osync_change_set_objtype(change, osync_objformat_get_objtype(sourceformat));
36
OSyncObjFormat *targetformat = osync_conv_find_objformat(conv_env, "xml-note");
37
fail_unless(targetformat != NULL, NULL);
39
OSyncChange *newchange = osync_change_copy(change, &error);
40
fail_unless(newchange != NULL, NULL);
43
fail_unless(osync_change_convert(conv_env, change, targetformat, &error), NULL);
46
fail_unless(osync_change_compare(newchange, change) == CONV_DATA_SAME, NULL);
49
fail_unless(osync_change_convert(conv_env, change, sourceformat, &error), NULL);
51
//Detect the output again
52
osync_change_set_objformat_string(change, "plain");
53
fail_unless(osync_change_detect_objformat(conv_env, change, &error) == sourceformat, NULL);
56
fail_unless(osync_change_compare(newchange, change) == CONV_DATA_SAME, NULL);
58
osync_conv_env_free(conv_env);
59
osync_env_finalize(env, NULL);
62
destroy_testbed(testbed);
65
static void compare_vnote(const char *lfilename, const char *rfilename, OSyncConvCmpResult result)
67
char *command1 = g_strdup_printf("cp %s/"OPENSYNC_TESTDATA"%s lfile", g_get_current_dir(), lfilename);
68
char *command2 = g_strdup_printf("cp %s/"OPENSYNC_TESTDATA"%s rfile", g_get_current_dir(), rfilename);
69
char *testbed = setup_testbed(NULL);
75
OSyncError *error = NULL;
76
OSyncEnv *env = init_env();
78
OSyncFormatEnv *conv_env = osync_conv_env_new(env);
79
fail_unless(conv_env != NULL, NULL);
84
fail_unless(osync_file_read("lfile", &buffer, &size, &error), NULL);
86
OSyncChange *lchange = osync_change_new();
87
osync_change_set_uid(lchange, "lfile");
88
osync_change_set_data(lchange, buffer, size + 1, TRUE);
89
osync_change_set_conv_env(lchange, conv_env);
90
osync_change_set_objformat_string(lchange, "plain");
92
OSyncObjFormat *sourceformat = osync_change_detect_objformat(conv_env, lchange, &error);
93
fail_unless(sourceformat != NULL, NULL);
94
osync_change_set_objformat(lchange, sourceformat);
95
osync_change_set_objtype(lchange, osync_objformat_get_objtype(sourceformat));
97
fail_unless(osync_file_read("rfile", &buffer, &size, &error), NULL);
99
OSyncChange *rchange = osync_change_new();
100
osync_change_set_uid(rchange, "rfile");
101
osync_change_set_data(rchange, buffer, size + 1, TRUE);
102
osync_change_set_conv_env(rchange, conv_env);
103
osync_change_set_objformat_string(rchange, "plain");
105
sourceformat = osync_change_detect_objformat(conv_env, rchange, &error);
106
fail_unless(sourceformat != NULL, NULL);
107
osync_change_set_objformat(rchange, sourceformat);
108
osync_change_set_objtype(rchange, osync_objformat_get_objtype(sourceformat));
110
fail_unless(osync_change_compare(lchange, rchange) == result, NULL);
112
osync_conv_env_free(conv_env);
113
osync_env_finalize(env, NULL);
115
destroy_testbed(testbed);
118
static time_t vnote_get_revision(const char *filename)
120
char *command = g_strdup_printf("cp %s/"OPENSYNC_TESTDATA"%s .", g_get_current_dir(), filename);
121
char *testbed = setup_testbed(NULL);
126
OSyncError *error = NULL;
127
OSyncEnv *env = init_env();
129
OSyncFormatEnv *conv_env = osync_conv_env_new(env);
130
fail_unless(conv_env != NULL, NULL);
135
char *file = g_path_get_basename(filename);
136
fail_unless(osync_file_read(file, &buffer, &size, &error), NULL);
138
OSyncChange *change = osync_change_new();
139
osync_change_set_uid(change, file);
141
osync_change_set_data(change, buffer, size + 1, TRUE);
142
osync_change_set_conv_env(change, conv_env);
144
osync_change_set_objformat_string(change, "plain");
146
OSyncObjFormat *sourceformat = osync_change_detect_objformat(conv_env, change, &error);
147
fail_unless(sourceformat != NULL, NULL);
148
osync_change_set_objformat(change, sourceformat);
150
OSyncObjFormat *targetformat = osync_conv_find_objformat(conv_env, "xml-note");
151
fail_unless(targetformat != NULL, NULL);
153
fail_unless(osync_change_convert(conv_env, change, targetformat, &error), NULL);
155
time_t time = osync_change_get_revision(change, &error);
157
osync_conv_env_free(conv_env);
158
osync_env_finalize(env, NULL);
161
destroy_testbed(testbed);
165
START_TEST (conv_vnote1)
167
conv_vnote("data/vnotes/vnote1.vnt");
171
START_TEST (conv_vnote2)
173
conv_vnote("data/vnotes/vnote2.vnt");
177
START_TEST (conv_vnote3)
179
conv_vnote("data/vnotes/vnote3.vnt");
183
START_TEST (conv_vnote_minimal)
185
conv_vnote("data/vnotes/vnote-minimal.vnt");
189
START_TEST (get_revision1)
191
struct tm testtm = {0, 0, 0, 6, 4 - 1, 2005 - 1900, 0, 0, 0};
192
fail_unless(vnote_get_revision("data/vnotes/vnote1.vnt") == mktime(&testtm), NULL);
196
START_TEST (get_revision2)
198
struct tm testtm = {1, 1, 1, 6, 4 - 1, 2005 - 1900, 0, 0, 0};
199
fail_unless(vnote_get_revision("data/vnotes/vnote2.vnt") == mktime(&testtm), NULL);
203
START_TEST (get_revision3)
205
struct tm testtm = {0, 0, 0, 6, 4 - 1, 2005 - 1900, 0, 0, 0};
206
fail_unless(vnote_get_revision("data/vnotes/vnote3.vnt") == mktime(&testtm), NULL);
210
START_TEST (get_revision4)
212
fail_unless(vnote_get_revision("data/vnotes/vnote-minimal.vnt") == -1, NULL);
216
START_TEST (compare_vnote_same1)
218
compare_vnote("data/vnotes/vnote1.vnt", "data/vnotes/vnote1.vnt", CONV_DATA_SAME);
222
START_TEST (compare_vnote_same2)
224
compare_vnote("data/vnotes/vnote1.vnt", "data/vnotes/vnote1-same.vnt", CONV_DATA_SAME);
228
START_TEST (compare_vnote_similar1)
230
compare_vnote("data/vnotes/vnote1.vnt", "data/vnotes/vnote1-similar.vnt", CONV_DATA_SIMILAR);
234
START_TEST (compare_vnote_mismatch1)
236
compare_vnote("data/vnotes/vnote1.vnt", "data/vnotes/vnote2.vnt", CONV_DATA_MISMATCH);
240
START_TEST (compare_vnote_mismatch2)
242
compare_vnote("data/vnotes/vnote1.vnt", "data/vnotes/vnote-minimal.vnt", CONV_DATA_MISMATCH);
246
Suite *vnote_suite(void)
248
Suite *s = suite_create("VNote");
249
//Suite *s2 = suite_create("VNote");
251
create_case(s, "conv_vnote1", conv_vnote1);
252
create_case(s, "conv_vnote2", conv_vnote2);
253
create_case(s, "conv_vnote3", conv_vnote3);
254
create_case(s, "conv_vnote_minimal", conv_vnote_minimal);
256
create_case(s, "get_revision1", get_revision1);
257
create_case(s, "get_revision2", get_revision2);
258
create_case(s, "get_revision3", get_revision3);
259
create_case(s, "get_revision4", get_revision4);
261
create_case(s, "compare_vnote_same1", compare_vnote_same1);
262
create_case(s, "compare_vnote_same2", compare_vnote_same2);
263
create_case(s, "compare_vnote_similar1", compare_vnote_similar1);
264
create_case(s, "compare_vnote_mismatch1", compare_vnote_mismatch1);
265
create_case(s, "compare_vnote_mismatch2", compare_vnote_mismatch2);
274
Suite *s = vnote_suite();
277
sr = srunner_create(s);
278
srunner_run_all(sr, CK_NORMAL);
279
nf = srunner_ntests_failed(sr);
281
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;