mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
Add a test for embedded conditionals
Also fix the initialization of properties in C++, make them zero-initialized like in rust
This commit is contained in:
parent
d7fe69ff74
commit
e8c825b434
3 changed files with 28 additions and 13 deletions
|
@ -43,6 +43,6 @@ struct Property
|
|||
|
||||
private:
|
||||
internal::PropertyHandleOpaque inner;
|
||||
mutable T value;
|
||||
mutable T value{};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
TestCase := Rectangle {
|
||||
property<bool> condition;
|
||||
property<int32> test_value: condition ? 1 : 2;
|
||||
property<bool> condition2;
|
||||
property<int32> test_value2: condition ? condition2 ? 1 : 2 : condition2 ? 3 : 4;
|
||||
|
||||
}
|
||||
/*
|
||||
```cpp
|
||||
TestCase instance;
|
||||
instance.set_condition(true);
|
||||
assert(instance.get_test_value() == 1);
|
||||
assert(instance.get_test_value2() == 2);
|
||||
instance.set_condition(false);
|
||||
assert(instance.get_test_value() == 2);
|
||||
assert(instance.get_test_value2() == 4);
|
||||
instance.set_condition2(true);
|
||||
assert(instance.get_test_value2() == 3);
|
||||
```
|
||||
|
||||
|
||||
|
@ -16,8 +23,12 @@ assert(instance.get_test_value() == 2);
|
|||
let instance = TestCase::default();
|
||||
instance.set_condition(true);
|
||||
assert_eq!(instance.get_test_value(), 1);
|
||||
assert_eq!(instance.get_test_value2(), 2);
|
||||
instance.set_condition(false);
|
||||
assert_eq!(instance.get_test_value(), 2);
|
||||
assert_eq!(instance.get_test_value2(), 4);
|
||||
instance.set_condition2(true);
|
||||
assert_eq!(instance.get_test_value2(), 3);
|
||||
```
|
||||
|
||||
```js
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use sixtyfps_compilerlib::*;
|
||||
use std::error::Error;
|
||||
use std::io::Write;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>> {
|
||||
let source = std::fs::read_to_string(&testcase.absolute_path)?;
|
||||
|
@ -82,20 +83,23 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
|
|||
return Err("C++ Compilation error (see stdout)".to_owned().into());
|
||||
}
|
||||
|
||||
std::process::Command::new(binary_path.clone())
|
||||
let output = std::process::Command::new(binary_path.deref())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.map_err(|err| format!("Error launching testcase binary: {}", err))?
|
||||
.wait()
|
||||
.map_err(|err| format!("Test case could not be run: {}", err))
|
||||
.and_then(|status| {
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else if let Some(exit_code) = status.code() {
|
||||
Err(format!("Test case exited with non-zero code: {}", exit_code))
|
||||
.wait_with_output()
|
||||
.map_err(|err| format!("Test case could not be run: {}", err))?;
|
||||
|
||||
if !output.status.success() {
|
||||
print!("{}", String::from_utf8_lossy(output.stdout.as_ref()));
|
||||
print!("{}", String::from_utf8_lossy(output.stderr.as_ref()));
|
||||
if let Some(exit_code) = output.status.code() {
|
||||
return Err(format!("Test case exited with non-zero code: {}", exit_code).into());
|
||||
} else {
|
||||
Err("Test case exited by signal".into())
|
||||
return Err("Test case exited by signal".into());
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
if keep_temp_files {
|
||||
println!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue