| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2020 Collabora Ltd. |
| 4 |
* @author George Kiagiadakis <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "../common/base-test-fixture.h" |
| 10 |
|
| 11 |
typedef struct { |
| 12 |
WpBaseTestFixture base; |
| 13 |
|
| 14 |
WpObjectManager *export_om; |
| 15 |
WpObjectManager *proxy_om; |
| 16 |
|
| 17 |
WpMetadata *impl_metadata; |
| 18 |
WpMetadata *proxy_metadata; |
| 19 |
|
| 20 |
gint n_events; |
| 21 |
|
| 22 |
} TestFixture; |
| 23 |
|
| 24 |
static void |
| 25 |
test_metadata_setup (TestFixture *self, gconstpointer user_data) |
| 26 |
{ |
| 27 |
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE); |
| 28 |
self->export_om = wp_object_manager_new (); |
| 29 |
self->proxy_om = wp_object_manager_new (); |
| 30 |
} |
| 31 |
|
| 32 |
static void |
| 33 |
test_metadata_teardown (TestFixture *self, gconstpointer user_data) |
| 34 |
{ |
| 35 |
g_clear_object (&self->proxy_om); |
| 36 |
g_clear_object (&self->export_om); |
| 37 |
wp_base_test_fixture_teardown (&self->base); |
| 38 |
} |
| 39 |
|
| 40 |
static void |
| 41 |
test_metadata_basic_exported_object_added (WpObjectManager *om, |
| 42 |
WpMetadata *metadata, TestFixture *fixture) |
| 43 |
{ |
| 44 |
g_debug ("exported object added"); |
| 45 |
|
| 46 |
g_assert_true (WP_IS_IMPL_METADATA (metadata)); |
| 47 |
|
| 48 |
g_assert_null (fixture->impl_metadata); |
| 49 |
fixture->impl_metadata = WP_METADATA (metadata); |
| 50 |
|
| 51 |
if (++fixture->n_events == 3) |
| 52 |
g_main_loop_quit (fixture->base.loop); |
| 53 |
} |
| 54 |
|
| 55 |
static void |
| 56 |
test_metadata_basic_exported_object_removed (WpObjectManager *om, |
| 57 |
WpMetadata *metadata, TestFixture *fixture) |
| 58 |
{ |
| 59 |
g_debug ("exported object removed"); |
| 60 |
|
| 61 |
g_assert_true (WP_IS_IMPL_METADATA (metadata)); |
| 62 |
|
| 63 |
g_assert_nonnull (fixture->impl_metadata); |
| 64 |
fixture->impl_metadata = NULL; |
| 65 |
|
| 66 |
if (++fixture->n_events == 2) |
| 67 |
g_main_loop_quit (fixture->base.loop); |
| 68 |
} |
| 69 |
|
| 70 |
static void |
| 71 |
test_metadata_basic_proxy_object_added (WpObjectManager *om, |
| 72 |
WpMetadata *metadata, TestFixture *fixture) |
| 73 |
{ |
| 74 |
g_debug ("proxy object added"); |
| 75 |
|
| 76 |
g_assert_true (WP_IS_METADATA (metadata)); |
| 77 |
|
| 78 |
g_assert_null (fixture->proxy_metadata); |
| 79 |
fixture->proxy_metadata = WP_METADATA (metadata); |
| 80 |
|
| 81 |
if (++fixture->n_events == 3) |
| 82 |
g_main_loop_quit (fixture->base.loop); |
| 83 |
} |
| 84 |
|
| 85 |
static void |
| 86 |
test_metadata_basic_proxy_object_removed (WpObjectManager *om, |
| 87 |
WpMetadata *metadata, TestFixture *fixture) |
| 88 |
{ |
| 89 |
g_debug ("proxy object removed"); |
| 90 |
|
| 91 |
g_assert_true (WP_IS_METADATA (metadata)); |
| 92 |
|
| 93 |
g_assert_nonnull (fixture->proxy_metadata); |
| 94 |
fixture->proxy_metadata = NULL; |
| 95 |
|
| 96 |
if (++fixture->n_events == 2) |
| 97 |
g_main_loop_quit (fixture->base.loop); |
| 98 |
} |
| 99 |
|
| 100 |
static void |
| 101 |
test_metadata_basic_export_done (WpObject * metadata, GAsyncResult * res, |
| 102 |
TestFixture *fixture) |
| 103 |
{ |
| 104 |
g_autoptr (GError) error = NULL; |
| 105 |
|
| 106 |
g_debug ("export done"); |
| 107 |
|
| 108 |
g_assert_true (wp_object_activate_finish (metadata, res, &error)); |
| 109 |
g_assert_no_error (error); |
| 110 |
|
| 111 |
g_assert_true (WP_IS_IMPL_METADATA (metadata)); |
| 112 |
|
| 113 |
if (++fixture->n_events == 3) |
| 114 |
g_main_loop_quit (fixture->base.loop); |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
test_metadata_basic_changed (WpMetadata *metadata, guint32 subject, |
| 119 |
const gchar *key, const gchar *type, const gchar *value, |
| 120 |
TestFixture *fixture) |
| 121 |
{ |
| 122 |
g_debug ("changed: %u %s", subject, key); |
| 123 |
|
| 124 |
g_assert_true (WP_IS_METADATA (metadata)); |
| 125 |
g_assert_cmpuint (subject, !=, PW_ID_ANY); |
| 126 |
|
| 127 |
if (++fixture->n_events == 4) |
| 128 |
g_main_loop_quit (fixture->base.loop); |
| 129 |
} |
| 130 |
|
| 131 |
static void |
| 132 |
test_metadata_basic (TestFixture *fixture, gconstpointer data) |
| 133 |
{ |
| 134 |
g_autoptr (WpMetadata) metadata = NULL; |
| 135 |
|
| 136 |
/* set up the export side */ |
| 137 |
g_signal_connect (fixture->export_om, "object_added", |
| 138 |
(GCallback) test_metadata_basic_exported_object_added, fixture); |
| 139 |
g_signal_connect (fixture->export_om, "object-removed", |
| 140 |
(GCallback) test_metadata_basic_exported_object_removed, fixture); |
| 141 |
wp_object_manager_add_interest (fixture->export_om, WP_TYPE_IMPL_METADATA, |
| 142 |
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "metadata.name", "=s", "default", |
| 143 |
NULL); |
| 144 |
wp_object_manager_request_object_features (fixture->export_om, |
| 145 |
WP_TYPE_IMPL_METADATA, WP_OBJECT_FEATURES_ALL); |
| 146 |
wp_core_install_object_manager (fixture->base.core, fixture->export_om); |
| 147 |
|
| 148 |
/* set up the proxy side */ |
| 149 |
g_signal_connect (fixture->proxy_om, "object_added", |
| 150 |
(GCallback) test_metadata_basic_proxy_object_added, fixture); |
| 151 |
g_signal_connect (fixture->proxy_om, "object-removed", |
| 152 |
(GCallback) test_metadata_basic_proxy_object_removed, fixture); |
| 153 |
wp_object_manager_add_interest (fixture->proxy_om, WP_TYPE_METADATA, |
| 154 |
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "metadata.name", "=s", "default", |
| 155 |
NULL); |
| 156 |
wp_object_manager_request_object_features (fixture->proxy_om, |
| 157 |
WP_TYPE_METADATA, WP_OBJECT_FEATURES_ALL); |
| 158 |
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om); |
| 159 |
|
| 160 |
/* create metadata */ |
| 161 |
metadata = WP_METADATA (wp_impl_metadata_new (fixture->base.core)); |
| 162 |
wp_metadata_set (metadata, 0, "test-key", NULL, "test-value"); |
| 163 |
wp_metadata_set (metadata, 15, "toast", "Spa:Int", "15"); |
| 164 |
|
| 165 |
/* verify properties are set before export */ |
| 166 |
{ |
| 167 |
g_autoptr (WpIterator) iter = wp_metadata_new_iterator (metadata, PW_ID_ANY); |
| 168 |
g_auto (GValue) val = G_VALUE_INIT; |
| 169 |
guint subject = -1; |
| 170 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 171 |
WpMetadataItem *mi; |
| 172 |
|
| 173 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 174 |
mi = g_value_get_boxed (&val); |
| 175 |
subject = wp_metadata_item_get_subject (mi); |
| 176 |
g_assert_cmpint (subject, ==, 0); |
| 177 |
key = wp_metadata_item_get_key (mi); |
| 178 |
g_assert_cmpstr (key, ==, "test-key"); |
| 179 |
type = wp_metadata_item_get_value_type (mi); |
| 180 |
g_assert_cmpstr (type, ==, "string"); |
| 181 |
value = wp_metadata_item_get_value (mi); |
| 182 |
g_assert_cmpstr (value, ==, "test-value"); |
| 183 |
g_value_unset (&val); |
| 184 |
|
| 185 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 186 |
|
| 187 |
mi = g_value_get_boxed (&val); |
| 188 |
subject = wp_metadata_item_get_subject (mi); |
| 189 |
g_assert_cmpint (subject, ==, 15); |
| 190 |
key = wp_metadata_item_get_key (mi); |
| 191 |
g_assert_cmpstr (key, ==, "toast"); |
| 192 |
type = wp_metadata_item_get_value_type (mi); |
| 193 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 194 |
value = wp_metadata_item_get_value (mi); |
| 195 |
g_assert_cmpstr (value, ==, "15"); |
| 196 |
g_value_unset (&val); |
| 197 |
|
| 198 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 199 |
} |
| 200 |
|
| 201 |
/* do export */ |
| 202 |
wp_object_activate (WP_OBJECT (metadata), WP_OBJECT_FEATURES_ALL, NULL, |
| 203 |
(GAsyncReadyCallback) test_metadata_basic_export_done, fixture); |
| 204 |
|
| 205 |
/* run until objects are created and features are cached */ |
| 206 |
fixture->n_events = 0; |
| 207 |
g_main_loop_run (fixture->base.loop); |
| 208 |
g_assert_cmpint (fixture->n_events, ==, 3); |
| 209 |
g_assert_nonnull (fixture->impl_metadata); |
| 210 |
g_assert_nonnull (fixture->proxy_metadata); |
| 211 |
g_assert_true (fixture->impl_metadata == metadata); |
| 212 |
|
| 213 |
/* test round 1: verify the values on the proxy */ |
| 214 |
{ |
| 215 |
g_autoptr (WpIterator) iter = |
| 216 |
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY); |
| 217 |
g_auto (GValue) val = G_VALUE_INIT; |
| 218 |
guint subject = -1; |
| 219 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 220 |
WpMetadataItem *mi; |
| 221 |
|
| 222 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 223 |
mi = g_value_get_boxed (&val); |
| 224 |
subject = wp_metadata_item_get_subject (mi); |
| 225 |
g_assert_cmpint (subject, ==, 0); |
| 226 |
key = wp_metadata_item_get_key (mi); |
| 227 |
g_assert_cmpstr (key, ==, "test-key"); |
| 228 |
type = wp_metadata_item_get_value_type (mi); |
| 229 |
g_assert_cmpstr (type, ==, "string"); |
| 230 |
value = wp_metadata_item_get_value (mi); |
| 231 |
g_assert_cmpstr (value, ==, "test-value"); |
| 232 |
g_value_unset (&val); |
| 233 |
|
| 234 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 235 |
mi = g_value_get_boxed (&val); |
| 236 |
subject = wp_metadata_item_get_subject (mi); |
| 237 |
g_assert_cmpint (subject, ==, 15); |
| 238 |
key = wp_metadata_item_get_key (mi); |
| 239 |
g_assert_cmpstr (key, ==, "toast"); |
| 240 |
type = wp_metadata_item_get_value_type (mi); |
| 241 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 242 |
value = wp_metadata_item_get_value (mi); |
| 243 |
g_assert_cmpstr (value, ==, "15"); |
| 244 |
g_value_unset (&val); |
| 245 |
|
| 246 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 247 |
} |
| 248 |
|
| 249 |
/* setup change signals */ |
| 250 |
g_signal_connect (fixture->proxy_metadata, "changed", |
| 251 |
(GCallback) test_metadata_basic_changed, fixture); |
| 252 |
g_signal_connect (metadata, "changed", |
| 253 |
(GCallback) test_metadata_basic_changed, fixture); |
| 254 |
|
| 255 |
/* change properties on the proxy */ |
| 256 |
wp_metadata_set (fixture->proxy_metadata, 15, "toast", "Spa:Int", "20"); |
| 257 |
wp_metadata_set (fixture->proxy_metadata, 0, "3rd.key", NULL, "3rd.value"); |
| 258 |
|
| 259 |
/* run until the change is on both sides */ |
| 260 |
fixture->n_events = 0; |
| 261 |
g_main_loop_run (fixture->base.loop); |
| 262 |
g_assert_cmpint (fixture->n_events, ==, 4); |
| 263 |
|
| 264 |
/* test round 2: verify the value change on both sides */ |
| 265 |
{ |
| 266 |
g_autoptr (WpIterator) iter = |
| 267 |
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY); |
| 268 |
g_auto (GValue) val = G_VALUE_INIT; |
| 269 |
guint subject = -1; |
| 270 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 271 |
WpMetadataItem *mi; |
| 272 |
|
| 273 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 274 |
mi = g_value_get_boxed (&val); |
| 275 |
subject = wp_metadata_item_get_subject (mi); |
| 276 |
g_assert_cmpint (subject, ==, 0); |
| 277 |
key = wp_metadata_item_get_key (mi); |
| 278 |
g_assert_cmpstr (key, ==, "test-key"); |
| 279 |
type = wp_metadata_item_get_value_type (mi); |
| 280 |
g_assert_cmpstr (type, ==, "string"); |
| 281 |
value = wp_metadata_item_get_value (mi); |
| 282 |
g_assert_cmpstr (value, ==, "test-value"); |
| 283 |
g_value_unset (&val); |
| 284 |
|
| 285 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 286 |
mi = g_value_get_boxed (&val); |
| 287 |
subject = wp_metadata_item_get_subject (mi); |
| 288 |
g_assert_cmpint (subject, ==, 15); |
| 289 |
key = wp_metadata_item_get_key (mi); |
| 290 |
g_assert_cmpstr (key, ==, "toast"); |
| 291 |
type = wp_metadata_item_get_value_type (mi); |
| 292 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 293 |
value = wp_metadata_item_get_value (mi); |
| 294 |
g_assert_cmpstr (value, ==, "20"); |
| 295 |
g_value_unset (&val); |
| 296 |
|
| 297 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 298 |
mi = g_value_get_boxed (&val); |
| 299 |
subject = wp_metadata_item_get_subject (mi); |
| 300 |
g_assert_cmpint (subject, ==, 0); |
| 301 |
key = wp_metadata_item_get_key (mi); |
| 302 |
g_assert_cmpstr (key, ==, "3rd.key"); |
| 303 |
type = wp_metadata_item_get_value_type (mi); |
| 304 |
g_assert_cmpstr (type, ==, "string"); |
| 305 |
value = wp_metadata_item_get_value (mi); |
| 306 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 307 |
g_value_unset (&val); |
| 308 |
|
| 309 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 310 |
} |
| 311 |
{ |
| 312 |
g_autoptr (WpIterator) iter = |
| 313 |
wp_metadata_new_iterator (metadata, PW_ID_ANY); |
| 314 |
g_auto (GValue) val = G_VALUE_INIT; |
| 315 |
guint subject = -1; |
| 316 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 317 |
WpMetadataItem *mi; |
| 318 |
|
| 319 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 320 |
mi = g_value_get_boxed (&val); |
| 321 |
subject = wp_metadata_item_get_subject (mi); |
| 322 |
g_assert_cmpint (subject, ==, 0); |
| 323 |
key = wp_metadata_item_get_key (mi); |
| 324 |
g_assert_cmpstr (key, ==, "test-key"); |
| 325 |
type = wp_metadata_item_get_value_type (mi); |
| 326 |
g_assert_cmpstr (type, ==, "string"); |
| 327 |
value = wp_metadata_item_get_value (mi); |
| 328 |
g_assert_cmpstr (value, ==, "test-value"); |
| 329 |
g_value_unset (&val); |
| 330 |
|
| 331 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 332 |
mi = g_value_get_boxed (&val); |
| 333 |
subject = wp_metadata_item_get_subject (mi); |
| 334 |
g_assert_cmpint (subject, ==, 15); |
| 335 |
key = wp_metadata_item_get_key (mi); |
| 336 |
g_assert_cmpstr (key, ==, "toast"); |
| 337 |
type = wp_metadata_item_get_value_type (mi); |
| 338 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 339 |
value = wp_metadata_item_get_value (mi); |
| 340 |
g_assert_cmpstr (value, ==, "20"); |
| 341 |
g_value_unset (&val); |
| 342 |
|
| 343 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 344 |
mi = g_value_get_boxed (&val); |
| 345 |
subject = wp_metadata_item_get_subject (mi); |
| 346 |
g_assert_cmpint (subject, ==, 0); |
| 347 |
key = wp_metadata_item_get_key (mi); |
| 348 |
g_assert_cmpstr (key, ==, "3rd.key"); |
| 349 |
type = wp_metadata_item_get_value_type (mi); |
| 350 |
g_assert_cmpstr (type, ==, "string"); |
| 351 |
value = wp_metadata_item_get_value (mi); |
| 352 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 353 |
g_value_unset (&val); |
| 354 |
|
| 355 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 356 |
} |
| 357 |
|
| 358 |
/* change properties on the exported */ |
| 359 |
fixture->n_events = 0; |
| 360 |
wp_metadata_set (metadata, 0, "4th.key", NULL, "4th.value"); |
| 361 |
wp_metadata_set (metadata, 0, "test-key", NULL, "new.value"); |
| 362 |
|
| 363 |
/* run until the change is on both sides */ |
| 364 |
g_main_loop_run (fixture->base.loop); |
| 365 |
g_assert_cmpint (fixture->n_events, ==, 4); |
| 366 |
|
| 367 |
/* test round 3: verify the value change on both sides */ |
| 368 |
{ |
| 369 |
g_autoptr (WpIterator) iter = |
| 370 |
wp_metadata_new_iterator (fixture->proxy_metadata, PW_ID_ANY); |
| 371 |
g_auto (GValue) val = G_VALUE_INIT; |
| 372 |
guint subject = -1; |
| 373 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 374 |
WpMetadataItem *mi; |
| 375 |
|
| 376 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 377 |
mi = g_value_get_boxed (&val); |
| 378 |
subject = wp_metadata_item_get_subject (mi); |
| 379 |
g_assert_cmpint (subject, ==, 0); |
| 380 |
key = wp_metadata_item_get_key (mi); |
| 381 |
g_assert_cmpstr (key, ==, "test-key"); |
| 382 |
type = wp_metadata_item_get_value_type (mi); |
| 383 |
g_assert_cmpstr (type, ==, "string"); |
| 384 |
value = wp_metadata_item_get_value (mi); |
| 385 |
g_assert_cmpstr (value, ==, "new.value"); |
| 386 |
g_value_unset (&val); |
| 387 |
|
| 388 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 389 |
mi = g_value_get_boxed (&val); |
| 390 |
subject = wp_metadata_item_get_subject (mi); |
| 391 |
g_assert_cmpint (subject, ==, 15); |
| 392 |
key = wp_metadata_item_get_key (mi); |
| 393 |
g_assert_cmpstr (key, ==, "toast"); |
| 394 |
type = wp_metadata_item_get_value_type (mi); |
| 395 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 396 |
value = wp_metadata_item_get_value (mi); |
| 397 |
g_assert_cmpstr (value, ==, "20"); |
| 398 |
g_value_unset (&val); |
| 399 |
|
| 400 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 401 |
mi = g_value_get_boxed (&val); |
| 402 |
subject = wp_metadata_item_get_subject (mi); |
| 403 |
g_assert_cmpint (subject, ==, 0); |
| 404 |
key = wp_metadata_item_get_key (mi); |
| 405 |
g_assert_cmpstr (key, ==, "3rd.key"); |
| 406 |
type = wp_metadata_item_get_value_type (mi); |
| 407 |
g_assert_cmpstr (type, ==, "string"); |
| 408 |
value = wp_metadata_item_get_value (mi); |
| 409 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 410 |
g_value_unset (&val); |
| 411 |
|
| 412 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 413 |
mi = g_value_get_boxed (&val); |
| 414 |
subject = wp_metadata_item_get_subject (mi); |
| 415 |
g_assert_cmpint (subject, ==, 0); |
| 416 |
key = wp_metadata_item_get_key (mi); |
| 417 |
g_assert_cmpstr (key, ==, "4th.key"); |
| 418 |
type = wp_metadata_item_get_value_type (mi); |
| 419 |
g_assert_cmpstr (type, ==, "string"); |
| 420 |
value = wp_metadata_item_get_value (mi); |
| 421 |
g_assert_cmpstr (value, ==, "4th.value"); |
| 422 |
g_value_unset (&val); |
| 423 |
|
| 424 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 425 |
} |
| 426 |
{ |
| 427 |
g_autoptr (WpIterator) iter = |
| 428 |
wp_metadata_new_iterator (metadata, PW_ID_ANY); |
| 429 |
g_auto (GValue) val = G_VALUE_INIT; |
| 430 |
guint subject = -1; |
| 431 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 432 |
WpMetadataItem *mi; |
| 433 |
|
| 434 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 435 |
mi = g_value_get_boxed (&val); |
| 436 |
subject = wp_metadata_item_get_subject (mi); |
| 437 |
g_assert_cmpint (subject, ==, 0); |
| 438 |
key = wp_metadata_item_get_key (mi); |
| 439 |
g_assert_cmpstr (key, ==, "test-key"); |
| 440 |
type = wp_metadata_item_get_value_type (mi); |
| 441 |
g_assert_cmpstr (type, ==, "string"); |
| 442 |
value = wp_metadata_item_get_value (mi); |
| 443 |
g_assert_cmpstr (value, ==, "new.value"); |
| 444 |
g_value_unset (&val); |
| 445 |
|
| 446 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 447 |
mi = g_value_get_boxed (&val); |
| 448 |
subject = wp_metadata_item_get_subject (mi); |
| 449 |
g_assert_cmpint (subject, ==, 15); |
| 450 |
key = wp_metadata_item_get_key (mi); |
| 451 |
g_assert_cmpstr (key, ==, "toast"); |
| 452 |
type = wp_metadata_item_get_value_type (mi); |
| 453 |
g_assert_cmpstr (type, ==, "Spa:Int"); |
| 454 |
value = wp_metadata_item_get_value (mi); |
| 455 |
g_assert_cmpstr (value, ==, "20"); |
| 456 |
g_value_unset (&val); |
| 457 |
|
| 458 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 459 |
mi = g_value_get_boxed (&val); |
| 460 |
subject = wp_metadata_item_get_subject (mi); |
| 461 |
g_assert_cmpint (subject, ==, 0); |
| 462 |
key = wp_metadata_item_get_key (mi); |
| 463 |
g_assert_cmpstr (key, ==, "3rd.key"); |
| 464 |
type = wp_metadata_item_get_value_type (mi); |
| 465 |
g_assert_cmpstr (type, ==, "string"); |
| 466 |
value = wp_metadata_item_get_value (mi); |
| 467 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 468 |
g_value_unset (&val); |
| 469 |
|
| 470 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 471 |
mi = g_value_get_boxed (&val); |
| 472 |
subject = wp_metadata_item_get_subject (mi); |
| 473 |
g_assert_cmpint (subject, ==, 0); |
| 474 |
key = wp_metadata_item_get_key (mi); |
| 475 |
g_assert_cmpstr (key, ==, "4th.key"); |
| 476 |
type = wp_metadata_item_get_value_type (mi); |
| 477 |
g_assert_cmpstr (type, ==, "string"); |
| 478 |
value = wp_metadata_item_get_value (mi); |
| 479 |
g_assert_cmpstr (value, ==, "4th.value"); |
| 480 |
g_value_unset (&val); |
| 481 |
|
| 482 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 483 |
} |
| 484 |
|
| 485 |
/* find with constraints */ |
| 486 |
{ |
| 487 |
g_autoptr (WpIterator) iter = wp_metadata_new_iterator (metadata, 0); |
| 488 |
g_auto (GValue) val = G_VALUE_INIT; |
| 489 |
guint subject = -1; |
| 490 |
const gchar *key = NULL, *type = NULL, *value = NULL; |
| 491 |
WpMetadataItem *mi; |
| 492 |
|
| 493 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 494 |
mi = g_value_get_boxed (&val); |
| 495 |
subject = wp_metadata_item_get_subject (mi); |
| 496 |
g_assert_cmpint (subject, ==, 0); |
| 497 |
key = wp_metadata_item_get_key (mi); |
| 498 |
g_assert_cmpstr (key, ==, "test-key"); |
| 499 |
type = wp_metadata_item_get_value_type (mi); |
| 500 |
g_assert_cmpstr (type, ==, "string"); |
| 501 |
value = wp_metadata_item_get_value (mi); |
| 502 |
g_assert_cmpstr (value, ==, "new.value"); |
| 503 |
g_value_unset (&val); |
| 504 |
|
| 505 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 506 |
mi = g_value_get_boxed (&val); |
| 507 |
subject = wp_metadata_item_get_subject (mi); |
| 508 |
g_assert_cmpint (subject, ==, 0); |
| 509 |
key = wp_metadata_item_get_key (mi); |
| 510 |
g_assert_cmpstr (key, ==, "3rd.key"); |
| 511 |
type = wp_metadata_item_get_value_type (mi); |
| 512 |
g_assert_cmpstr (type, ==, "string"); |
| 513 |
value = wp_metadata_item_get_value (mi); |
| 514 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 515 |
g_value_unset (&val); |
| 516 |
|
| 517 |
g_assert_true (wp_iterator_next (iter, &val)); |
| 518 |
mi = g_value_get_boxed (&val); |
| 519 |
subject = wp_metadata_item_get_subject (mi); |
| 520 |
g_assert_cmpint (subject, ==, 0); |
| 521 |
key = wp_metadata_item_get_key (mi); |
| 522 |
g_assert_cmpstr (key, ==, "4th.key"); |
| 523 |
type = wp_metadata_item_get_value_type (mi); |
| 524 |
g_assert_cmpstr (type, ==, "string"); |
| 525 |
value = wp_metadata_item_get_value (mi); |
| 526 |
g_assert_cmpstr (value, ==, "4th.value"); |
| 527 |
g_value_unset (&val); |
| 528 |
|
| 529 |
g_assert_false (wp_iterator_next (iter, &val)); |
| 530 |
} |
| 531 |
{ |
| 532 |
const gchar *value = NULL, *type = NULL; |
| 533 |
value = wp_metadata_find (metadata, 0, "3rd.key", &type); |
| 534 |
g_assert_cmpstr (type, ==, "string"); |
| 535 |
g_assert_cmpstr (value, ==, "3rd.value"); |
| 536 |
} |
| 537 |
|
| 538 |
/* destroy impl metadata */ |
| 539 |
fixture->n_events = 0; |
| 540 |
g_clear_object (&metadata); |
| 541 |
|
| 542 |
/* run until objects are destroyed */ |
| 543 |
g_main_loop_run (fixture->base.loop); |
| 544 |
g_assert_cmpint (fixture->n_events, ==, 2); |
| 545 |
g_assert_null (fixture->impl_metadata); |
| 546 |
g_assert_null (fixture->proxy_metadata); |
| 547 |
} |
| 548 |
|
| 549 |
gint |
| 550 |
main (gint argc, gchar *argv[]) |
| 551 |
{ |
| 552 |
g_test_init (&argc, &argv, NULL); |
| 553 |
wp_init (WP_INIT_ALL); |
| 554 |
|
| 555 |
g_test_add ("/wp/metadata/basic", TestFixture, NULL, |
| 556 |
test_metadata_setup, test_metadata_basic, test_metadata_teardown); |
| 557 |
|
| 558 |
return g_test_run (); |
| 559 |
} |