Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Send impl for Module #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 106 additions & 113 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,64 @@ use std::str;
/// A struct containing the OpenMPT version number, in big-endian.
///
/// `CoreVersion(majormajor, major, minor, minorminor)`
pub struct CoreVersion (pub u8, pub u8, pub u8, pub u8);
pub struct CoreVersion(pub u8, pub u8, pub u8, pub u8);

#[derive(Debug)]
/// A struct containing the libopenmpt version number, in big-endian.
///
/// `LibraryVersion(major, minor, revision)`
pub struct LibraryVersion (pub u8, pub u8, pub u16);
pub struct LibraryVersion(pub u8, pub u8, pub u16);

#[derive(Debug)]
/// An enum containing all the potentially valid keys for `openmpt_get_string`
pub enum InfoField {
/// Verbose library version string
/// Verbose library version string
LibraryVersion,
/// Verbose library features string
/// Verbose library features string
LibraryFeatures,
/// Verbose OpenMPT core version string
CoreVersion,
/// Original source code URL
SourceURL,
/// Original source code date
SourceDate,
/// Information about the current build (e.g. the build date or compiler used)
Build,
/// Information about the compiler used to build libopenmpt
BuildCompiler,
/// All contributors
Credits,
/// Contact information about libopenmpt
Contact,
/// The libopenmpt license
License,
/// libopenmpt website URL
URL,
/// libopenmpt support and discussions forum URL
SupportForumUrl,
/// libopenmpt bug and issue tracker URL
BugtrackerURL,
/// Verbose OpenMPT core version string
CoreVersion,
/// Original source code URL
SourceURL,
/// Original source code date
SourceDate,
/// Information about the current build (e.g. the build date or compiler used)
Build,
/// Information about the compiler used to build libopenmpt
BuildCompiler,
/// All contributors
Credits,
/// Contact information about libopenmpt
Contact,
/// The libopenmpt license
License,
/// libopenmpt website URL
URL,
/// libopenmpt support and discussions forum URL
SupportForumUrl,
/// libopenmpt bug and issue tracker URL
BugtrackerURL,
}

impl InfoField {
fn to_str(&self) -> &str {
use self::InfoField::*;
match *self {

LibraryVersion => "library_version",
LibraryFeatures => "library_features",
CoreVersion => "core_version",
SourceURL => "source_url",
SourceDate => "source_date",
Build => "build",
BuildCompiler => "build_compiler",
Credits => "credits",
Contact => "contact",
License => "license",
URL => "url",
SupportForumUrl => "support_forum_url",
BugtrackerURL => "bugtracker_url",
}
}
fn to_str(&self) -> &str {
use self::InfoField::*;
match *self {
LibraryVersion => "library_version",
LibraryFeatures => "library_features",
CoreVersion => "core_version",
SourceURL => "source_url",
SourceDate => "source_date",
Build => "build",
BuildCompiler => "build_compiler",
Credits => "credits",
Contact => "contact",
License => "license",
URL => "url",
SupportForumUrl => "support_forum_url",
BugtrackerURL => "bugtracker_url",
}
}
}

