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

Generate message types #14

Merged
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
2 changes: 1 addition & 1 deletion fitparser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io;
use std::{error, fmt};

/// The result of a deserialization operation.
pub type Result<T> = ::std::result::Result<T, Error>;
pub type Result<T, E = Error> = ::std::result::Result<T, E>;
stadelmanma marked this conversation as resolved.
Show resolved Hide resolved

/// An error that can be produced during deserializing.
pub type Error = Box<ErrorKind>;
Expand Down
45 changes: 45 additions & 0 deletions fitparser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ impl fmt::Display for ValueWithUnits {

#[cfg(test)]
mod tests {
use super::profile::{MesgNum, Message, MessageParseOptions};
use super::*;
use std::collections::HashSet;

Expand All @@ -365,69 +366,99 @@ mod tests {
let data = include_bytes!("../tests/fixtures/Activity.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 22);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_developer_data() {
let data = include_bytes!("../tests/fixtures/DeveloperData.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 6);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_monitoring_file() {
let data = include_bytes!("../tests/fixtures/MonitoringFile.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 355);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_settings() {
let data = include_bytes!("../tests/fixtures/Settings.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 3);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_weight_scale_multi_user() {
let data = include_bytes!("../tests/fixtures/WeightScaleMultiUser.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 7);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_weight_scale_single_user() {
let data = include_bytes!("../tests/fixtures/WeightScaleSingleUser.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 6);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_workout_custom_target_values() {
let data = include_bytes!("../tests/fixtures/WorkoutCustomTargetValues.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 6);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_workout_individual_steps() {
let data = include_bytes!("../tests/fixtures/WorkoutIndividualSteps.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 6);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_workout_repeat_greater_than_step() {
let data = include_bytes!("../tests/fixtures/WorkoutRepeatGreaterThanStep.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 7);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
fn parse_workout_repeat_steps() {
let data = include_bytes!("../tests/fixtures/WorkoutRepeatSteps.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 7);
for record in fit_data {
assert!(Message::parse(record).is_ok());
}
}

#[test]
Expand All @@ -437,6 +468,13 @@ mod tests {
let data = include_bytes!("../tests/fixtures/garmin-fenix-5-bike.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 143);
let mut options = MessageParseOptions::default();
options.ignore_unexpected_fields = true;
for record in fit_data {
if MesgNum::is_named_variant(record.kind().as_i64()) {
assert!(Message::parse_with_options(record, options).is_ok());
}
}
}

#[test]
Expand All @@ -445,6 +483,13 @@ mod tests {
let data = include_bytes!("../tests/fixtures/sample_mulitple_header.fit").to_vec();
let fit_data = from_bytes(&data).unwrap();
assert_eq!(fit_data.len(), 3023);
let mut options = MessageParseOptions::default();
options.ignore_unexpected_fields = true;
for record in fit_data {
if MesgNum::is_named_variant(record.kind().as_i64()) {
assert!(Message::parse_with_options(record, options).is_ok());
}
}
}

#[test]
Expand Down
Loading
Loading