#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum PropValType {
Container = 0,
String = 1,
Boolean = 2,
Number = 3,
NamedType = 4,
Reference = 5,
Array = 6,
Enum = 7,
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct PropertyValueTypeFlags: i32 {
const NONE = 0;
const ANY = -1;
const BOOLEAN = 1;
const NUMBER = 2;
const STRING = 4;
const REFERENCE = 8;
const CONTAINER = 16;
const NAMED_TYPE = 32;
const BOOLEAN_ARRAY = 64;
const NUMBER_ARRAY = 128;
const STRING_ARRAY = 256;
const REFERENCE_ARRAY = 512;
const CONTAINER_ARRAY = 1024;
const ARRAY_OF_NAMED_TYPE = 2048;
const NOTHING = 4096;
const OBJECT = 16384;
const PLAIN_REFERENCE = 32768;
const PLAIN_CONTAINER = 65536;
const ENUM = 131_072;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum StepGroup {
Setup = 0,
Main = 1,
Cleanup = 2,
}
impl StepGroup {
pub const ALL: [Self; 3] = [Self::Setup, Self::Main, Self::Cleanup];
#[must_use]
pub const fn bits(self) -> i32 {
self as i32
}
pub const fn from_bits(raw: i32) -> Result<Self, i32> {
Ok(match raw {
0 => Self::Setup,
1 => Self::Main,
2 => Self::Cleanup,
other => return Err(other),
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum ExecRunState {
Running = 1,
Paused = 2,
Stopped = 3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum ExecTermState {
Normal = 1,
Terminating = 2,
TerminatingInteractive = 3,
Aborting = 4,
KillingThreads = 5,
}
#[allow(
clippy::enum_variant_names,
reason = "variant names mirror the type library"
)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum SearchDirectoryType {
TestStandDir = 1,
TestStandBinDir = 2,
AdapterSupportDir = 3,
ApplicationDir = 4,
InitialWorkingDir = 5,
WindowsSystemDir = 6,
WindowsDir = 7,
PathEnvironmentVarDir = 8,
CurrentSequenceFileDir = 9,
UserComponentsDir = 11,
NIComponentsDir = 12,
CurrentWorkspaceDir = 13,
ContainingProjectDir = 14,
ExplicitDir = 15,
TestStandPublicDir = 16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum OpenWorkspaceFileOptions {
NoOptions = 0,
IgnoreMissingFiles = 1,
SearchCurrentDirectory = 2,
UseSearchDirectories = 4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum SaveWorkspaceFileOptions {
NoOptions = 0,
PromptUser = 1,
SkipWorkspaceFile = 2,
SkipReadOnlyFiles = 4,
}
impl TryFrom<i32> for SearchDirectoryType {
type Error = i32;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
1 => Ok(Self::TestStandDir),
2 => Ok(Self::TestStandBinDir),
3 => Ok(Self::AdapterSupportDir),
4 => Ok(Self::ApplicationDir),
5 => Ok(Self::InitialWorkingDir),
6 => Ok(Self::WindowsSystemDir),
7 => Ok(Self::WindowsDir),
8 => Ok(Self::PathEnvironmentVarDir),
9 => Ok(Self::CurrentSequenceFileDir),
11 => Ok(Self::UserComponentsDir),
12 => Ok(Self::NIComponentsDir),
13 => Ok(Self::CurrentWorkspaceDir),
14 => Ok(Self::ContainingProjectDir),
15 => Ok(Self::ExplicitDir),
16 => Ok(Self::TestStandPublicDir),
other => Err(other),
}
}
}
impl std::fmt::Display for SearchDirectoryType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl std::fmt::Display for PropValType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn discriminants_match_tlb_ground_truth() {
assert_eq!(PropValType::Container as i32, 0);
assert_eq!(PropValType::String as i32, 1);
assert_eq!(PropValType::Boolean as i32, 2);
assert_eq!(PropValType::Number as i32, 3);
assert_eq!(PropValType::Enum as i32, 7);
assert_eq!(PropertyValueTypeFlags::ANY.bits(), -1);
assert_eq!(PropertyValueTypeFlags::CONTAINER.bits(), 16);
assert_eq!(PropertyValueTypeFlags::ENUM.bits(), 131_072);
}
#[test]
fn value_type_flags_combine_and_round_trip() {
let mask = PropertyValueTypeFlags::NUMBER | PropertyValueTypeFlags::STRING;
assert_eq!(mask.bits(), 6);
assert!(mask.contains(PropertyValueTypeFlags::NUMBER));
assert!(mask.contains(PropertyValueTypeFlags::STRING));
assert!(!mask.contains(PropertyValueTypeFlags::CONTAINER));
assert_eq!(PropertyValueTypeFlags::from_bits_retain(mask.bits()), mask);
let mut acc = PropertyValueTypeFlags::NONE;
assert!(acc.is_empty());
acc |= PropertyValueTypeFlags::CONTAINER;
assert_eq!(acc, PropertyValueTypeFlags::CONTAINER);
assert_eq!(
acc & PropertyValueTypeFlags::CONTAINER,
PropertyValueTypeFlags::CONTAINER
);
}
#[test]
fn remaining_discriminants_match_tlb_ground_truth() {
assert_eq!(StepGroup::Setup as i32, 0);
assert_eq!(StepGroup::Main as i32, 1);
assert_eq!(StepGroup::Cleanup as i32, 2);
assert_eq!(ExecRunState::Running as i32, 1);
assert_eq!(ExecTermState::Normal as i32, 1);
assert_eq!(SearchDirectoryType::ExplicitDir as i32, 15);
assert_eq!(
SearchDirectoryType::try_from(15),
Ok(SearchDirectoryType::ExplicitDir)
);
assert_eq!(OpenWorkspaceFileOptions::NoOptions as i32, 0);
assert_eq!(OpenWorkspaceFileOptions::UseSearchDirectories as i32, 4);
assert_eq!(SaveWorkspaceFileOptions::NoOptions as i32, 0);
assert_eq!(SaveWorkspaceFileOptions::SkipReadOnlyFiles as i32, 4);
}
}