/// Get a library-related metadata string.
Expand All @@ -76,11 +75,9 @@ impl InfoField {
/// ### Returns
/// A (possibly multi-line) string containing the queried information.
/// If no information is available, the string is empty.
pub fn get_string (field : &InfoField) -> Option<String> {
let field = field.to_str();
get_string_with_string!(field, {
openmpt_sys::openmpt_get_string(field)
})
pub fn get_string(field: &InfoField) -> Option<String> {
let field = field.to_str();
get_string_with_string!(field, { openmpt_sys::openmpt_get_string(field) })
}

/// Get a list of supported file extensions.
Expand All @@ -90,11 +87,11 @@ pub fn get_string (field : &InfoField) -> Option<String> {
/// the libopenmpt build. The extensions are returned lower-case
/// without a leading dot.
pub fn get_supported_extensions() -> String {
let opt_string = get_string!{
openmpt_sys::openmpt_get_supported_extensions()
};
let opt_string = get_string! {
openmpt_sys::openmpt_get_supported_extensions()
};

opt_string.expect("Got null pointer instead of string")
opt_string.expect("Got null pointer instead of string")
}

/// Query whether a file extension is supported.
Expand All @@ -104,13 +101,13 @@ pub fn get_supported_extensions() -> String {
///
/// ### Returns
/// Whether a module tracker format with that extension is supported or not.
pub fn is_extension_supported(extension : &str) -> bool {
let result = with_string!(extension, {
openmpt_sys::openmpt_is_extension_supported(extension)
});
pub fn is_extension_supported(extension: &str) -> bool {
let result = with_string!(extension, {
openmpt_sys::openmpt_is_extension_supported(extension)
});

// Returns : 1 if the extension is supported by libopenmpt, 0 otherwise.
if result == 1 { true } else { false }
// Returns : 1 if the extension is supported by libopenmpt, 0 otherwise.
result == 1
}

/// Get the OpenMPT core version number.
Expand All @@ -119,17 +116,15 @@ pub fn is_extension_supported(extension : &str) -> bool {
/// A struct containing the OpenMPT version number, in big-endian :
///
/// `CoreVersion(majormajor, major, minor, minorminor)`
pub fn get_core_version () -> CoreVersion {
let version_number = unsafe {
openmpt_sys::openmpt_get_core_version()
};

CoreVersion (
(version_number >> 24) as u8,
(version_number >> 16) as u8,
(version_number >> 8) as u8,
version_number as u8
)
pub fn get_core_version() -> CoreVersion {
let version_number = unsafe { openmpt_sys::openmpt_get_core_version() };

CoreVersion(
(version_number >> 24) as u8,
(version_number >> 16) as u8,
(version_number >> 8) as u8,
version_number as u8,
)
}

/// Get the libopenmpt version number.
Expand All @@ -138,49 +133,47 @@ pub fn get_core_version () -> CoreVersion {
/// A struct containing the libopenmpt version number, in big-endian :
///
/// `LibraryVersion(major, minor, revision)`
pub fn get_library_version () -> LibraryVersion {
let version_number = unsafe {
openmpt_sys::openmpt_get_library_version()
};

LibraryVersion (
(version_number >> 24) as u8,
(version_number >> 16) as u8,
version_number as u16
)
pub fn get_library_version() -> LibraryVersion {
let version_number = unsafe { openmpt_sys::openmpt_get_library_version() };

LibraryVersion(
(version_number >> 24) as u8,
(version_number >> 16) as u8,
version_number as u16,
)
}

#[cfg(test)]
mod tests {
#[test]
fn try_lib_version_field() {
// Those should always return something
test_info_field(&super::InfoField::LibraryVersion);
test_info_field(&super::InfoField::LibraryFeatures);
test_info_field(&super::InfoField::CoreVersion);
}

fn test_info_field(field : &super::InfoField) {
let val = super::get_string(&field).unwrap();
println!("Field {:?} : \"{}\"", &field, &val);
}

#[test]
fn supported_extensions_include_xm() {
let support_list = super::get_supported_extensions();
assert!(support_list.contains("xm"));
}

#[test]
fn xm_is_supported() {
assert!(super::is_extension_supported("xm"));
}

#[test]
fn show_version_numbers() {
let x = super::get_core_version();
println!("Core Version : {:?}", &x);
let y = super::get_library_version();
println!("Lib Version : {:?}", &y);
}
}
#[test]
fn try_lib_version_field() {
// Those should always return something
test_info_field(&super::InfoField::LibraryVersion);
test_info_field(&super::InfoField::LibraryFeatures);
test_info_field(&super::InfoField::CoreVersion);
}

fn test_info_field(field: &super::InfoField) {
let val = super::get_string(&field).unwrap();
println!("Field {:?} : \"{}\"", &field, &val);
}

#[test]
fn supported_extensions_include_xm() {
let support_list = super::get_supported_extensions();
assert!(support_list.contains("xm"));
}

#[test]
fn xm_is_supported() {
assert!(super::is_extension_supported("xm"));
}

#[test]
fn show_version_numbers() {
let x = super::get_core_version();
println!("Core Version : {:?}", &x);
let y = super::get_library_version();
println!("Lib Version : {:?}", &y);
}
}
Loading