Add end-to-end tests for passing pointers to functions and returning them.
This functionality does already have a test in ast_visitor_test.cc, but it is
fundamental enough that it seems worth adding an end-to-end test as well.
Also, renamed hello_world to simple_functions to more accurately reflect what
the test does.
PiperOrigin-RevId: 413362293
diff --git a/rs_bindings_from_cc/test/function/simple/hello_world.cc b/rs_bindings_from_cc/test/function/simple/hello_world.cc
deleted file mode 100644
index 0d84a8a..0000000
--- a/rs_bindings_from_cc/test/function/simple/hello_world.cc
+++ /dev/null
@@ -1,7 +0,0 @@
-// Part of the Crubit project, under the Apache License v2.0 with LLVM
-// Exceptions. See /LICENSE for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "rs_bindings_from_cc/test/function/simple/hello_world.h"
-
-int hello_world() { return 42; }
diff --git a/rs_bindings_from_cc/test/function/simple/hello_world.h b/rs_bindings_from_cc/test/function/simple/hello_world.h
deleted file mode 100644
index a07ea69..0000000
--- a/rs_bindings_from_cc/test/function/simple/hello_world.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// Part of the Crubit project, under the Apache License v2.0 with LLVM
-// Exceptions. See /LICENSE for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_HELLO_WORLD_H_
-#define CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_HELLO_WORLD_H_
-
-int hello_world();
-
-#endif // CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_HELLO_WORLD_H_
diff --git a/rs_bindings_from_cc/test/function/simple/simple_functions.cc b/rs_bindings_from_cc/test/function/simple/simple_functions.cc
new file mode 100644
index 0000000..036bd7a
--- /dev/null
+++ b/rs_bindings_from_cc/test/function/simple/simple_functions.cc
@@ -0,0 +1,14 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#include "rs_bindings_from_cc/test/function/simple/simple_functions.h"
+
+int return_value() { return 42; }
+
+int* return_pointer() {
+ static int i = 42;
+ return &i;
+}
+
+void take_pointer(int* i) { *i = 42; }
diff --git a/rs_bindings_from_cc/test/function/simple/simple_functions.h b/rs_bindings_from_cc/test/function/simple/simple_functions.h
new file mode 100644
index 0000000..138f13d
--- /dev/null
+++ b/rs_bindings_from_cc/test/function/simple/simple_functions.h
@@ -0,0 +1,12 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#ifndef CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_SIMPLE_FUNCTIONS_H_
+#define CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_SIMPLE_FUNCTIONS_H_
+
+int return_value();
+int* return_pointer();
+void take_pointer(int* i);
+
+#endif // CRUBIT_RS_BINDINGS_FROM_CC_TEST_FUNCTION_SIMPLE_SIMPLE_FUNCTIONS_H_
diff --git a/rs_bindings_from_cc/test/function/simple/test.rs b/rs_bindings_from_cc/test/function/simple/test.rs
index cb497b9..d5ab5f2 100644
--- a/rs_bindings_from_cc/test/function/simple/test.rs
+++ b/rs_bindings_from_cc/test/function/simple/test.rs
@@ -4,10 +4,25 @@
#[cfg(test)]
mod tests {
- use hello_world::hello_world;
+ #[test]
+ fn test_return_value() {
+ use simple_functions::return_value;
+ assert_eq!(return_value(), 42);
+ }
#[test]
- fn test_hello_world() {
- assert_eq!(hello_world(), 42);
+ fn test_return_pointer() {
+ use simple_functions::return_pointer;
+ unsafe {
+ assert_eq!(*return_pointer(), 42);
+ }
+ }
+
+ #[test]
+ fn test_take_pointer() {
+ use simple_functions::take_pointer;
+ let mut i: i32 = 0;
+ take_pointer(&mut i);
+ assert_eq!(i, 42);
}
}