// This file was generated by gir (https://github.com/gtk-rs/gir @ 0ab7700) // from gir-files (https://github.com/gtk-rs/gir-files @ ???) // DO NOT EDIT extern crate goa_sys; extern crate shell_words; extern crate tempdir; use std::env; use std::error::Error; use std::path::Path; use std::mem::{align_of, size_of}; use std::process::Command; use std::str; use goa_sys::*; static PACKAGES: &[&str] = &["goa-1.0"]; #[derive(Clone, Debug)] struct Compiler { pub args: Vec, } impl Compiler { pub fn new() -> Result> { let mut args = get_var("CC", "cc")?; args.push("-Wno-deprecated-declarations".to_owned()); // For %z support in printf when using MinGW. args.push("-D__USE_MINGW_ANSI_STDIO".to_owned()); args.extend(get_var("CFLAGS", "")?); args.extend(get_var("CPPFLAGS", "")?); args.extend(pkg_config_cflags(PACKAGES)?); Ok(Compiler { args }) } pub fn define<'a, V: Into>>(&mut self, var: &str, val: V) { let arg = match val.into() { None => format!("-D{}", var), Some(val) => format!("-D{}={}", var, val), }; self.args.push(arg); } pub fn compile(&self, src: &Path, out: &Path) -> Result<(), Box> { let mut cmd = self.to_command(); cmd.arg(src); cmd.arg("-o"); cmd.arg(out); let status = cmd.spawn()?.wait()?; if !status.success() { return Err(format!("compilation command {:?} failed, {}", &cmd, status).into()); } Ok(()) } fn to_command(&self) -> Command { let mut cmd = Command::new(&self.args[0]); cmd.args(&self.args[1..]); cmd } } fn get_var(name: &str, default: &str) -> Result, Box> { match env::var(name) { Ok(value) => Ok(shell_words::split(&value)?), Err(env::VarError::NotPresent) => Ok(shell_words::split(default)?), Err(err) => Err(format!("{} {}", name, err).into()), } } fn pkg_config_cflags(packages: &[&str]) -> Result, Box> { if packages.is_empty() { return Ok(Vec::new()); } let mut cmd = Command::new("pkg-config"); cmd.arg("--cflags"); cmd.args(packages); let out = cmd.output()?; if !out.status.success() { return Err(format!("command {:?} returned {}", &cmd, out.status).into()); } let stdout = str::from_utf8(&out.stdout)?; Ok(shell_words::split(stdout.trim())?) } #[derive(Copy, Clone, Debug, Eq, PartialEq)] struct Layout { size: usize, alignment: usize, } #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] struct Results { /// Number of successfully completed tests. passed: usize, /// Total number of failed tests (including those that failed to compile). failed: usize, /// Number of tests that failed to compile. failed_to_compile: usize, } impl Results { fn record_passed(&mut self) { self.passed += 1; } fn record_failed(&mut self) { self.failed += 1; } fn record_failed_to_compile(&mut self) { self.failed += 1; self.failed_to_compile += 1; } fn summary(&self) -> String { format!( "{} passed; {} failed (compilation errors: {})", self.passed, self.failed, self.failed_to_compile) } fn expect_total_success(&self) { if self.failed == 0 { println!("OK: {}", self.summary()); } else { panic!("FAILED: {}", self.summary()); }; } } #[test] fn cross_validate_constants_with_c() { let tmpdir = tempdir::TempDir::new("abi").expect("temporary directory"); let cc = Compiler::new().expect("configured compiler"); assert_eq!("1", get_c_value(tmpdir.path(), &cc, "1").expect("C constant"), "failed to obtain correct constant value for 1"); let mut results : Results = Default::default(); for (i, &(name, rust_value)) in RUST_CONSTANTS.iter().enumerate() { match get_c_value(tmpdir.path(), &cc, name) { Err(e) => { results.record_failed_to_compile(); eprintln!("{}", e); }, Ok(ref c_value) => { if rust_value == c_value { results.record_passed(); } else { results.record_failed(); eprintln!("Constant value mismatch for {}\nRust: {:?}\nC: {:?}", name, rust_value, c_value); } } }; if (i + 1) % 25 == 0 { println!("constants ... {}", results.summary()); } } results.expect_total_success(); } #[test] fn cross_validate_layout_with_c() { let tmpdir = tempdir::TempDir::new("abi").expect("temporary directory"); let cc = Compiler::new().expect("configured compiler"); assert_eq!(Layout {size: 1, alignment: 1}, get_c_layout(tmpdir.path(), &cc, "char").expect("C layout"), "failed to obtain correct layout for char type"); let mut results : Results = Default::default(); for (i, &(name, rust_layout)) in RUST_LAYOUTS.iter().enumerate() { match get_c_layout(tmpdir.path(), &cc, name) { Err(e) => { results.record_failed_to_compile(); eprintln!("{}", e); }, Ok(c_layout) => { if rust_layout == c_layout { results.record_passed(); } else { results.record_failed(); eprintln!("Layout mismatch for {}\nRust: {:?}\nC: {:?}", name, rust_layout, &c_layout); } } }; if (i + 1) % 25 == 0 { println!("layout ... {}", results.summary()); } } results.expect_total_success(); } fn get_c_layout(dir: &Path, cc: &Compiler, name: &str) -> Result> { let exe = dir.join("layout"); let mut cc = cc.clone(); cc.define("ABI_TYPE_NAME", name); cc.compile(Path::new("tests/layout.c"), &exe)?; let mut abi_cmd = Command::new(exe); let output = abi_cmd.output()?; if !output.status.success() { return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into()); } let stdout = str::from_utf8(&output.stdout)?; let mut words = stdout.trim().split_whitespace(); let size = words.next().unwrap().parse().unwrap(); let alignment = words.next().unwrap().parse().unwrap(); Ok(Layout {size, alignment}) } fn get_c_value(dir: &Path, cc: &Compiler, name: &str) -> Result> { let exe = dir.join("constant"); let mut cc = cc.clone(); cc.define("ABI_CONSTANT_NAME", name); cc.compile(Path::new("tests/constant.c"), &exe)?; let mut abi_cmd = Command::new(exe); let output = abi_cmd.output()?; if !output.status.success() { return Err(format!("command {:?} failed, {:?}", &abi_cmd, &output).into()); } let output = str::from_utf8(&output.stdout)?.trim(); if !output.starts_with("###gir test###") || !output.ends_with("###gir test###") { return Err(format!("command {:?} return invalid output, {:?}", &abi_cmd, &output).into()); } Ok(String::from(&output[14..(output.len() - 14)])) } const RUST_LAYOUTS: &[(&str, Layout)] = &[ ("GoaAccountIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaAccountProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaAccountProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaAccountSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaAccountSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaCalendarIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaCalendarProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaCalendarProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaCalendarSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaCalendarSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaChatIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaChatProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaChatProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaChatSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaChatSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaClientClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaContactsIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaContactsProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaContactsProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaContactsSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaContactsSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaDocumentsIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaDocumentsProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaDocumentsProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaDocumentsSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaDocumentsSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaError", Layout {size: size_of::(), alignment: align_of::()}), ("GoaExchangeIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaExchangeProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaExchangeProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaExchangeSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaExchangeSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaFilesIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaFilesProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaFilesProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaFilesSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaFilesSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMailIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMailProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMailProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMailSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMailSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaManagerIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaManagerProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaManagerProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaManagerSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaManagerSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMapsIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMapsProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMapsProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMapsSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMapsSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMediaServerIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMediaServerProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMediaServerProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMediaServerSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMediaServerSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMusicIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMusicProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMusicProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMusicSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaMusicSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuth2BasedIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuth2BasedProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuth2BasedProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuth2BasedSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuth2BasedSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuthBasedIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuthBasedProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuthBasedProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuthBasedSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaOAuthBasedSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectManagerClient", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectManagerClientClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaObjectSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPasswordBasedIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPasswordBasedProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPasswordBasedProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPasswordBasedSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPasswordBasedSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPhotosIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPhotosProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPhotosProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPhotosSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPhotosSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPrintersIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPrintersProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPrintersProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPrintersSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaPrintersSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaReadLaterIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaReadLaterProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaReadLaterProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaReadLaterSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaReadLaterSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTicketingIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTicketingProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTicketingProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTicketingSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTicketingSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTodoIface", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTodoProxy", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTodoProxyClass", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTodoSkeleton", Layout {size: size_of::(), alignment: align_of::()}), ("GoaTodoSkeletonClass", Layout {size: size_of::(), alignment: align_of::()}), ]; const RUST_CONSTANTS: &[(&str, &str)] = &[ ("(gint) GOA_ERROR_ACCOUNT_EXISTS", "3"), ("(gint) GOA_ERROR_DIALOG_DISMISSED", "2"), ("(gint) GOA_ERROR_FAILED", "0"), ("(gint) GOA_ERROR_NOT_AUTHORIZED", "4"), ("(gint) GOA_ERROR_NOT_SUPPORTED", "1"), ("GOA_ERROR_NUM_ENTRIES", "6"), ("(gint) GOA_ERROR_SSL", "5"), ];