@@ -31,6 +31,7 @@ std::string home_dir(){
31
31
32
32
TEST (CTest, link_read_write){
33
33
fdp_set_log_level (FDP_LOG_DEBUG);
34
+ char buf[512 ];
34
35
35
36
// Initialise
36
37
FdpDataPipeline* pipeline;
@@ -48,7 +49,6 @@ TEST(CTest, link_read_write){
48
49
),
49
50
FDP_ERR_NONE
50
51
);
51
- char buf[512 ];
52
52
53
53
// Test link write
54
54
buf[0 ] = ' \0 ' ; // Ensure strlen of output buffer is 0
@@ -82,6 +82,79 @@ TEST(CTest, link_read_write){
82
82
EXPECT_EQ (fdp_finalise (&pipeline), FDP_ERR_NONE);
83
83
}
84
84
85
+ TEST (CTest, cpp_to_c){
86
+ fdp_set_log_level (FDP_LOG_DEBUG);
87
+ char buf[512 ];
88
+
89
+ // Initialise using C++
90
+ fs::path config = fs::path (TESTDIR) / " data" / " write_csv.yaml" ;
91
+ fs::path script = fs::path (TESTDIR) / " test_script.sh" ;
92
+ std::string token = fdp::read_token (
93
+ fs::path (home_dir ()) / " .fair" / " registry" / " token"
94
+ );
95
+ auto cpp_pipeline = fdp::DataPipeline::construct (
96
+ config.string (), script.string (), token
97
+ );
98
+
99
+ // Switch to C API, use temporary FdpDataPipeline
100
+ FdpDataPipeline *c_pipeline = fdp::to_c_struct (cpp_pipeline);
101
+
102
+ // Test link write
103
+ buf[0 ] = ' \0 ' ; // Ensure strlen of output buffer is 0
104
+ EXPECT_EQ (fdp_link_write (c_pipeline, " test/csv" , buf), FDP_ERR_NONE);
105
+ EXPECT_GT (strlen (buf), 1 );
106
+
107
+ // Write to new path
108
+ std::ofstream fstream (buf);
109
+ fstream << " Test" ;
110
+ fstream.close ();
111
+
112
+ // Finish working in C, delete FdpDataPipeline
113
+ fdp::delete_c_struct (c_pipeline);
114
+
115
+ // Finalise in C++
116
+ cpp_pipeline->finalise ();
117
+ }
118
+
119
+ TEST (CTest, c_to_cpp){
120
+ fdp_set_log_level (FDP_LOG_DEBUG);
121
+
122
+ // Initialise using C
123
+ FdpDataPipeline* c_pipeline;
124
+ fs::path config = fs::path (TESTDIR) / " data" / " write_csv.yaml" ;
125
+ fs::path script = fs::path (TESTDIR) / " test_script.sh" ;
126
+ std::string token = fdp::read_token (
127
+ fs::path (home_dir ()) / " .fair" / " registry" / " token"
128
+ );
129
+ ASSERT_EQ (
130
+ fdp_init (
131
+ &c_pipeline,
132
+ config.string ().c_str (),
133
+ script.string ().c_str (),
134
+ token.c_str ()
135
+ ),
136
+ FDP_ERR_NONE
137
+ );
138
+
139
+ // Switch to C++ API
140
+ auto cpp_pipeline = fdp::from_c_struct (c_pipeline);
141
+
142
+ // Test link write
143
+ std::string data_product = " test/csv" ;
144
+ fs::path currentLink = fs::path (cpp_pipeline->link_write (data_product));
145
+ EXPECT_GT (currentLink.string ().size (), 1 );
146
+
147
+ // Write to new path
148
+ std::ofstream fstream (currentLink);
149
+ fstream << " Test" ;
150
+ fstream.close ();
151
+
152
+ // Finish working in C++
153
+ cpp_pipeline = nullptr ;
154
+
155
+ // Finalise in C
156
+ EXPECT_EQ (fdp_finalise (&c_pipeline), FDP_ERR_NONE);
157
+ }
85
158
86
159
TEST (CTest, log_levels){
87
160
fdp_set_log_level (FDP_LOG_INFO);
0 commit comments