1
+ #include " gtest/gtest.h"
2
+ #include < thread>
3
+ #include < chrono>
4
+ // ここにはテスト対象のヘッダーファイルをインクルードします。
5
+ #include " hako_asset.h"
6
+ #include " hako_conductor.h"
7
+
8
+ // コールバック関数の実装
9
+ static int my_on_initialize (hako_asset_context_t * context)
10
+ {
11
+ std::cout << " INFO: my_on_initialize enter" << std::endl;
12
+ return 0 ;
13
+ }
14
+
15
+ static int my_on_reset (hako_asset_context_t * context)
16
+ {
17
+ std::cout << " INFO: my_on_reset enter" << std::endl;
18
+ return 0 ;
19
+ }
20
+
21
+ static int my_on_simulation_step (hako_asset_context_t * context)
22
+ {
23
+ std::cout << " INFO: on_simulation_step enter: " << hako_asset_simulation_time () << std::endl;
24
+ std::cout << " INFO: sleep 1sec" << std::endl;
25
+ usleep (1000 *1000 );
26
+ std::cout << " INFO: on_simulation_step exit" << std::endl;
27
+ return 0 ;
28
+ }
29
+
30
+ hako_asset_callbacks_t callbacks = {
31
+ .on_initialize = my_on_initialize,
32
+ .on_simulation_step = my_on_simulation_step,
33
+ .on_reset = my_on_reset
34
+ };
35
+
36
+ hako_time_t delta_time_usec = 1000 * 1000 * 100 ;
37
+
38
+ void run_hako_cmd_sequence () {
39
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
40
+ std::system (" /usr/local/bin/hakoniwa/hako-cmd start" );
41
+ std::this_thread::sleep_for (std::chrono::seconds (10 ));
42
+ std::system (" /usr/local/bin/hakoniwa/hako-cmd stop" );
43
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
44
+ std::system (" /usr/local/bin/hakoniwa/hako-cmd reset" );
45
+ }
46
+
47
+ TEST (HakoCApiTest, AssetRegist) {
48
+ hako_conductor_start (delta_time_usec, delta_time_usec);
49
+ int result = hako_asset_register (" AssetDumy" , " ../../config.json" , &callbacks, 1000 , HAKO_ASSET_MODEL_CONTROLLER);
50
+ ASSERT_EQ (result, 0 );
51
+ }
52
+
53
+ TEST (HakoCApiTest, AssetStart) {
54
+ // Execute the external command to launch the sandbox in a separate thread
55
+ std::thread t (run_hako_cmd_sequence);
56
+ t.detach ();
57
+
58
+ int result = hako_asset_start ();
59
+ ASSERT_EQ (result, EINTR); // Resetで終了するのでEINTRが返る
60
+ }
61
+
62
+ TEST (HakoCApiTest, ConductorStop) {
63
+ hako_conductor_stop ();
64
+ // ASSERT_EQ(result, 0);
65
+ }
66
+
67
+
68
+
69
+ int main (int argc, char **argv) {
70
+ ::testing::InitGoogleTest (&argc, argv);
71
+ return RUN_ALL_TESTS ();
72
+ }
0 commit comments