Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock collection support for IIterable #2346

Merged
merged 9 commits into from
Feb 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more tests
kennykerr committed Feb 23, 2023
commit 922206649c3a447b8599994a9354f23d13ae240d
1 change: 1 addition & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ jobs:
cargo clippy -p test_bstr &&
cargo clippy -p test_calling_convention &&
cargo clippy -p test_cfg_generic &&
cargo clippy -p test_collections &&
cargo clippy -p test_component &&
cargo clippy -p test_component_client &&
cargo clippy -p test_const_fields &&
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -121,6 +121,7 @@ jobs:
cargo test --target ${{ matrix.target }} -p test_bstr &&
cargo test --target ${{ matrix.target }} -p test_calling_convention &&
cargo test --target ${{ matrix.target }} -p test_cfg_generic &&
cargo test --target ${{ matrix.target }} -p test_collections &&
cargo test --target ${{ matrix.target }} -p test_component &&
cargo test --target ${{ matrix.target }} -p test_component_client &&
cargo test --target ${{ matrix.target }} -p test_const_fields &&
@@ -133,8 +134,8 @@ jobs:
cargo test --target ${{ matrix.target }} -p test_enums &&
cargo test --target ${{ matrix.target }} -p test_error &&
cargo test --target ${{ matrix.target }} -p test_event &&
cargo test --target ${{ matrix.target }} -p test_extensions &&
cargo clean &&
cargo test --target ${{ matrix.target }} -p test_extensions &&
cargo test --target ${{ matrix.target }} -p test_handles &&
cargo test --target ${{ matrix.target }} -p test_helpers &&
cargo test --target ${{ matrix.target }} -p test_implement &&
13 changes: 13 additions & 0 deletions crates/tests/collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "test_collections"
version = "0.0.0"
authors = ["Microsoft"]
edition = "2018"

[dependencies.windows]
path = "../../libs/windows"
features = [
"implement",
"Foundation_Collections",
"Win32_Foundation",
]
1 change: 1 addition & 0 deletions crates/tests/collections/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

135 changes: 135 additions & 0 deletions crates/tests/collections/tests/stock_iterable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#![allow(non_snake_case)]

use std::convert::TryFrom;
use windows::core::{h, Result, HSTRING};
use windows::Foundation::Collections::IIterable;
use windows::Win32::Foundation::E_BOUNDS;

#[test]
fn primitive() -> Result<()> {
let able = IIterable::<i32>::try_from(vec![])?;
let iter = able.First()?;

assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);

assert!(!iter.HasCurrent()?);
assert!(!iter.HasCurrent()?);

assert!(!iter.MoveNext()?);
assert!(!iter.MoveNext()?);

assert_eq!(iter.GetMany(&mut [0; 5])?, 0);

let able = IIterable::<i32>::try_from(vec![1, 2, 3])?;
let iter = able.First()?;

assert_eq!(iter.Current()?, 1);
assert_eq!(iter.Current()?, 1);

assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(iter.MoveNext()?);
assert_eq!(iter.Current()?, 2);
assert_eq!(iter.Current()?, 2);
assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(iter.MoveNext()?);
assert_eq!(iter.Current()?, 3);
assert_eq!(iter.Current()?, 3);
assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(!iter.MoveNext()?);
assert!(!iter.MoveNext()?);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert!(!iter.HasCurrent()?);
assert!(!iter.HasCurrent()?);

let iter = able.First()?;
let mut values = [0; 5];
assert_eq!(iter.GetMany(&mut values)?, 3);
assert_eq!(values, [1, 2, 3, 0, 0]);
assert_eq!(iter.GetMany(&mut values)?, 0);

let iter = able.First()?;
let mut values = [0; 1];
assert_eq!(iter.GetMany(&mut values)?, 1);
assert_eq!(values, [1]);
let mut values = [0; 2];
assert_eq!(iter.GetMany(&mut values)?, 2);
assert_eq!(values, [2, 3]);
assert_eq!(iter.GetMany(&mut values)?, 0);

Ok(())
}

#[test]
fn hstring() -> Result<()> {
let able = IIterable::<HSTRING>::try_from(vec![])?;
let iter = able.First()?;

assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);

assert!(!iter.HasCurrent()?);
assert!(!iter.HasCurrent()?);

assert!(!iter.MoveNext()?);
assert!(!iter.MoveNext()?);

let mut values = vec![];
values.resize_with(5, Default::default);
assert_eq!(iter.GetMany(&mut values)?, 0);

let able = IIterable::<HSTRING>::try_from(vec![HSTRING::from("one"), HSTRING::from("two"), HSTRING::from("three")])?;
let iter = able.First()?;

assert_eq!(&iter.Current()?, h!("one"));
assert_eq!(&iter.Current()?, h!("one"));

assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(iter.MoveNext()?);
assert_eq!(&iter.Current()?, h!("two"));
assert_eq!(&iter.Current()?, h!("two"));
assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(iter.MoveNext()?);
assert_eq!(&iter.Current()?, h!("three"));
assert_eq!(&iter.Current()?, h!("three"));
assert!(iter.HasCurrent()?);
assert!(iter.HasCurrent()?);

assert!(!iter.MoveNext()?);
assert!(!iter.MoveNext()?);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert_eq!(iter.Current().unwrap_err().code(), E_BOUNDS);
assert!(!iter.HasCurrent()?);
assert!(!iter.HasCurrent()?);

let iter = able.First()?;
let mut values = vec![];
values.resize_with(5, Default::default);
assert_eq!(iter.GetMany(&mut values)?, 3);
assert_eq!(values, [HSTRING::from("one"), HSTRING::from("two"), HSTRING::from("three"), HSTRING::default(), HSTRING::default()]);
assert_eq!(iter.GetMany(&mut values)?, 0);

let iter = able.First()?;
let mut values = vec![];
values.resize_with(1, Default::default);
assert_eq!(iter.GetMany(&mut values)?, 1);
assert_eq!(values, [HSTRING::from("one")]);
let mut values = vec![];
values.resize_with(2, Default::default);
assert_eq!(iter.GetMany(&mut values)?, 2);
assert_eq!(values, [HSTRING::from("two"), HSTRING::from("three")]);
assert_eq!(iter.GetMany(&mut values)?, 0);

Ok(())
}
68 changes: 0 additions & 68 deletions crates/tests/implement/tests/stock_iterable.rs

This file was deleted.