@@ -1085,7 +1085,27 @@ namespace tut
1085
1085
return false ;
1086
1086
}
1087
1087
1088
- std::list<LLSD> mHistory ;
1088
+ template <typename CALLABLE>
1089
+ void checkHistory (CALLABLE&& code)
1090
+ {
1091
+ try
1092
+ {
1093
+ // we expect this lambda to contain tut::ensure() calls
1094
+ std::forward<CALLABLE>(code)(mHistory );
1095
+ }
1096
+ catch (const failure&)
1097
+ {
1098
+ LL_INFOS () << " event history:" << LL_ENDL;
1099
+ for (const LLSD& item : mHistory )
1100
+ {
1101
+ LL_INFOS () << item << LL_ENDL;
1102
+ }
1103
+ throw ;
1104
+ }
1105
+ }
1106
+
1107
+ using Listory = std::list<LLSD>;
1108
+ Listory mHistory ;
1089
1109
LLTempBoundListener mConnection ;
1090
1110
};
1091
1111
@@ -1136,23 +1156,26 @@ namespace tut
1136
1156
// finish out the run
1137
1157
waitfor (*py.mPy );
1138
1158
// now verify history
1139
- std::list<LLSD>::const_iterator li (listener.mHistory .begin ()),
1140
- lend (listener.mHistory .end ());
1141
- ensure (" no events" , li != lend);
1142
- ensure_equals (" history[0]" , (*li)[" data" ].asString (), " abc" );
1143
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 3 );
1144
- ++li;
1145
- ensure (" only 1 event" , li != lend);
1146
- ensure_equals (" history[1]" , (*li)[" data" ].asString (), " abcdef" );
1147
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 6 );
1148
- ++li;
1149
- ensure (" only 2 events" , li != lend);
1150
- ensure_equals (" history[2]" , (*li)[" data" ].asString (), " abcdefghi" EOL);
1151
- ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 9 + sizeof (EOL) - 1 );
1152
- ++li;
1153
- // We DO NOT expect a whole new event for the second line because we
1154
- // disconnected.
1155
- ensure (" more than 3 events" , li == lend);
1159
+ listener.checkHistory (
1160
+ [](const EventListener::Listory& history)
1161
+ {
1162
+ auto li (history.begin ()), lend (history.end ());
1163
+ ensure (" no events" , li != lend);
1164
+ ensure_equals (" history[0]" , (*li)[" data" ].asString (), " abc" );
1165
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 3 );
1166
+ ++li;
1167
+ ensure (" only 1 event" , li != lend);
1168
+ ensure_equals (" history[1]" , (*li)[" data" ].asString (), " abcdef" );
1169
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 6 );
1170
+ ++li;
1171
+ ensure (" only 2 events" , li != lend);
1172
+ ensure_equals (" history[2]" , (*li)[" data" ].asString (), " abcdefghi" EOL);
1173
+ ensure_equals (" history[0] len" , (*li)[" len" ].asInteger (), 9 + sizeof (EOL) - 1 );
1174
+ ++li;
1175
+ // We DO NOT expect a whole new event for the second line because we
1176
+ // disconnected.
1177
+ ensure (" more than 3 events" , li == lend);
1178
+ });
1156
1179
}
1157
1180
1158
1181
template <> template <>
@@ -1172,14 +1195,17 @@ namespace tut
1172
1195
// (or any other intervening layer) does crazy buffering. What we want
1173
1196
// to ensure is that there was exactly ONE event with "eof" true, and
1174
1197
// that it was the LAST event.
1175
- std::list<LLSD>::const_reverse_iterator rli (listener.mHistory .rbegin ()),
1176
- rlend (listener.mHistory .rend ());
1177
- ensure (" no events" , rli != rlend);
1178
- ensure (" last event not \" eof\" " , (*rli)[" eof" ].asBoolean ());
1179
- while (++rli != rlend)
1180
- {
1181
- ensure (" \" eof\" event not last" , ! (*rli)[" eof" ].asBoolean ());
1182
- }
1198
+ listener.checkHistory (
1199
+ [](const EventListener::Listory& history)
1200
+ {
1201
+ auto rli (history.rbegin ()), rlend (history.rend ());
1202
+ ensure (" no events" , rli != rlend);
1203
+ ensure (" last event not \" eof\" " , (*rli)[" eof" ].asBoolean ());
1204
+ while (++rli != rlend)
1205
+ {
1206
+ ensure (" \" eof\" event not last" , ! (*rli)[" eof" ].asBoolean ());
1207
+ }
1208
+ });
1183
1209
}
1184
1210
1185
1211
template <> template <>
@@ -1202,13 +1228,17 @@ namespace tut
1202
1228
ensure_equals (" getLimit() after setlimit(10)" , childout.getLimit (), 10 );
1203
1229
// okay, pump I/O to pick up output from child
1204
1230
waitfor (*py.mPy );
1205
- ensure (" no events" , ! listener.mHistory .empty ());
1206
- // For all we know, that data could have arrived in several different
1207
- // bursts... probably not, but anyway, only check the last one.
1208
- ensure_equals (" event[\" len\" ]" ,
1209
- listener.mHistory .back ()[" len" ].asInteger (), abc.length ());
1210
- ensure_equals (" length of setLimit(10) data" ,
1211
- listener.mHistory .back ()[" data" ].asString ().length (), 10 );
1231
+ listener.checkHistory (
1232
+ [abc](const EventListener::Listory& history)
1233
+ {
1234
+ ensure (" no events" , ! history.empty ());
1235
+ // For all we know, that data could have arrived in several different
1236
+ // bursts... probably not, but anyway, only check the last one.
1237
+ ensure_equals (" event[\" len\" ]" ,
1238
+ history.back ()[" len" ].asInteger (), abc.length ());
1239
+ ensure_equals (" length of setLimit(10) data" ,
1240
+ history.back ()[" data" ].asString ().length (), 10 );
1241
+ });
1212
1242
}
1213
1243
1214
1244
template <> template <>
@@ -1275,18 +1305,22 @@ namespace tut
1275
1305
params.postend = pumpname;
1276
1306
LLProcessPtr child = LLProcess::create (params);
1277
1307
ensure (" shouldn't have launched" , ! child);
1278
- ensure_equals (" number of postend events" , listener.mHistory .size (), 1 );
1279
- LLSD postend (listener.mHistory .front ());
1280
- ensure (" has id" , ! postend.has (" id" ));
1281
- ensure_equals (" desc" , postend[" desc" ].asString (), std::string (params.desc ));
1282
- ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::UNSTARTED);
1283
- ensure (" has data" , ! postend.has (" data" ));
1284
- std::string error (postend[" string" ]);
1285
- // All we get from canned parameter validation is a bool, so the
1286
- // "validation failed" message we ourselves generate can't mention
1287
- // "executable" by name. Just check that it's nonempty.
1288
- // ensure_contains("error", error, "executable");
1289
- ensure (" string" , ! error.empty ());
1308
+ listener.checkHistory (
1309
+ [¶ms](const EventListener::Listory& history)
1310
+ {
1311
+ ensure_equals (" number of postend events" , history.size (), 1 );
1312
+ LLSD postend (history.front ());
1313
+ ensure (" has id" , ! postend.has (" id" ));
1314
+ ensure_equals (" desc" , postend[" desc" ].asString (), std::string (params.desc ));
1315
+ ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::UNSTARTED);
1316
+ ensure (" has data" , ! postend.has (" data" ));
1317
+ std::string error (postend[" string" ]);
1318
+ // All we get from canned parameter validation is a bool, so the
1319
+ // "validation failed" message we ourselves generate can't mention
1320
+ // "executable" by name. Just check that it's nonempty.
1321
+ // ensure_contains("error", error, "executable");
1322
+ ensure (" string" , ! error.empty ());
1323
+ });
1290
1324
}
1291
1325
1292
1326
template <> template <>
@@ -1308,16 +1342,20 @@ namespace tut
1308
1342
{
1309
1343
yield ();
1310
1344
}
1311
- ensure (" no postend event" , i < timeout);
1312
- ensure_equals (" number of postend events" , listener.mHistory .size (), 1 );
1313
- LLSD postend (listener.mHistory .front ());
1314
- ensure_equals (" id" , postend[" id" ].asInteger (), childid);
1315
- ensure (" desc empty" , ! postend[" desc" ].asString ().empty ());
1316
- ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::EXITED);
1317
- ensure_equals (" data" , postend[" data" ].asInteger (), 35 );
1318
- std::string str (postend[" string" ]);
1319
- ensure_contains (" string" , str, " exited" );
1320
- ensure_contains (" string" , str, " 35" );
1345
+ listener.checkHistory (
1346
+ [i, timeout, childid](const EventListener::Listory& history)
1347
+ {
1348
+ ensure (" no postend event" , i < timeout);
1349
+ ensure_equals (" number of postend events" , history.size (), 1 );
1350
+ LLSD postend (history.front ());
1351
+ ensure_equals (" id" , postend[" id" ].asInteger (), childid);
1352
+ ensure (" desc empty" , ! postend[" desc" ].asString ().empty ());
1353
+ ensure_equals (" state" , postend[" state" ].asInteger (), LLProcess::EXITED);
1354
+ ensure_equals (" data" , postend[" data" ].asInteger (), 35 );
1355
+ std::string str (postend[" string" ]);
1356
+ ensure_contains (" string" , str, " exited" );
1357
+ ensure_contains (" string" , str, " 35" );
1358
+ });
1321
1359
}
1322
1360
1323
1361
struct PostendListener
0 commit comments