Debian Codegraph @

third_party/rust/embed-manifest/src/manifest/test.rs

raw
1 use super::{ExecutionLevel, SupportedOS};
2 use crate::{empty_manifest, new_manifest};
3
4 fn enc(s: &str) -> String {
5 let mut buf = String::with_capacity(1024);
6 buf.push('\u{feff}');
7 for l in s.lines() {
8 buf.push_str(l);
9 buf.push_str("\r\n");
10 }
11 buf.truncate(buf.len() - 2);
12 buf
13 }
14
15 fn encp(s: &str) -> String {
16 s.replace("\n", "\r\n")
17 }
18
19 #[test]
20 fn empty_manifest_canonical() {
21 let builder = empty_manifest();
22 assert_eq!(
23 format!("{}", builder),
24 enc(r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
25 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"></assembly>"#)
26 );
27 }
28
29 #[test]
30 fn empty_manifest_pretty() {
31 let builder = empty_manifest();
32 assert_eq!(
33 format!("{:#}", builder),
34 encp(
35 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
36 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"/>"#
37 )
38 );
39 }
40
41 #[test]
42 fn only_execution_level() {
43 let builder = empty_manifest().requested_execution_level(ExecutionLevel::AsInvoker);
44 assert_eq!(
45 format!("{:#}", builder),
46 encp(
47 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
48 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
49 <asmv3:trustInfo>
50 <asmv3:security>
51 <asmv3:requestedPrivileges>
52 <asmv3:requestedExecutionLevel level="asInvoker" uiAccess="false"/>
53 </asmv3:requestedPrivileges>
54 </asmv3:security>
55 </asmv3:trustInfo>
56 </assembly>"#
57 )
58 );
59 }
60
61 #[test]
62 fn only_windows10() {
63 let builder = empty_manifest().supported_os(SupportedOS::Windows10..);
64 assert_eq!(
65 format!("{:#}", builder),
66 encp(
67 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
68 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
69 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
70 <application>
71 <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
72 </application>
73 </compatibility>
74 </assembly>"#
75 )
76 );
77 }
78
79 #[test]
80 fn no_comctl32_6() {
81 let builder = new_manifest("Company.OrgUnit.Program")
82 .version(1, 0, 0, 2)
83 .remove_dependency("Microsoft.Windows.Common-Controls");
84 assert_eq!(
85 format!("{:#}", builder),
86 encp(
87 r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
88 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
89 <assemblyIdentity name="Company.OrgUnit.Program" type="win32" version="1.0.0.2"/>
90 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
91 <application>
92 <maxversiontested Id="10.0.18362.1"/>
93 <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
94 <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
95 <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
96 <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
97 </application>
98 </compatibility>
99 <asmv3:application>
100 <asmv3:windowsSettings>
101 <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
102 <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2</dpiAwareness>
103 <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
104 <printerDriverIsolation xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">true</printerDriverIsolation>
105 </asmv3:windowsSettings>
106 </asmv3:application>
107 <asmv3:trustInfo>
108 <asmv3:security>
109 <asmv3:requestedPrivileges>
110 <asmv3:requestedExecutionLevel level="asInvoker" uiAccess="false"/>
111 </asmv3:requestedPrivileges>
112 </asmv3:security>
113 </asmv3:trustInfo>
114 </assembly>"#
115 )
116 );
117 }