use cfg_if::cfg_if;
use openssl_macros::corresponds;
use std::ffi::CStr;
cfg_if! {
    if #[cfg(any(ossl110, libressl271))] {
        use ffi::{
            OPENSSL_VERSION, OPENSSL_CFLAGS, OPENSSL_BUILT_ON, OPENSSL_PLATFORM, OPENSSL_DIR,
            OpenSSL_version_num, OpenSSL_version,
        };
    } else {
        use ffi::{
            SSLEAY_VERSION as OPENSSL_VERSION, SSLEAY_CFLAGS as OPENSSL_CFLAGS,
            SSLEAY_BUILT_ON as OPENSSL_BUILT_ON, SSLEAY_PLATFORM as OPENSSL_PLATFORM,
            SSLEAY_DIR as OPENSSL_DIR, SSLeay as OpenSSL_version_num,
            SSLeay_version as OpenSSL_version,
        };
    }
}
#[corresponds(OpenSSL_version_num)]
pub fn number() -> i64 {
    unsafe { OpenSSL_version_num() as i64 }
}
#[corresponds(OpenSSL_version)]
pub fn version() -> &'static str {
    unsafe {
        CStr::from_ptr(OpenSSL_version(OPENSSL_VERSION))
            .to_str()
            .unwrap()
    }
}
#[corresponds(OpenSSL_version)]
pub fn c_flags() -> &'static str {
    unsafe {
        CStr::from_ptr(OpenSSL_version(OPENSSL_CFLAGS))
            .to_str()
            .unwrap()
    }
}
#[corresponds(OpenSSL_version)]
pub fn built_on() -> &'static str {
    unsafe {
        CStr::from_ptr(OpenSSL_version(OPENSSL_BUILT_ON))
            .to_str()
            .unwrap()
    }
}
#[corresponds(OpenSSL_version)]
pub fn platform() -> &'static str {
    unsafe {
        CStr::from_ptr(OpenSSL_version(OPENSSL_PLATFORM))
            .to_str()
            .unwrap()
    }
}
#[corresponds(OpenSSL_version)]
pub fn dir() -> &'static str {
    unsafe {
        CStr::from_ptr(OpenSSL_version(OPENSSL_DIR))
            .to_str()
            .unwrap()
    }
}
#[test]
fn test_versions() {
    println!("Number: '{}'", number());
    println!("Version: '{}'", version());
    println!("C flags: '{}'", c_flags());
    println!("Built on: '{}'", built_on());
    println!("Platform: '{}'", platform());
    println!("Dir: '{}'", dir());
    #[cfg(not(any(libressl, boringssl)))]
    fn expected_name() -> &'static str {
        "OpenSSL"
    }
    #[cfg(libressl)]
    fn expected_name() -> &'static str {
        "LibreSSL"
    }
    #[cfg(boringssl)]
    fn expected_name() -> &'static str {
        "BoringSSL"
    }
    assert!(number() > 0);
    assert!(version().starts_with(expected_name()));
    assert!(c_flags().starts_with("compiler:"));
        if !built_on().is_empty() {
        assert!(built_on().starts_with("built on:"));
    }
    assert!(dir().starts_with("OPENSSLDIR:"));
}