Skip to content

Commit

Permalink
feat: basic test file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
LeuisKen committed Jan 18, 2025
1 parent 1f348ac commit cb29c7b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
23 changes: 6 additions & 17 deletions integration_tests/rust_builder/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@ use std::ffi::c_void;
use webf_sys::executing_context::ExecutingContextRustMethods;
use webf_sys::{initialize_webf_api, ExecutingContext, RustValue};

fn test_user_agent(context: ExecutingContext) {
let navigator = context.navigator();
let exception_state = context.create_exception_state();
let ua_string = navigator.user_agent(&exception_state);

assert!(ua_string.contains("WebF"));
}

fn test_hardware_concurrency(context: ExecutingContext) {
let navigator = context.navigator();
let exception_state = context.create_exception_state();
let hardware_concurrency = navigator.hardware_concurrency(&exception_state);

assert!(hardware_concurrency > 0);
}
pub mod navigator;
pub mod storage;

fn webf_test_runner(tests: &[&dyn Fn(ExecutingContext)], context: ExecutingContext) {
println!("Running {} tests", tests.len());
Expand All @@ -31,8 +18,10 @@ pub extern "C" fn init_webf_test_app(handle: RustValue<ExecutingContextRustMetho
let context = initialize_webf_api(handle);

let tests: &[&dyn Fn(ExecutingContext)] = &[
&test_user_agent,
&test_hardware_concurrency,
&navigator::navigator::test_user_agent,
&navigator::navigator::test_hardware_concurrency,
&storage::set::test_local_storage_method_access,
&storage::set::test_session_storage_method_access,
];

webf_test_runner(tests, context);
Expand Down
1 change: 1 addition & 0 deletions integration_tests/rust_builder/rust/src/navigator/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod navigator;
17 changes: 17 additions & 0 deletions integration_tests/rust_builder/rust/src/navigator/navigator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use webf_sys::ExecutingContext;

pub fn test_hardware_concurrency(context: ExecutingContext) {
let navigator = context.navigator();
let exception_state = context.create_exception_state();
let hardware_concurrency = navigator.hardware_concurrency(&exception_state);

assert!(hardware_concurrency > 0);
}

pub fn test_user_agent(context: ExecutingContext) {
let navigator = context.navigator();
let exception_state = context.create_exception_state();
let ua_string = navigator.user_agent(&exception_state);

assert!(ua_string.contains("WebF"));
}
1 change: 1 addition & 0 deletions integration_tests/rust_builder/rust/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod set;
39 changes: 39 additions & 0 deletions integration_tests/rust_builder/rust/src/storage/set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use webf_sys::ExecutingContext;

pub fn test_local_storage_method_access(context: ExecutingContext) {
let storage = context.local_storage();
let exception_state = context.create_exception_state();
storage.clear(&exception_state);

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 0);

storage.set_item("name", "user1", &exception_state).unwrap();

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 1);

storage.remove_item("name", &exception_state).unwrap();

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 0);
}

pub fn test_session_storage_method_access(context: ExecutingContext) {
let storage = context.session_storage();
let exception_state = context.create_exception_state();
storage.clear(&exception_state);

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 0);

storage.set_item("name", "user1", &exception_state).unwrap();

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 1);

storage.remove_item("name", &exception_state).unwrap();

let keys = storage.get_all_keys(&exception_state);
assert_eq!(keys.len(), 0);
}

0 comments on commit cb29c7b

Please sign in to comment.