rerun buil.rs when windows icon changes; added tests about IpVersion and Protocol

This commit is contained in:
Giuliano Bellini s294739
2024-02-10 15:07:03 +01:00
parent d26707d028
commit d5b8e4c36c
3 changed files with 49 additions and 1 deletions

View File

@@ -12,9 +12,11 @@
include!("./src/networking/types/service_query.rs");
include!("./src/networking/types/protocol.rs");
const WINDOWS_ICON_PATH: &str = "./resources/packaging/windows/graphics/sniffnet.ico";
const SERVICES_LIST_PATH: &str = "./services.txt";
fn main() {
println!("cargo:rerun-if-changed={WINDOWS_ICON_PATH}");
println!("cargo:rerun-if-changed={SERVICES_LIST_PATH}");
set_icon();
@@ -25,7 +27,7 @@ fn set_icon() {
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("resources/packaging/windows/graphics/sniffnet.ico");
res.set_icon(WINDOWS_ICON_PATH);
res.compile().unwrap();
}
}

View File

@@ -18,3 +18,25 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl IpVersion {
pub(crate) const ALL: [IpVersion; 2] = [IpVersion::IPv4, IpVersion::IPv6];
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_ip_version_display() {
for version in IpVersion::ALL {
match version {
IpVersion::IPv4 => assert_eq!(version.to_string(), "IPv4"),
IpVersion::IPv6 => assert_eq!(version.to_string(), "IPv6"),
}
}
}
#[test]
fn test_all_ip_versions_collection() {
assert_eq!(IpVersion::ALL.len(), 2);
assert_eq!(IpVersion::ALL.get(0).unwrap(), &IpVersion::IPv4);
assert_eq!(IpVersion::ALL.get(1).unwrap(), &IpVersion::IPv6);
}
}

View File

@@ -21,3 +21,27 @@ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl Protocol {
pub const ALL: [Protocol; 3] = [Protocol::TCP, Protocol::UDP, Protocol::ICMP];
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_protocol_display() {
for protocol in Protocol::ALL {
match protocol {
Protocol::TCP => assert_eq!(protocol.to_string(), "TCP"),
Protocol::UDP => assert_eq!(protocol.to_string(), "UDP"),
Protocol::ICMP => assert_eq!(protocol.to_string(), "ICMP"),
}
}
}
#[test]
fn test_all_protocols_collection() {
assert_eq!(Protocol::ALL.len(), 3);
assert_eq!(Protocol::ALL.get(0).unwrap(), &Protocol::TCP);
assert_eq!(Protocol::ALL.get(1).unwrap(), &Protocol::UDP);
assert_eq!(Protocol::ALL.get(2).unwrap(), &Protocol::ICMP);
}
}