rs_teststand/license/options.rs
1//! Options for acquiring a license.
2
3bitflags::bitflags! {
4 /// How to behave when a license cannot be acquired (`AcquireLicenseOptions`).
5 ///
6 /// The default is to ask a person. A host with nobody in front of it must
7 /// say otherwise, or it stops on a window it cannot answer.
8 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9 pub struct AcquireLicenseOptions: i32 {
10 /// Take the engine's default behavior, which raises a dialog offering
11 /// to evaluate, activate or buy when the license is not available.
12 const NONE = 0;
13 /// Never raise that dialog: fail the call instead.
14 ///
15 /// What a headless host wants. The failure becomes an [`Error`] a
16 /// caller can report, rather than a window nobody will close.
17 ///
18 /// [`Error`]: crate::Error
19 const SUPPRESS_STARTUP_DIALOG = 1;
20 /// Suppress the dialog only when another running process has already
21 /// shown it and a license was chosen there. If not, the dialog still
22 /// appears, so this is not a substitute for
23 /// [`SUPPRESS_STARTUP_DIALOG`](Self::SUPPRESS_STARTUP_DIALOG) on an
24 /// unattended station.
25 const SUPPRESS_STARTUP_DIALOG_IF_ALREADY_SHOWN = 2;
26 /// Give the dialog an Exit button rather than a Close button; the
27 /// application exits if acquisition fails. Only meaningful when the
28 /// dialog is allowed to appear at all.
29 const SHOW_EXIT_BUTTON = 4;
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::AcquireLicenseOptions;
36
37 #[test]
38 fn the_documented_bits_are_what_the_engine_expects() {
39 assert_eq!(AcquireLicenseOptions::NONE.bits(), 0);
40 assert_eq!(AcquireLicenseOptions::SUPPRESS_STARTUP_DIALOG.bits(), 1);
41 assert_eq!(
42 AcquireLicenseOptions::SUPPRESS_STARTUP_DIALOG_IF_ALREADY_SHOWN.bits(),
43 2
44 );
45 assert_eq!(AcquireLicenseOptions::SHOW_EXIT_BUTTON.bits(), 4);
46 }
47
48 #[test]
49 fn suppressing_and_exiting_are_independent() {
50 // Combining them is legal; the exit button only applies if a dialog is
51 // shown, so the pair is not a contradiction the type should prevent.
52 let both = AcquireLicenseOptions::SUPPRESS_STARTUP_DIALOG
53 | AcquireLicenseOptions::SHOW_EXIT_BUTTON;
54 assert_eq!(both.bits(), 5);
55 assert!(both.contains(AcquireLicenseOptions::SUPPRESS_STARTUP_DIALOG));
56 }
57}