Skip to content

Commit fa7c2be

Browse files
committed
adj: removed test block
1 parent 14cf043 commit fa7c2be

9 files changed

Lines changed: 3 additions & 1273 deletions

File tree

‎okrmng/src/cli.rs‎

Lines changed: 0 additions & 495 deletions
Large diffs are not rendered by default.

‎okrmng/src/config.rs‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -102,43 +102,3 @@ fn sync_directory(path: &Path) -> Result<()> {
102102
fn sync_directory(_path: &Path) -> Result<()> {
103103
Ok(())
104104
}
105-
106-
#[cfg(test)]
107-
mod tests {
108-
use super::{App, Config};
109-
use std::collections::BTreeSet;
110-
111-
use tempfile::tempdir;
112-
113-
#[test]
114-
fn missing_config_loads_as_default() {
115-
let dir = tempdir().unwrap();
116-
let path = dir.path().join("config.toml");
117-
118-
let config = Config::load_from_path(&path).unwrap();
119-
120-
assert_eq!(config, Config::default());
121-
}
122-
123-
#[test]
124-
fn save_and_reload_round_trips_sorted_config() {
125-
let dir = tempdir().unwrap();
126-
let path = dir.path().join("config.toml");
127-
let config = Config {
128-
app: App {
129-
system_app: BTreeSet::from([
130-
"com.example.beta".to_string(),
131-
"com.example.alpha".to_string(),
132-
]),
133-
priv_app: BTreeSet::from(["com.example.gamma".to_string()]),
134-
},
135-
};
136-
137-
config.save_to_path(&path).unwrap();
138-
let reloaded = Config::load_from_path(&path).unwrap();
139-
let contents = std::fs::read_to_string(&path).unwrap();
140-
141-
assert_eq!(reloaded, config);
142-
assert!(contents.contains("system_app = [\"com.example.alpha\", \"com.example.beta\"]"));
143-
}
144-
}

‎oukaro/src/android_install_path.rs‎

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub fn has_known_user_app_prefix(path: &Path) -> bool {
88
|| is_adopted_storage_app_path(&normalized)
99
}
1010

11-
#[cfg_attr(test, allow(dead_code))]
11+
fn is_known_existing_user_app_path(path: &Path) -> bool {
12+
has_known_user_app_prefix(path) || { false }
13+
}
1214
pub fn normalize_user_app_code_path(path: &Path) -> Option<PathBuf> {
1315
if path.is_dir() && is_known_existing_user_app_path(path) {
1416
return Some(path.to_path_buf());
@@ -30,20 +32,6 @@ pub fn normalize_user_app_code_path(path: &Path) -> Option<PathBuf> {
3032

3133
None
3234
}
33-
34-
fn is_known_existing_user_app_path(path: &Path) -> bool {
35-
has_known_user_app_prefix(path) || {
36-
#[cfg(test)]
37-
{
38-
has_embedded_test_user_app_prefix(path)
39-
}
40-
#[cfg(not(test))]
41-
{
42-
false
43-
}
44-
}
45-
}
46-
4735
fn is_adopted_storage_app_path(normalized: &str) -> bool {
4836
let Some(rest) = normalized.strip_prefix("/mnt/expand/") else {
4937
return false;
@@ -55,42 +43,3 @@ fn is_adopted_storage_app_path(normalized: &str) -> bool {
5543
(Some(uuid), Some("app")) if !uuid.is_empty()
5644
)
5745
}
58-
59-
#[cfg(test)]
60-
fn has_embedded_test_user_app_prefix(path: &Path) -> bool {
61-
let normalized = path.to_string_lossy().replace('\\', "/");
62-
normalized.contains("/data/app/") || normalized.contains("/data/app-private/")
63-
}
64-
65-
#[cfg(test)]
66-
mod tests {
67-
use std::path::Path;
68-
69-
use super::has_known_user_app_prefix;
70-
71-
#[test]
72-
fn known_user_app_prefix_covers_android_install_locations() {
73-
assert!(has_known_user_app_prefix(Path::new(
74-
"/data/app/~~token/com.example/base.apk"
75-
)));
76-
assert!(has_known_user_app_prefix(Path::new(
77-
"/data/app-private/com.example.locked/base.apk"
78-
)));
79-
assert!(has_known_user_app_prefix(Path::new(
80-
"/mnt/expand/uuid/app/com.example/base.apk"
81-
)));
82-
}
83-
84-
#[test]
85-
fn known_user_app_prefix_rejects_non_app_roots() {
86-
assert!(!has_known_user_app_prefix(Path::new(
87-
"/system/app/Example/Example.apk"
88-
)));
89-
assert!(!has_known_user_app_prefix(Path::new(
90-
"/mnt/expand/uuid/media/com.example/base.apk"
91-
)));
92-
assert!(!has_known_user_app_prefix(Path::new(
93-
"/data/user/0/com.example/files"
94-
)));
95-
}
96-
}

‎oukaro/src/android_package.rs‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,3 @@ pub fn validate_package_name(package: &str) -> Result<()> {
3636

3737
Ok(())
3838
}
39-
40-
#[cfg(test)]
41-
mod tests {
42-
use super::{is_valid_package_name, validate_package_name};
43-
44-
#[test]
45-
fn android_package_rules_accept_standard_application_ids() {
46-
assert!(is_valid_package_name("com.example.app"));
47-
assert!(is_valid_package_name("com.Example_1.app_2"));
48-
}
49-
50-
#[test]
51-
fn android_package_rules_reject_invalid_names() {
52-
assert!(validate_package_name("").is_err());
53-
assert!(validate_package_name("single").is_err());
54-
assert!(validate_package_name("com..example").is_err());
55-
assert!(validate_package_name("1com.example").is_err());
56-
assert!(validate_package_name("com.example-app").is_err());
57-
assert!(validate_package_name("com.example/app").is_err());
58-
}
59-
}

‎oukaro/src/android_package_state.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,3 @@ impl SystemUserPackageState {
1818
self.installed && !self.hidden
1919
}
2020
}
21-
22-
#[cfg(test)]
23-
mod tests {
24-
use super::SystemUserPackageState;
25-
26-
#[test]
27-
fn package_state_matches_android_is_available_semantics() {
28-
assert!(SystemUserPackageState::default().is_available());
29-
assert!(
30-
!SystemUserPackageState {
31-
installed: false,
32-
hidden: false,
33-
}
34-
.is_available()
35-
);
36-
assert!(
37-
!SystemUserPackageState {
38-
installed: true,
39-
hidden: true,
40-
}
41-
.is_available()
42-
);
43-
}
44-
}

‎oukaro/src/android_xml.rs‎

Lines changed: 0 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -463,195 +463,3 @@ fn bytes_to_base64(bytes: &[u8]) -> String {
463463

464464
out
465465
}
466-
467-
#[cfg(test)]
468-
mod tests {
469-
use super::{decode_xmlish_bytes, parse_boolish, parse_i64ish};
470-
471-
fn push_utf(buf: &mut Vec<u8>, value: &str) {
472-
let len = u16::try_from(value.len()).unwrap();
473-
buf.extend_from_slice(&len.to_be_bytes());
474-
buf.extend_from_slice(value.as_bytes());
475-
}
476-
477-
fn push_utf_bytes(buf: &mut Vec<u8>, value: &[u8]) {
478-
let len = u16::try_from(value.len()).unwrap();
479-
buf.extend_from_slice(&len.to_be_bytes());
480-
buf.extend_from_slice(value);
481-
}
482-
483-
fn push_new_interned(buf: &mut Vec<u8>, value: &str) {
484-
buf.extend_from_slice(&0xFFFF_u16.to_be_bytes());
485-
push_utf(buf, value);
486-
}
487-
488-
fn push_interned_ref(buf: &mut Vec<u8>, index: u16) {
489-
buf.extend_from_slice(&index.to_be_bytes());
490-
}
491-
492-
#[test]
493-
fn parse_boolish_handles_common_android_representations() {
494-
assert_eq!(parse_boolish("true"), Some(true));
495-
assert_eq!(parse_boolish("False"), Some(false));
496-
assert_eq!(parse_boolish("1"), Some(true));
497-
assert_eq!(parse_boolish("0"), Some(false));
498-
assert_eq!(parse_boolish("maybe"), None);
499-
}
500-
501-
#[test]
502-
fn parse_i64ish_understands_decimal_and_hex() {
503-
assert_eq!(parse_i64ish("16"), Some(16));
504-
assert_eq!(parse_i64ish("0x10"), Some(16));
505-
assert_eq!(parse_i64ish("ff"), Some(255));
506-
assert_eq!(parse_i64ish("-0x10"), Some(-16));
507-
}
508-
509-
#[test]
510-
fn android_binary_xml_is_decoded_to_text_xml() {
511-
let mut abx = Vec::new();
512-
abx.extend_from_slice(b"ABX\0");
513-
abx.push(0x00);
514-
515-
abx.push(0x02);
516-
push_new_interned(&mut abx, "packages");
517-
518-
abx.push(0x02);
519-
push_new_interned(&mut abx, "package");
520-
521-
abx.push(0x2F);
522-
push_new_interned(&mut abx, "name");
523-
push_utf(&mut abx, "com.example.app");
524-
525-
abx.push(0x2F);
526-
push_new_interned(&mut abx, "codePath");
527-
push_utf(&mut abx, "/data/app/~~abc/com.example.app/base.apk");
528-
529-
abx.push(0x7F);
530-
push_new_interned(&mut abx, "publicFlags");
531-
abx.extend_from_slice(&(0x10_i32).to_be_bytes());
532-
533-
abx.push(0x03);
534-
push_interned_ref(&mut abx, 1);
535-
536-
abx.push(0x03);
537-
push_interned_ref(&mut abx, 0);
538-
539-
abx.push(0x01);
540-
541-
let decoded = decode_xmlish_bytes(&abx).unwrap();
542-
543-
assert!(decoded.contains("<package"));
544-
assert!(decoded.contains(r#"name="com.example.app""#));
545-
assert!(decoded.contains(r#"codePath="/data/app/~~abc/com.example.app/base.apk""#));
546-
assert!(decoded.contains(r#"publicFlags="0x10""#));
547-
}
548-
549-
#[test]
550-
fn android_binary_xml_decodes_boolean_attributes() {
551-
let mut abx = Vec::new();
552-
abx.extend_from_slice(b"ABX\0");
553-
abx.push(0x00);
554-
555-
abx.push(0x02);
556-
push_new_interned(&mut abx, "package-restrictions");
557-
558-
abx.push(0x02);
559-
push_new_interned(&mut abx, "pkg");
560-
561-
abx.push(0x2F);
562-
push_new_interned(&mut abx, "name");
563-
push_utf(&mut abx, "com.example.alpha");
564-
565-
abx.push(0xDF);
566-
push_new_interned(&mut abx, "inst");
567-
568-
abx.push(0x03);
569-
push_interned_ref(&mut abx, 1);
570-
571-
abx.push(0x03);
572-
push_interned_ref(&mut abx, 0);
573-
574-
abx.push(0x01);
575-
576-
let decoded = decode_xmlish_bytes(&abx).unwrap();
577-
578-
assert!(decoded.contains(r#"<pkg name="com.example.alpha" inst="false">"#));
579-
}
580-
581-
#[test]
582-
fn text_xml_utf16le_without_bom_is_detected() {
583-
let bytes = b"<root>ok</root>"
584-
.iter()
585-
.flat_map(|byte| [*byte, 0x00])
586-
.collect::<Vec<_>>();
587-
588-
let decoded = decode_xmlish_bytes(&bytes).unwrap();
589-
590-
assert_eq!(decoded, "<root>ok</root>");
591-
}
592-
593-
#[test]
594-
fn android_binary_xml_supports_art_modified_utf_with_four_byte_sequences() {
595-
let mut abx = Vec::new();
596-
abx.extend_from_slice(b"ABX\0");
597-
abx.push(0x00);
598-
599-
abx.push(0x02);
600-
push_new_interned(&mut abx, "emoji");
601-
602-
abx.push(0x24);
603-
push_utf_bytes(&mut abx, "😀".as_bytes());
604-
605-
abx.push(0x03);
606-
push_interned_ref(&mut abx, 0);
607-
abx.push(0x01);
608-
609-
let decoded = decode_xmlish_bytes(&abx).unwrap();
610-
611-
assert_eq!(decoded, "<emoji>😀</emoji>");
612-
}
613-
614-
#[test]
615-
fn android_binary_xml_resolves_entity_refs_like_android() {
616-
let mut abx = Vec::new();
617-
abx.extend_from_slice(b"ABX\0");
618-
abx.push(0x00);
619-
620-
abx.push(0x02);
621-
push_new_interned(&mut abx, "root");
622-
623-
abx.push(0x26);
624-
push_utf(&mut abx, "amp");
625-
626-
abx.push(0x03);
627-
push_interned_ref(&mut abx, 0);
628-
abx.push(0x01);
629-
630-
let decoded = decode_xmlish_bytes(&abx).unwrap();
631-
632-
assert_eq!(decoded, "<root>&amp;</root>");
633-
}
634-
635-
#[test]
636-
fn android_binary_xml_base64_attributes_are_rendered_as_base64_text() {
637-
let mut abx = Vec::new();
638-
abx.extend_from_slice(b"ABX\0");
639-
abx.push(0x00);
640-
641-
abx.push(0x02);
642-
push_new_interned(&mut abx, "root");
643-
644-
abx.push(0x5F);
645-
push_new_interned(&mut abx, "blob");
646-
abx.extend_from_slice(&(3_u16).to_be_bytes());
647-
abx.extend_from_slice(&[0x01, 0x02, 0x03]);
648-
649-
abx.push(0x03);
650-
push_interned_ref(&mut abx, 0);
651-
abx.push(0x01);
652-
653-
let decoded = decode_xmlish_bytes(&abx).unwrap();
654-
655-
assert_eq!(decoded, r#"<root blob="AQID"></root>"#);
656-
}
657-
}

‎oukaro/src/config.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,3 @@ fn sync_directory(path: &Path) -> Result<()> {
100100
fn sync_directory(_path: &Path) -> Result<()> {
101101
Ok(())
102102
}
103-
104-
#[cfg(test)]
105-
mod tests {
106-
use tempfile::tempdir;
107-
108-
use super::write_atomically;
109-
110-
#[test]
111-
fn atomic_writer_creates_complete_config_file() {
112-
let dir = tempdir().unwrap();
113-
let path = dir.path().join("config.toml");
114-
115-
write_atomically(&path, b"[app]\n").unwrap();
116-
117-
assert_eq!(std::fs::read_to_string(path).unwrap(), "[app]\n");
118-
}
119-
}

0 commit comments

Comments
 (0)