| 1 |
// Take a look at the license at the top of the repository in the LICENSE file. |
| 2 |
|
| 3 |
use glib::ParamFlags; |
| 4 |
use glib::prelude::*; |
| 5 |
|
| 6 |
#[cfg(test)] |
| 7 |
mod base { |
| 8 |
use glib::prelude::*; |
| 9 |
use glib::subclass::prelude::*; |
| 10 |
use glib_macros::Properties; |
| 11 |
use std::marker::PhantomData; |
| 12 |
|
| 13 |
pub mod imp { |
| 14 |
use super::*; |
| 15 |
|
| 16 |
#[derive(Properties, Default)] |
| 17 |
#[properties(wrapper_type = super::Base, ext_trait)] |
| 18 |
pub struct Base { |
| 19 |
#[property(get = Self::not_overridden)] |
| 20 |
overridden: PhantomData<u32>, |
| 21 |
#[property(get = Self::not_overridden)] |
| 22 |
not_overridden: PhantomData<u32>, |
| 23 |
} |
| 24 |
|
| 25 |
#[glib::derived_properties] |
| 26 |
impl ObjectImpl for Base {} |
| 27 |
|
| 28 |
#[glib::object_subclass] |
| 29 |
impl ObjectSubclass for Base { |
| 30 |
const NAME: &'static str = "MyBase"; |
| 31 |
type Type = super::Base; |
| 32 |
} |
| 33 |
|
| 34 |
impl Base { |
| 35 |
fn not_overridden(&self) -> u32 { |
| 36 |
42 |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
glib::wrapper! { |
| 42 |
pub struct Base(ObjectSubclass<imp::Base>); |
| 43 |
} |
| 44 |
|
| 45 |
unsafe impl<T: ObjectImpl> IsSubclassable<T> for Base {} |
| 46 |
} |
| 47 |
|
| 48 |
#[cfg(test)] |
| 49 |
mod foo { |
| 50 |
use glib::prelude::*; |
| 51 |
use glib::subclass::prelude::*; |
| 52 |
use glib_macros::{Properties, ValueDelegate}; |
| 53 |
use std::cell::Cell; |
| 54 |
use std::cell::RefCell; |
| 55 |
use std::marker::PhantomData; |
| 56 |
use std::sync::Mutex; |
| 57 |
|
| 58 |
use super::base::Base; |
| 59 |
|
| 60 |
#[derive(ValueDelegate, Default, Debug, PartialEq)] |
| 61 |
pub struct MyPropertyValue(pub i32); |
| 62 |
|
| 63 |
#[derive(Clone, Default, Debug, PartialEq, Eq, glib::Boxed)] |
| 64 |
#[boxed_type(name = "SimpleBoxedString")] |
| 65 |
pub struct SimpleBoxedString(pub String); |
| 66 |
|
| 67 |
#[derive(Copy, Default, Clone, Debug, PartialEq, Eq, glib::Enum)] |
| 68 |
#[enum_type(name = "SimpleEnum")] |
| 69 |
pub enum SimpleEnum { |
| 70 |
#[default] |
| 71 |
One, |
| 72 |
Two, |
| 73 |
} |
| 74 |
|
| 75 |
#[derive(Default, Clone)] |
| 76 |
struct Author { |
| 77 |
name: String, |
| 78 |
nick: String, |
| 79 |
} |
| 80 |
|
| 81 |
pub mod imp { |
| 82 |
use std::{cell::OnceCell, rc::Rc}; |
| 83 |
|
| 84 |
use super::*; |
| 85 |
|
| 86 |
#[derive(Properties, Default)] |
| 87 |
#[properties(wrapper_type = super::Foo)] |
| 88 |
pub struct Foo { |
| 89 |
#[property(get, set)] |
| 90 |
bar: Mutex<String>, |
| 91 |
#[property(get, set)] |
| 92 |
double: RefCell<f64>, |
| 93 |
#[property(get, set)] |
| 94 |
string_vec: RefCell<Vec<String>>, |
| 95 |
#[property(get, set, builder(glib::VariantTy::DOUBLE))] |
| 96 |
variant: RefCell<Option<glib::Variant>>, |
| 97 |
#[property(get, set, builder(&<Option<i32>>::static_variant_type()))] |
| 98 |
variant2: RefCell<Option<glib::Variant>>, |
| 99 |
#[property(get = |_| 42.0, set)] |
| 100 |
infer_inline_type: RefCell<f64>, |
| 101 |
// The following property doesn't store any data. The value of the property is calculated |
| 102 |
// when the value is accessed. |
| 103 |
#[property(get = Self::hello_world)] |
| 104 |
_buzz: PhantomData<String>, |
| 105 |
#[property(get, set)] |
| 106 |
my_property_value: RefCell<MyPropertyValue>, |
| 107 |
#[property(get, set = Self::set_fizz, name = "fizz", nick = "fizz-nick", |
| 108 |
blurb = "short description stored in the GLib type system" |
| 109 |
)] |
| 110 |
fizz: RefCell<String>, |
| 111 |
#[property(name = "author-name", get, set, type = String, member = name)] |
| 112 |
#[property(name = "author-nick", get, set, type = String, member = nick)] |
| 113 |
author: RefCell<Author>, |
| 114 |
#[property( |
| 115 |
type = String, |
| 116 |
get = |t: &Self| t.author.borrow().name.to_owned(), |
| 117 |
set = Self::set_author_name)] |
| 118 |
fake_field: PhantomData<String>, |
| 119 |
#[property(get)] |
| 120 |
read_only_text: String, |
| 121 |
#[property(get, set, explicit_notify, lax_validation)] |
| 122 |
custom_flags: RefCell<String>, |
| 123 |
#[property(get, set, default = "hello")] |
| 124 |
with_default: RefCell<String>, |
| 125 |
#[property(get, set, builder())] |
| 126 |
simple_builder: RefCell<u32>, |
| 127 |
#[property(get, set, builder().minimum(0).maximum(5))] |
| 128 |
numeric_builder: RefCell<u32>, |
| 129 |
#[property(get, set, minimum = 0, maximum = 5)] |
| 130 |
builder_fields_without_builder: RefCell<u32>, |
| 131 |
#[property(get, set, builder('c'))] |
| 132 |
builder_with_required_param: RefCell<char>, |
| 133 |
#[property(get, set, default)] |
| 134 |
char_default: RefCell<char>, |
| 135 |
#[property(get, set)] |
| 136 |
boxed: RefCell<SimpleBoxedString>, |
| 137 |
#[property(get, set, builder(SimpleEnum::Two))] |
| 138 |
fenum: RefCell<SimpleEnum>, |
| 139 |
#[property(get, set, default)] |
| 140 |
fenum_default: RefCell<SimpleEnum>, |
| 141 |
#[property(get, set, nullable)] |
| 142 |
object: RefCell<Option<glib::Object>>, |
| 143 |
#[property(get, set, nullable)] |
| 144 |
optional: RefCell<Option<String>>, |
| 145 |
#[property(get, set)] |
| 146 |
smart_pointer: Rc<RefCell<String>>, |
| 147 |
#[property(get, set)] |
| 148 |
once_cell: OnceCell<u8>, |
| 149 |
#[property(get, set)] |
| 150 |
cell: Cell<u8>, |
| 151 |
#[property(get = Self::overridden, override_class = Base)] |
| 152 |
overridden: PhantomData<u32>, |
| 153 |
#[property(get, set)] |
| 154 |
weak_ref_prop: glib::WeakRef<glib::Object>, |
| 155 |
#[property(get, set)] |
| 156 |
send_weak_ref_prop: glib::SendWeakRef<glib::Object>, |
| 157 |
#[property(get, default_value = 0, construct_only)] |
| 158 |
construct_only_cell: OnceCell<u32>, |
| 159 |
#[property(get, set = Self::set_construct_only_custom, construct_only)] |
| 160 |
construct_only_custom_setter: OnceCell<Option<String>>, |
| 161 |
} |
| 162 |
|
| 163 |
#[glib::object_subclass] |
| 164 |
impl ObjectSubclass for Foo { |
| 165 |
const NAME: &'static str = "MyFoo"; |
| 166 |
type Type = super::Foo; |
| 167 |
type ParentType = Base; |
| 168 |
} |
| 169 |
|
| 170 |
#[glib::derived_properties] |
| 171 |
impl ObjectImpl for Foo {} |
| 172 |
|
| 173 |
impl Foo { |
| 174 |
fn set_author_name(&self, value: String) { |
| 175 |
self.author.borrow_mut().name = value; |
| 176 |
} |
| 177 |
fn hello_world(&self) -> String { |
| 178 |
String::from("Hello world!") |
| 179 |
} |
| 180 |
fn set_fizz(&self, value: String) { |
| 181 |
*self.fizz.borrow_mut() = format!("custom set: {value}"); |
| 182 |
} |
| 183 |
fn overridden(&self) -> u32 { |
| 184 |
43 |
| 185 |
} |
| 186 |
fn set_construct_only_custom(&self, value: Option<String>) { |
| 187 |
self.construct_only_custom_setter |
| 188 |
.set(value.map(|v| format!("custom set: {v}"))) |
| 189 |
.expect("Setter to be only called once"); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/// Checks that `Properties` does not pollute the scope with |
| 194 |
/// trait imports, as it did in older versions. |
| 195 |
#[test] |
| 196 |
fn no_import_leaks() { |
| 197 |
// `vec.get` can match these methods (in order of precedence): |
| 198 |
// (1) `<Vec<String> as PropertyGet>::get` |
| 199 |
// (2) `<[String]>::get` through deref of `Vec<String>` |
| 200 |
// Had the macro introduced `PropertyGet` into the scope, it would |
| 201 |
// resolve to (1), which we do not want. |
| 202 |
let vec: Vec<String> = vec![String::new(); 2]; |
| 203 |
assert_eq!(vec.get(1), Some(&String::new())); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
glib::wrapper! { |
| 208 |
pub struct Foo(ObjectSubclass<imp::Foo>) @extends Base; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
#[test] |
| 213 |
fn props() { |
| 214 |
use crate::foo::SimpleEnum; |
| 215 |
|
| 216 |
let myfoo: foo::Foo = glib::object::Object::new(); |
| 217 |
|
| 218 |
// Read values |
| 219 |
let bar: String = myfoo.property("bar"); |
| 220 |
assert_eq!(bar, "".to_string()); |
| 221 |
let string_vec: Vec<String> = myfoo.property("string-vec"); |
| 222 |
assert!(string_vec.is_empty()); |
| 223 |
let my_property_value: foo::MyPropertyValue = myfoo.property("my-property-value"); |
| 224 |
assert_eq!(my_property_value, foo::MyPropertyValue(0)); |
| 225 |
let var: Option<glib::Variant> = myfoo.property("variant"); |
| 226 |
assert!(var.is_none()); |
| 227 |
|
| 228 |
// Set values |
| 229 |
myfoo.set_property("bar", "epic".to_value()); |
| 230 |
let bar: String = myfoo.property("bar"); |
| 231 |
assert_eq!(bar, "epic".to_string()); |
| 232 |
myfoo.set_property("string-vec", ["epic", "more epic"].to_value()); |
| 233 |
let string_vec: Vec<String> = myfoo.property("string-vec"); |
| 234 |
assert_eq!( |
| 235 |
string_vec, |
| 236 |
vec!["epic".to_string(), "more epic".to_string()] |
| 237 |
); |
| 238 |
let myv = Some(2.0f64.to_variant()); |
| 239 |
myfoo.set_property("variant", &myv); |
| 240 |
let var: Option<glib::Variant> = myfoo.property("variant"); |
| 241 |
assert_eq!(var, myv); |
| 242 |
|
| 243 |
// Custom getter |
| 244 |
let buzz: String = myfoo.property("buzz"); |
| 245 |
assert_eq!(buzz, "Hello world!".to_string()); |
| 246 |
|
| 247 |
// Custom setter |
| 248 |
myfoo.set_property("fizz", "test"); |
| 249 |
let fizz: String = myfoo.property("fizz"); |
| 250 |
assert_eq!(fizz, "custom set: test".to_string()); |
| 251 |
|
| 252 |
// Multiple props on the same field |
| 253 |
myfoo.set_property("author-name", "freddy".to_value()); |
| 254 |
let author_name: String = myfoo.property("author-name"); |
| 255 |
assert_eq!(author_name, "freddy".to_string()); |
| 256 |
|
| 257 |
myfoo.set_property("author-nick", "freddy-nick".to_value()); |
| 258 |
let author_name: String = myfoo.property("author-nick"); |
| 259 |
assert_eq!(author_name, "freddy-nick".to_string()); |
| 260 |
|
| 261 |
// read_only |
| 262 |
assert_eq!( |
| 263 |
myfoo.find_property("read_only_text").unwrap().flags(), |
| 264 |
ParamFlags::READABLE |
| 265 |
); |
| 266 |
|
| 267 |
// custom flags |
| 268 |
assert_eq!( |
| 269 |
myfoo.find_property("custom_flags").unwrap().flags(), |
| 270 |
ParamFlags::EXPLICIT_NOTIFY | ParamFlags::READWRITE | ParamFlags::LAX_VALIDATION |
| 271 |
); |
| 272 |
|
| 273 |
// default value |
| 274 |
assert_eq!( |
| 275 |
myfoo |
| 276 |
.find_property("with_default") |
| 277 |
.unwrap() |
| 278 |
.default_value() |
| 279 |
.get::<String>() |
| 280 |
.unwrap(), |
| 281 |
"hello".to_string() |
| 282 |
); |
| 283 |
|
| 284 |
assert_eq!( |
| 285 |
myfoo |
| 286 |
.find_property("fenum") |
| 287 |
.unwrap() |
| 288 |
.default_value() |
| 289 |
.get::<SimpleEnum>() |
| 290 |
.unwrap(), |
| 291 |
SimpleEnum::Two |
| 292 |
); |
| 293 |
assert_eq!( |
| 294 |
myfoo |
| 295 |
.find_property("fenum_default") |
| 296 |
.unwrap() |
| 297 |
.default_value() |
| 298 |
.get::<SimpleEnum>() |
| 299 |
.unwrap(), |
| 300 |
SimpleEnum::One |
| 301 |
); |
| 302 |
|
| 303 |
// numeric builder |
| 304 |
assert_eq!( |
| 305 |
myfoo |
| 306 |
.find_property("numeric_builder") |
| 307 |
.unwrap() |
| 308 |
.downcast::<glib::ParamSpecUInt>() |
| 309 |
.unwrap() |
| 310 |
.maximum(), |
| 311 |
5 |
| 312 |
); |
| 313 |
|
| 314 |
assert_eq!( |
| 315 |
{ |
| 316 |
let spec = myfoo |
| 317 |
.find_property("builder_fields_without_builder") |
| 318 |
.unwrap() |
| 319 |
.downcast::<glib::ParamSpecUInt>() |
| 320 |
.unwrap(); |
| 321 |
(spec.minimum(), spec.maximum()) |
| 322 |
}, |
| 323 |
(0, 5) |
| 324 |
); |
| 325 |
|
| 326 |
// builder with required param |
| 327 |
assert_eq!( |
| 328 |
myfoo |
| 329 |
.find_property("builder_with_required_param") |
| 330 |
.unwrap() |
| 331 |
.default_value() |
| 332 |
.get::<char>() |
| 333 |
.unwrap(), |
| 334 |
'c' |
| 335 |
); |
| 336 |
|
| 337 |
// boxed type |
| 338 |
assert_eq!( |
| 339 |
myfoo.property::<foo::SimpleBoxedString>("boxed"), |
| 340 |
foo::SimpleBoxedString("".into()) |
| 341 |
); |
| 342 |
|
| 343 |
// Test `FooPropertiesExt` |
| 344 |
// getters |
| 345 |
{ |
| 346 |
// simple |
| 347 |
let bar = myfoo.bar(); |
| 348 |
assert_eq!(bar, myfoo.property::<String>("bar")); |
| 349 |
|
| 350 |
// custom |
| 351 |
let buzz = myfoo.buzz(); |
| 352 |
assert_eq!(buzz, myfoo.property::<String>("buzz")); |
| 353 |
|
| 354 |
// member of struct field |
| 355 |
let author_nick = myfoo.author_nick(); |
| 356 |
assert_eq!(author_nick, myfoo.property::<String>("author-nick")); |
| 357 |
} |
| 358 |
|
| 359 |
// setters |
| 360 |
{ |
| 361 |
// simple |
| 362 |
myfoo.set_bar("setter working"); |
| 363 |
assert_eq!( |
| 364 |
myfoo.property::<String>("bar"), |
| 365 |
"setter working".to_string() |
| 366 |
); |
| 367 |
|
| 368 |
myfoo.set_double(0.1); |
| 369 |
assert_eq!(myfoo.property::<f64>("double"), 0.1); |
| 370 |
|
| 371 |
myfoo.set_infer_inline_type(42.0); |
| 372 |
assert_eq!(myfoo.property::<f64>("infer-inline-type"), 42.0); |
| 373 |
|
| 374 |
// simple with various String types |
| 375 |
myfoo.set_bar(String::from("setter working")); |
| 376 |
myfoo.set_bar(glib::GString::from("setter working")); |
| 377 |
assert_eq!( |
| 378 |
myfoo.property::<String>("bar"), |
| 379 |
"setter working".to_string() |
| 380 |
); |
| 381 |
|
| 382 |
// custom |
| 383 |
myfoo.set_fake_field("fake setter"); |
| 384 |
assert_eq!( |
| 385 |
myfoo.property::<String>("author-name"), |
| 386 |
"fake setter".to_string() |
| 387 |
); |
| 388 |
|
| 389 |
// member of struct field |
| 390 |
myfoo.set_author_nick("setter nick"); |
| 391 |
assert_eq!( |
| 392 |
myfoo.property::<String>("author-nick"), |
| 393 |
"setter nick".to_string() |
| 394 |
); |
| 395 |
} |
| 396 |
|
| 397 |
// overrides |
| 398 |
{ |
| 399 |
let overridden: u32 = myfoo.property("overridden"); |
| 400 |
assert_eq!(overridden, 43); |
| 401 |
let not_overridden: u32 = myfoo.property("not-overridden"); |
| 402 |
assert_eq!(not_overridden, 42); |
| 403 |
} |
| 404 |
|
| 405 |
// optional |
| 406 |
myfoo.set_optional(Some("Hello world")); |
| 407 |
assert_eq!(myfoo.optional(), Some("Hello world".to_string())); |
| 408 |
myfoo.connect_optional_notify(|_| println!("notified")); |
| 409 |
|
| 410 |
// object subclass |
| 411 |
let myobj = glib::BoxedAnyObject::new(""); |
| 412 |
myfoo.set_object(Some(myobj.upcast_ref())); |
| 413 |
assert_eq!(myfoo.object(), Some(myobj.upcast())); |
| 414 |
|
| 415 |
// construct_only |
| 416 |
let myfoo: foo::Foo = glib::object::Object::builder() |
| 417 |
.property("construct-only-cell", 1u32) |
| 418 |
.build(); |
| 419 |
assert_eq!(myfoo.construct_only_cell(), 1u32); |
| 420 |
|
| 421 |
// construct_only with custom setter |
| 422 |
let myfoo: foo::Foo = glib::object::Object::builder() |
| 423 |
.property("construct-only-custom-setter", "foo") |
| 424 |
.build(); |
| 425 |
assert_eq!( |
| 426 |
myfoo.construct_only_custom_setter(), |
| 427 |
Some("custom set: foo".to_owned()) |
| 428 |
); |
| 429 |
} |
| 430 |
|
| 431 |
#[test] |
| 432 |
fn ext_trait() { |
| 433 |
use base::imp::BasePropertiesExt; |
| 434 |
let base: base::Base = glib::object::Object::builder().build(); |
| 435 |
assert_eq!(BasePropertiesExt::overridden(&base), 42); |
| 436 |
|
| 437 |
let foo_obj: foo::Foo = glib::object::Object::builder().build(); |
| 438 |
assert_eq!(BasePropertiesExt::overridden(&foo_obj), 43); |
| 439 |
assert_eq!(foo_obj.overridden(), 43); |
| 440 |
} |
| 441 |
|
| 442 |
#[test] |
| 443 |
fn keyword_propnames() { |
| 444 |
mod kw_names { |
| 445 |
mod imp { |
| 446 |
|
| 447 |
use std::cell::Cell; |
| 448 |
|
| 449 |
use glib::{prelude::*, subclass::prelude::*}; |
| 450 |
use glib_macros::Properties; |
| 451 |
|
| 452 |
#[derive(Properties, Default)] |
| 453 |
#[properties(wrapper_type = super::KwNames)] |
| 454 |
pub struct KwNames { |
| 455 |
// Some of the strict keywords |
| 456 |
#[property(get, set)] |
| 457 |
r#loop: Cell<u8>, |
| 458 |
#[property(get, set)] |
| 459 |
r#move: Cell<u8>, |
| 460 |
#[property(get, set)] |
| 461 |
r#type: Cell<u8>, |
| 462 |
|
| 463 |
// Lexer 2018+ strict keywords |
| 464 |
#[property(get, set)] |
| 465 |
r#async: Cell<u8>, |
| 466 |
#[property(get, set)] |
| 467 |
r#await: Cell<u8>, |
| 468 |
#[property(get, set)] |
| 469 |
r#dyn: Cell<u8>, |
| 470 |
|
| 471 |
// Some of the reserved keywords |
| 472 |
#[property(get, set)] |
| 473 |
r#become: Cell<u8>, |
| 474 |
#[property(get, set)] |
| 475 |
r#macro: Cell<u8>, |
| 476 |
#[property(get, set)] |
| 477 |
r#unsized: Cell<u8>, |
| 478 |
|
| 479 |
// Lexer 2018+ reserved keywords |
| 480 |
#[property(get, set)] |
| 481 |
r#try: Cell<u8>, |
| 482 |
} |
| 483 |
|
| 484 |
#[glib::object_subclass] |
| 485 |
impl ObjectSubclass for KwNames { |
| 486 |
const NAME: &'static str = "MyKwNames"; |
| 487 |
type Type = super::KwNames; |
| 488 |
} |
| 489 |
|
| 490 |
#[glib::derived_properties] |
| 491 |
impl ObjectImpl for KwNames {} |
| 492 |
} |
| 493 |
|
| 494 |
glib::wrapper! { |
| 495 |
pub struct KwNames(ObjectSubclass<imp::KwNames>); |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
let mykwnames: kw_names::KwNames = glib::Object::new(); |
| 500 |
|
| 501 |
// make sure all 10 properties are registered |
| 502 |
assert_eq!(mykwnames.list_properties().len(), 10); |
| 503 |
|
| 504 |
// getting property values |
| 505 |
assert_eq!(mykwnames.r#loop(), 0); |
| 506 |
assert_eq!(mykwnames.r#move(), 0); |
| 507 |
assert_eq!(mykwnames.r#type(), 0); |
| 508 |
assert_eq!(mykwnames.r#async(), 0); |
| 509 |
assert_eq!(mykwnames.r#await(), 0); |
| 510 |
assert_eq!(mykwnames.r#try(), 0); |
| 511 |
|
| 512 |
// getting property by name |
| 513 |
assert_eq!(mykwnames.property::<u8>("loop"), 0); |
| 514 |
assert_eq!(mykwnames.property::<u8>("move"), 0); |
| 515 |
assert_eq!(mykwnames.property::<u8>("type"), 0); |
| 516 |
assert_eq!(mykwnames.property::<u8>("async"), 0); |
| 517 |
assert_eq!(mykwnames.property::<u8>("await"), 0); |
| 518 |
assert_eq!(mykwnames.property::<u8>("try"), 0); |
| 519 |
|
| 520 |
// setting property values |
| 521 |
mykwnames.set_loop(128_u8); |
| 522 |
assert_eq!(mykwnames.r#loop(), 128_u8); |
| 523 |
mykwnames.set_move(128_u8); |
| 524 |
assert_eq!(mykwnames.r#move(), 128_u8); |
| 525 |
mykwnames.set_type(128_u8); |
| 526 |
assert_eq!(mykwnames.r#type(), 128_u8); |
| 527 |
mykwnames.set_async(128_u8); |
| 528 |
assert_eq!(mykwnames.r#async(), 128_u8); |
| 529 |
mykwnames.set_await(128_u8); |
| 530 |
assert_eq!(mykwnames.r#await(), 128_u8); |
| 531 |
mykwnames.set_try(128_u8); |
| 532 |
assert_eq!(mykwnames.r#try(), 128_u8); |
| 533 |
|
| 534 |
// setting property by name |
| 535 |
mykwnames.set_property("loop", 255_u8); |
| 536 |
assert_eq!(mykwnames.r#loop(), 255_u8); |
| 537 |
mykwnames.set_property("move", 255_u8); |
| 538 |
assert_eq!(mykwnames.r#loop(), 255_u8); |
| 539 |
mykwnames.set_property("type", 255_u8); |
| 540 |
assert_eq!(mykwnames.r#loop(), 255_u8); |
| 541 |
mykwnames.set_property("async", 255_u8); |
| 542 |
assert_eq!(mykwnames.r#async(), 255_u8); |
| 543 |
mykwnames.set_property("await", 255_u8); |
| 544 |
assert_eq!(mykwnames.r#await(), 255_u8); |
| 545 |
mykwnames.set_property("try", 255_u8); |
| 546 |
assert_eq!(mykwnames.r#try(), 255_u8); |
| 547 |
} |
| 548 |
|
| 549 |
/// This struct is intentionally left empty. |
| 550 |
/// |
| 551 |
/// Ensure the code compiles even when no properties are specified at all. |
| 552 |
/// This is useful for refactoring. |
| 553 |
#[test] |
| 554 |
#[allow(unreachable_code)] |
| 555 |
fn empty_struct() { |
| 556 |
mod empty { |
| 557 |
mod imp { |
| 558 |
use glib::subclass::prelude::*; |
| 559 |
use glib_macros::Properties; |
| 560 |
|
| 561 |
#[derive(Properties, Default)] |
| 562 |
#[properties(wrapper_type = super::Empty)] |
| 563 |
pub struct Empty {} |
| 564 |
|
| 565 |
#[glib::object_subclass] |
| 566 |
impl ObjectSubclass for Empty { |
| 567 |
const NAME: &'static str = "Empty"; |
| 568 |
type Type = super::Empty; |
| 569 |
} |
| 570 |
|
| 571 |
#[glib::derived_properties] |
| 572 |
impl ObjectImpl for Empty {} |
| 573 |
} |
| 574 |
|
| 575 |
glib::wrapper! { |
| 576 |
pub struct Empty(ObjectSubclass<imp::Empty>); |
| 577 |
} |
| 578 |
} |
| 579 |
} |