Skip to content

Commit

Permalink
Add unit test for non-empty function GUID
Browse files Browse the repository at this point in the history
  • Loading branch information
emesare committed Oct 31, 2024
1 parent 2178a87 commit 61e88ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions rust/signature/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ impl FromStr for FunctionGUID {
}
}

impl TryFrom<&str> for FunctionGUID {
type Error = uuid::Error;

fn try_from(value: &str) -> Result<Self, Self::Error> {
Self::from_str(value)
}
}

impl From<&[u8]> for FunctionGUID {
fn from(value: &[u8]) -> Self {
Self {
Expand Down Expand Up @@ -127,6 +135,7 @@ impl From<fb::Function<'_>> for Function {
mod tests {
use crate::r#type::class::TypeClass;
use crate::r#type::Type;
use crate::signature::basic_block::BasicBlockGUID;
use crate::signature::function::constraints::FunctionConstraints;
use crate::signature::function::{Function, FunctionGUID};
use crate::signature::Data;
Expand All @@ -135,16 +144,34 @@ mod tests {
use uuid::{uuid, Uuid};

const EMPTY_FN_UUID: Uuid = uuid!("db867a3e-416a-5d7f-aa6d-b8ae6be36da2");
const NONEMPTY_FN_UUID: Uuid = uuid!("7a55be03-76b7-5cb5-bae9-4edcf47795ac");

const FIRST_BB_UUID: Uuid = uuid!("036cccf0-8239-5b84-a811-60efc2d7eeb0");
const SECOND_BB_UUID: Uuid = uuid!("3ed5c023-658d-5511-9710-40814f31af50");
const THIRD_BB_UUID: Uuid = uuid!("8a076c92-0ba0-540d-b724-7fd5838da9df");

fn empty_fn_guid() -> FunctionGUID {
FunctionGUID::from_basic_blocks(&[])
}

fn nonempty_fn_guid() -> FunctionGUID {
FunctionGUID::from_basic_blocks(&[
BasicBlockGUID::from(FIRST_BB_UUID),
BasicBlockGUID::from(SECOND_BB_UUID),
BasicBlockGUID::from(THIRD_BB_UUID),
])
}

#[test]
fn empty_function_guid() {
assert_eq!(FunctionGUID::from(EMPTY_FN_UUID), empty_fn_guid());
}

#[test]
fn nonempty_function_guid() {
assert_eq!(FunctionGUID::from(NONEMPTY_FN_UUID), nonempty_fn_guid());
}

fn empty_function() -> Function {
Function {
guid: empty_fn_guid(),
Expand Down
2 changes: 1 addition & 1 deletion rust/symbol/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl DataSymbolClass {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum SymbolClass {
Function,
Data,
Expand Down

0 comments on commit 61e88ee

Please sign in to comment.