@@ -149,3 +149,60 @@ void test_rtsk_individual_table_add_row_forced_error(const SEXP tc) {
149149 throw ;
150150 }
151151}
152+
153+ // TEST-ONLY
154+ // @title Force tskit-level error path in \code{rtsk_node_table_add_row}
155+ // @param tc an external pointer to table collection as a
156+ // \code{tsk_table_collection_t} object.
157+ // @return No return value; called for side effects - testing.
158+ // [[Rcpp::export]]
159+ void test_rtsk_node_table_add_row_forced_error (const SEXP tc) {
160+ rtsk_table_collection_t tc_xptr (tc);
161+ tsk_node_table_t &nodes = tc_xptr->nodes ;
162+ tsk_size_t saved_max_rows = nodes.max_rows ;
163+ tsk_size_t saved_max_rows_increment = nodes.max_rows_increment ;
164+ nodes.max_rows = 1 ;
165+ nodes.max_rows_increment = static_cast <tsk_size_t >(TSK_MAX_ID ) + 1 ;
166+ try {
167+ (void )rtsk_node_table_add_row (tc);
168+ // Lines below not hit by tests because rtsk_node_table_add_row()
169+ // throws error # nocov start
170+ nodes.max_rows = saved_max_rows;
171+ nodes.max_rows_increment = saved_max_rows_increment;
172+ return ;
173+ // # nocov end
174+ } catch (...) {
175+ nodes.max_rows = saved_max_rows;
176+ nodes.max_rows_increment = saved_max_rows_increment;
177+ throw ;
178+ }
179+ }
180+
181+ // TEST-ONLY
182+ // @title Force tskit-level error path in \code{rtsk_edge_table_add_row}
183+ // @param tc an external pointer to table collection as a
184+ // \code{tsk_table_collection_t} object.
185+ // @return No return value; called for side effects - testing.
186+ // [[Rcpp::export]]
187+ void test_rtsk_edge_table_add_row_forced_error (const SEXP tc) {
188+ rtsk_table_collection_t tc_xptr (tc);
189+ tsk_edge_table_t &edges = tc_xptr->edges ;
190+ tsk_size_t saved_max_rows = edges.max_rows ;
191+ tsk_size_t saved_max_rows_increment = edges.max_rows_increment ;
192+ edges.max_rows = 1 ;
193+ edges.max_rows_increment = static_cast <tsk_size_t >(TSK_MAX_ID ) + 1 ;
194+ try {
195+ (void )rtsk_edge_table_add_row (tc, 0 , 1 , static_cast <int >(edges.parent [0 ]),
196+ static_cast <int >(edges.child [0 ]), R_NilValue);
197+ // Lines below not hit by tests because rtsk_edge_table_add_row()
198+ // throws error # nocov start
199+ edges.max_rows = saved_max_rows;
200+ edges.max_rows_increment = saved_max_rows_increment;
201+ return ;
202+ // # nocov end
203+ } catch (...) {
204+ edges.max_rows = saved_max_rows;
205+ edges.max_rows_increment = saved_max_rows_increment;
206+ throw ;
207+ }
208+ }
0 commit comments