summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-04-07 20:50:55 +0200
committerHampusM <hampus@hampusmat.com>2023-04-07 20:50:55 +0200
commit067d5c321ca186382cedab2718cbe3ecd0651a33 (patch)
treeab50e744f6c651ccbd96f6f883165a6b4db65e88 /src/lib.rs
parent966ebb03abd8ae5ed4f47f4b53c00222269a56b4 (diff)
test: add command function unit tests
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 88eb0a3..fc0400e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,3 +18,47 @@ mod ffi
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
+
+#[cfg(test)]
+mod tests
+{
+ use std::mem::transmute;
+ use std::sync::atomic::{AtomicBool, Ordering};
+
+ use super::*;
+
+ #[test]
+ fn can_set_and_use_command_function()
+ {
+ static HAS_CALLED_FUNC: AtomicBool = AtomicBool::new(false);
+
+ extern "C" fn func(x: GLint, y: GLint, width: GLsizei, height: GLsizei)
+ {
+ assert_eq!(x, 123);
+ assert_eq!(y, 9);
+ assert_eq!(width, 1920);
+ assert_eq!(height, 1080);
+
+ HAS_CALLED_FUNC.store(true, Ordering::Relaxed);
+ }
+
+ unsafe {
+ functions::glViewport = transmute(func as *const ());
+ }
+
+ unsafe {
+ Viewport(123, 9, 1920, 1080);
+ }
+
+ assert!(HAS_CALLED_FUNC.load(Ordering::Relaxed));
+ }
+
+ #[test]
+ #[should_panic]
+ fn no_set_command_function_ptr_panics()
+ {
+ unsafe {
+ AttachShader(2, 30);
+ }
+ }
+}