Skip to content

Commit bcff09a

Browse files
committed
C unit tests
1 parent 88dfd67 commit bcff09a

File tree

8 files changed

+95
-5
lines changed

8 files changed

+95
-5
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
[workspace]
2-
members = ["imageflow_helpers", "imageflow_types", "imageflow_riapi", "imageflow_core", "imageflow_abi", "imageflow_tool", "imageflow_server"]
2+
members = [
3+
"imageflow_helpers",
4+
"imageflow_types",
5+
"imageflow_riapi",
6+
"imageflow_core",
7+
"imageflow_abi",
8+
"imageflow_tool",
9+
"imageflow_server",
10+
"c_components",
11+
"c_components/tests",
12+
]
313

414
[dependencies.regex]
515
features=["pattern"]
@@ -9,4 +19,4 @@ debug = true
919

1020
# RIAPI Tests take 600ms each at 0, 200ms each at 1, 36ms each at 2, 26ms each at 3
1121
[profile.test]
12-
opt-level = 1
22+
opt-level = 1

c_components/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
authors = ["Nathanael Jones <[email protected]>", "Kornel Lesiński <[email protected]>"]
55
links = "imageflow_c"
66
workspace = "../"
7+
build = "build.rs"
78

89
[lib]
910
name = "imageflow_c_components"

c_components/tests/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "c_components_tests"
3+
version = "0.1.0"
4+
authors = ["Nathanael Jones <[email protected]>", "Kornel Lesiński <[email protected]>"]
5+
workspace = "../../"
6+
build = "src/build.rs"
7+
8+
[dependencies]
9+
imageflow_c_components = {path = ".."}
10+
lcms2-sys = "2.4.8"
11+
libpng-sys = "0.2.3"
12+
13+
[build-dependencies.cc]
14+
version = "1.0.3"
15+
features = ["parallel"]

c_components/tests/helpers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool create_path_from_relative(flow_c * c, const char * base_file, bool create_p
191191
return false;
192192
}
193193
const char * this_file = base_file;
194-
char * last_slash = strrchr(this_file, '/');
194+
const char * last_slash = strrchr(this_file, '/');
195195
if (last_slash == NULL) {
196196
last_slash = strrchr(this_file, '\\');
197197
}

c_components/tests/runner.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
#define CATCH_CONFIG_MAIN // tell catch to generate main
2-
#include "catch.hpp"
1+
#define CATCH_CONFIG_RUNNER
2+
#include "catch.hpp"
3+
4+
extern "C" int run_c_components_tests() {
5+
return Catch::Session().run( 0, NULL );
6+
}

c_components/tests/src/build.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extern crate cc;
2+
use std::env;
3+
use std::path::PathBuf;
4+
5+
fn main() {
6+
let mut cc = cc::Build::new();
7+
cc.warnings(false);
8+
9+
for path in env::split_paths(&env::var_os("DEP_PNG_INCLUDE").expect("include paths from libpng-sys")) {
10+
cc.include(path);
11+
}
12+
for path in env::split_paths(&env::var_os("DEP_LCMS2_INCLUDE").expect("include paths from lcms2-sys")) {
13+
cc.include(path);
14+
}
15+
16+
let test_root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
17+
let c_root = test_root.parent().unwrap();
18+
cc.include(c_root.join("lib"));
19+
cc.include(c_root);
20+
cc.include(&test_root);
21+
22+
cc.cpp(true);
23+
cc.flag("-std=c++11");
24+
25+
// the C code wants __FILE__ to contain slashes
26+
cc.file(test_root.join("runner.cpp"));
27+
cc.file(test_root.join("test.cpp"));
28+
cc.file(test_root.join("helpers.c"));
29+
cc.file(test_root.join("test_context.cpp"));
30+
cc.file(test_root.join("test_error_handling.cpp"));
31+
cc.file(test_root.join("test_integration.cpp"));
32+
cc.file(test_root.join("test_io.cpp"));
33+
cc.file(test_root.join("test_operations.cpp"));
34+
cc.file(test_root.join("test_variations.cpp"));
35+
cc.file(test_root.join("test_weighting.cpp"));
36+
cc.file(test_root.join("test_weighting_helpers.cpp"));
37+
cc.compile("imageflow_c_tests");
38+
}

c_components/tests/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extern crate imageflow_c_components;
2+
3+
extern "C" {
4+
pub fn run_c_components_tests() -> std::os::raw::c_int;
5+
}
6+
7+
#[test]
8+
fn c_catch() {
9+
unsafe {
10+
assert!(0 == run_c_components_tests());
11+
}
12+
}

0 commit comments

Comments
 (0)