@@ -288,20 +288,86 @@ TEST_F(CApiWhileLoopTest, NestedLoop) {
288288 ExpectOutputValue (1 , 3 );
289289}
290290
291- TEST_F (CApiWhileLoopTest, BadCondOutput ) {
291+ TEST_F (CApiWhileLoopTest, UnsetCondOutput ) {
292292 Init (1 );
293293 params_->body_outputs [0 ] = params_->body_inputs [0 ];
294294 ExpectError (TF_INVALID_ARGUMENT ,
295295 " TF_WhileParams `cond_output` field isn't set" );
296296}
297297
298- TEST_F (CApiWhileLoopTest, BadBodyOutput) {
298+ TEST_F (CApiWhileLoopTest, WrongCondOutputType) {
299+ Init (1 );
300+ params_->cond_output = params_->cond_inputs [0 ];
301+ params_->body_outputs [0 ] = params_->body_inputs [0 ];
302+ ExpectError (TF_INVALID_ARGUMENT ,
303+ " BuildWhileLoop: 'cond' argument must return a boolean output, "
304+ " got int32" );
305+ }
306+
307+ TEST_F (CApiWhileLoopTest, InvalidCondOutputNode) {
308+ Init (1 );
309+ // Try to reuse node from parent graph
310+ params_->cond_output = inputs_[0 ];
311+ params_->body_outputs [0 ] = params_->body_inputs [0 ];
312+ // TODO(skyewm): this error message could be more informative. Add explicit
313+ // checks for this case in the while loop implementation?
314+ ExpectError (TF_INVALID_ARGUMENT ,
315+ " Requested return node 'p0' not found in graph def" );
316+ }
317+
318+ TEST_F (CApiWhileLoopTest, InvalidCondOutputIndex) {
319+ Init (1 );
320+ CreateCondGraph ();
321+ params_->cond_output .index = 100 ;
322+ params_->body_outputs [0 ] = params_->body_inputs [0 ];
323+ ExpectError (TF_INVALID_ARGUMENT ,
324+ " Invalid return output 100 of node 'less_than', which has 1 "
325+ " output(s)" );
326+ }
327+
328+ // TODO(skyewm): test bad cond output shape
329+
330+ TEST_F (CApiWhileLoopTest, UnsetBodyOutput) {
299331 Init (1 );
300332 CreateCondGraph ();
301333 ExpectError (TF_INVALID_ARGUMENT ,
302334 " TF_WhileParams `body_outputs[0]` field isn't set" );
303335}
304336
337+ // TODO(skyewm): enable this when it works (currently doesn't error)
338+ // TEST_F(CApiWhileLoopTest, WrongBodyOutputType) {
339+ // Init(1);
340+ // CreateCondGraph();
341+ // TF_Operation* double_scalar =
342+ // ScalarConst(1.0, params_->body_graph, s_, "double_scalar");
343+ // params_->body_outputs[0] = {double_scalar, 0};
344+ // ExpectError(TF_INVALID_ARGUMENT, "bad body output type");
345+ // }
346+
347+ TEST_F (CApiWhileLoopTest, InvalidBodyOutputNode) {
348+ Init (1 );
349+ CreateCondGraph ();
350+ // Try to reuse node from parent graph
351+ params_->body_outputs [0 ] = inputs_[0 ];
352+ // TODO(skyewm): this error message could be more informative. Add explicit
353+ // checks for this case in the while loop implementation?
354+ ExpectError (TF_INVALID_ARGUMENT ,
355+ " Requested return node 'p0' not found in graph def" );
356+ }
357+
358+ // TODO(skyewm): enable this when it works (currently segfaults!)
359+ // TEST_F(CApiWhileLoopTest, InvalidBodyOutputIndex) {
360+ // Init(1);
361+ // CreateCondGraph();
362+ // params_->body_outputs[0] = params_->body_inputs[0];
363+ // params_->body_outputs[0].index = 100;
364+ // ExpectError(TF_INVALID_ARGUMENT,
365+ // "Invalid return output 100 of node 'less_than', which has 1 "
366+ // "output(s)");
367+ // }
368+
369+ // TODO(skyewm): test bad body output shape
370+
305371TEST_F (CApiWhileLoopTest, NullName) {
306372 Init (1 );
307373 CreateCondGraph ();
0 commit comments